From patchwork Thu Oct 28 12:51:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12590051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74773C433F5 for ; Thu, 28 Oct 2021 12:53:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3CE0660F9D for ; Thu, 28 Oct 2021 12:53:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3CE0660F9D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=JHxBS+P9LL64nZ+ovEh2TfixmZANE9i47FPKs3wzIZ0=; b=Y7r2quz77nYAkt 6BiXGJ3dnf4kwFOenrPvVvZQhwRGQfiafJjKfTHj3yh//BYVFa/tsZcG+L8FhiUoiyl83V7p3XxVZ biMlM7DyQFwEcNqooH+Y5tq6NwDXtQLgiY5Qv1LH/v+IJG8BFOOQdOVJ+Yw6ItLm1cc43wiuRviZ6 IU9IZwcG2RWS6WL0linwtzvAMkZ3UqG4u5TP2UdwJOG3FV7xortNvr5Q6WrLll1pb02ejOaJqy7vM gJpoifXaYJeadaR68HS72FXkv3cMWAqa1ZS/N+hnVTxxaHoML4WxtKKvn688K3/fWk6zGsN3y0NaW OnnR3llOoPkr4YHQw5Ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mg4ts-007qIh-3z; Thu, 28 Oct 2021 12:52:56 +0000 Received: from mail-lj1-f180.google.com ([209.85.208.180]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mg4tp-007qGM-JN for linux-riscv@lists.infradead.org; Thu, 28 Oct 2021 12:52:54 +0000 Received: by mail-lj1-f180.google.com with SMTP id k13so10451764ljj.12 for ; Thu, 28 Oct 2021 05:52:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xrmACLrClol1Ht1AqRT5BlRPbvf71eFZVnNxO5q/rNI=; b=JhKrrI7sPs7TevEoAbZg+n1MvZ4cv3qdxzPNJCNisS6hVLngUXfsgutjyCjzeei6d+ xgVauZR4TjYJe9GLWahh7i27SfK9BDBvkY5GDAid0aZkJ5zllMK+eKBKumZBnaL4lb7h 6N+bS9VyZz8kfFJfWbiuQfR0KaQGKkV0kEAs5WMRf1GnExsLPRLCF9mpZd2u9sr5c8Ld yEE33buIT0pHw2h3qXnDgHJH9w1TpagF2QaKVPLU10dBXNt2Zkzwro8T1Bbv/SLSDwoD 2Wfs3n1RqQM+LpnfgKuTQHEYw1Ajab5k4MHp8tCeIuHbmJ1HXf3zOZC4duALOHgkV3oi 0ADA== X-Gm-Message-State: AOAM531CMEMT6/TeHdGPkZMy5O4XrpMjQ7zG6RxQA0ceTjOUgMJqX2ui oGD3ze0yYG57uKJfn0b6xRU= X-Google-Smtp-Source: ABdhPJyQuQYnh4pcXTg5UYacz2zwAvAPf7Nnyl+A/VS8XnK9ZOgp2IkFx0P7Wfl5aBeow658nwCU2w== X-Received: by 2002:a2e:9d88:: with SMTP id c8mr4662425ljj.276.1635425567390; Thu, 28 Oct 2021 05:52:47 -0700 (PDT) Received: from kladdkakan.. ([185.213.154.234]) by smtp.gmail.com with ESMTPSA id p10sm282150ljm.53.2021.10.28.05.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 05:52:46 -0700 (PDT) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org Subject: [PATCH bpf] riscv, bpf: Fix potential NULL dereference Date: Thu, 28 Oct 2021 14:51:15 +0200 Message-Id: <20211028125115.514587-1-bjorn@kernel.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211028_055253_670192_FB9E7295 X-CRM114-Status: UNSURE ( 8.48 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The bpf_jit_binary_free() function requires a non-NULL argument. When the RISC-V BPF JIT fails to converge in NR_JIT_ITERATIONS steps, jit_data->header will be NULL, which triggers a NULL dereference. Avoid this by checking the argument, prior calling the function. Fixes: ca6cb5447cec ("riscv, bpf: Factor common RISC-V JIT code") Signed-off-by: Björn Töpel --- arch/riscv/net/bpf_jit_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) base-commit: 72f898ca0ab85fde6facf78b14d9f67a4a7b32d1 diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c index 0fee2cbaaf53..753d85bdfad0 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -125,7 +125,8 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) if (i == NR_JIT_ITERATIONS) { pr_err("bpf-jit: image did not converge in <%d passes!\n", i); - bpf_jit_binary_free(jit_data->header); + if (jit_data->header) + bpf_jit_binary_free(jit_data->header); prog = orig_prog; goto out_offset; }