Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2829472pxb; Mon, 1 Nov 2021 02:42:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1pPOIrB9RCpFVk6qVNNbEJcWIktJxikvvarqQRIGZ/a+PV9VIKgCVEzi490F17SZaDA9m X-Received: by 2002:a05:6402:1801:: with SMTP id g1mr12814615edy.107.1635759756603; Mon, 01 Nov 2021 02:42:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635759756; cv=none; d=google.com; s=arc-20160816; b=TKQjwai5E6njo8VnG2nVL9NsJGjTSGsXNXXNHdTrp0FBfewQ8YW/cMvNK7GAM1sigh FJpi3Xg1QuFg2sWcOu5hu41mVoTIaANfleNvhx3oWp2sszIYH9x16bYct0yj4feeEOtp MjkINMDLV/VmOM2k6XtU4skVqqPhnFUz7gP0f8JR4vaXuPLXX0l3CXs0eU6snpZyg7b6 x5UeXEg70ynpIugTN9Cx5b9loZkAza+KN7kxP0ifJa4ZLKc1bOKfvUIXEZYu8lh1HhGU L+P2YCFVnWhq+BVCl4de4JMPAPJXf9jxQcSSGfxSOKiNR+V6Ynrxu5sLbbp4L1EmilkF bwrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VeIPN4d+Y5cvNLjwRD5ajdjvPixihau/UEUgeA2DueU=; b=RE62gy30drt3F/Ceybs/+xvsminLHpAkVTlKV6BnpSXduvgC9NQYp3BQgFeWMLyO1+ YY0FKQuWIW3pdO6noW7kF2QXSGUSY00Biw/U6KevBuRvALbUbLy/gakk/LGvIZyz5buR lPCZSgioJpBns45RYiUjNWdGhaaNRovoY5zelv7FwD0Fq5VB1Q8qubvmzkLpYdwbYu4G tqXR2yqSoRq4ws9N2XDjN8GiacFal2rRfCbcQjxi0eh5bfHTT4uBlCxZvnVLS3rU7xvV Tmlwe2JBwnQQfa6Os88ewWygSGKTpcDPuCFs8/GZROAkBRpzAae5NbYFeChyjKtGYBwV 7K5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MhYwkqml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg16si25681170ejc.752.2021.11.01.02.42.12; Mon, 01 Nov 2021 02:42:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MhYwkqml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233575AbhKAJkF (ORCPT + 99 others); Mon, 1 Nov 2021 05:40:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233634AbhKAJhp (ORCPT ); Mon, 1 Nov 2021 05:37:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45591611C4; Mon, 1 Nov 2021 09:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758795; bh=js6PGcD2sqCtv9u3aattD7TJxF1BWSw49LaHNk+d62c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhYwkqmlmPlo4UQynzvegDr2sK9zMh2PBFHJOFy3H3kg3cfE/K4gmj6XYChZKo5S2 WvSSQBshTVM+QZY6O/R1yi/pXpIxnD6uM+cXjlQZpBlrZBHd4+cPpmwPibyva1XT2W g9G7mBHwv/ulcrVHMixlvwKW4NK/3Pa/MpqxN2vE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Daniel Borkmann , Jakub Kicinski Subject: [PATCH 5.10 35/77] riscv, bpf: Fix potential NULL dereference Date: Mon, 1 Nov 2021 10:17:23 +0100 Message-Id: <20211101082519.237065874@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Björn Töpel commit 27de809a3d83a6199664479ebb19712533d6fd9b upstream. 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 Acked-by: Daniel Borkmann Link: https://lore.kernel.org/r/20211028125115.514587-1-bjorn@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- arch/riscv/net/bpf_jit_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- 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(str 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; }