From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68853146D6B; Mon, 6 Jan 2025 15:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736176957; cv=none; b=dtiJScDUCsTyB4lUTNQAzXvYUoToMpdq8BRjm9ZnH7N8GUFATsjNoijzTPsWU9sW0YcYVI68g+Lpgsf80E6bkt5p6+FKbGFWirYWzhjzFl+BigWPxN/hCFnUtc03gvJsfVEk8gtulOlZXamTMg2lQFqsSR7uGiC3L3xdbMMmLxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736176957; c=relaxed/simple; bh=RFjsFZ/YtpsOVNz/mai2c2brkR9rC7IoeTLEUcUwafg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B2WTKmy4HfQ61fcqHnbB25P29f5VxgCvH+jNW88G7K0/mN2SLxfMFxloC5kIocRbw6BNVxq7einxa/MKNc9Rog5DUet7yCrxC5MmBFJiursb7xAnN8cK51JIHd0gygPlB5529elYQK7rpUJaOtNApbjKEQY0FP8rdRNMAXXIh1E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PKnjUf2m; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PKnjUf2m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D163C4CED2; Mon, 6 Jan 2025 15:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736176957; bh=RFjsFZ/YtpsOVNz/mai2c2brkR9rC7IoeTLEUcUwafg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PKnjUf2mCqrHlq2nTczQeU6TxqnsQr7eN2liKiYxhZ6hb2u7khnZb84egACNYkOwC zc4E72U0NExGmGM9YNuIO+h8v5GmUfYIEn0Zj66GczIwUd5KJ21gFqErc8OF4OAOLu IfjRokzCODjV+I3rp4PZLg5945iDqu+w2OpegZ0E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Anton Protopopov , Jiri Olsa , Andrii Nakryiko , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 59/81] bpf: fix potential error return Date: Mon, 6 Jan 2025 16:16:31 +0100 Message-ID: <20250106151131.663057837@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151129.433047073@linuxfoundation.org> References: <20250106151129.433047073@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anton Protopopov [ Upstream commit c4441ca86afe4814039ee1b32c39d833c1a16bbc ] The bpf_remove_insns() function returns WARN_ON_ONCE(error), where error is a result of bpf_adj_branches(), and thus should be always 0 However, if for any reason it is not 0, then it will be converted to boolean by WARN_ON_ONCE and returned to user space as 1, not an actual error value. Fix this by returning the original err after the WARN check. Signed-off-by: Anton Protopopov Acked-by: Jiri Olsa Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/r/20241210114245.836164-1-aspsk@isovalent.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 0ea0d50a7c16..83b416af4da1 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -523,6 +523,8 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt) { + int err; + /* Branch offsets can't overflow when program is shrinking, no need * to call bpf_adj_branches(..., true) here */ @@ -530,7 +532,9 @@ int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt) sizeof(struct bpf_insn) * (prog->len - off - cnt)); prog->len -= cnt; - return WARN_ON_ONCE(bpf_adj_branches(prog, off, off + cnt, off, false)); + err = bpf_adj_branches(prog, off, off + cnt, off, false); + WARN_ON_ONCE(err); + return err; } static void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp) -- 2.39.5