From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385141; b=R0M7FI3GNTsWl8Yf/HobczD8AZx96cm4cKYtJuq1z9fdEhjr9BGE+DYUYMbMr77SYP8o mt8bAQPGjFB1/ZH2pXZgzUwwml2TuM2qrxuHYd2bMrz57JJvs/j4aDDvda7VXlxsIsbP/ of4XIgvAipKv5mHjSogDlH/mqPN90wk8QYOaU84XpUbJ/tn4SAMFcoiOqW3rhVvvrbD2O Pp5Spwi2tPldw3XgTalO2sjeMPglsEbBplbASldQ8MVN89hu1otechft39Yf0oZjkiMZV q6f0+f0YpDmLoJBUAGY/wYqbCOjGiKZ25xhXGBLJm+3thZZG3Alb6bDx7D2AhvfvjJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385141; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ByiTY7IPTosKYZ+hb9p0sJfFQoqbJUNv+LJYIzbOCk8=; b=mcZ/wsqdl7uOOdyptUvycF9gGqEGhgZNmlytjFQFEo87hXnznaT/DZej5JOa6e2IVwpB M3mBFdcjaIFuCAOvVdAa/1kdn/9vRAQnyIRxpJ7Wsv9DZvYK8UzWvcWII4/Hlgy+wTJIP esoZRcBFudCbaBoXuaPgBN8/wGEG2JM9RVeRRbOUz6yvPQ8KQ25PKnvECliXVUWLhMLxJ tZgdnTFectodYpfT6/I+l+KwENGlk2WDr/7Rhzn227bQnMhQY7iHcMRaYgtGEsVxKyLo4 8snDX7RtD5X4E5wgzqyI9HfRgsv0UR3LLbC9sBNW4bvcQLJRK6B+86wDiub242doqkw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YTdffhs4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB9D0606A322; Fri, 4 Dec 2026 11:52:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YTdffhs4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 081E31F00A05; Fri, 4 Dec 2026 11:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385141; bh=ByiTY7IPTosKYZ+hb9p0sJfFQoqbJUNv+LJYIzbOCk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YTdffhs4xtwQuO47YeOY7QzS4+y6UJMVjCWa/7viZZdZEiURUoDwBR+kezPznn+DH 5SiXJ2+odw4FLUgIcNc33Gr8NPI0DgGkP6KY/6OyuHM4u9c41f9W8BlPGYKSrMnHR6 ZUyrCyprx+GlGhcBzBOzR24iYweqdNI20DXa7xPw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0435/1167] bpf: Let bpf_dynptr_write() mark a global function Date: Fri, 4 Dec 2026 18:57:42 +0900 Message-ID: <20261204100713.346973129@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 589998616e0f9190ba6f6644a19532c5b2ba66d0 ] The caller of a global function loses its packet pointers if the function may change packet data. That is found out by a scan for calls of the helpers which bpf_helper_changes_pkt_data() lists. bpf_dynptr_write() is not on the list, because it depends on the type of the dynptr: check_helper_call() looks at it. The scan cannot do that, and so a global function which makes a dynptr from the skb, or gets one as an argument, and writes through it counts as harmless. The write can reallocate the head of the skb, and the caller goes on with pointers into the old one, which has been freed. Let every call of bpf_dynptr_write() mark the function, as a tail call does. The same mark decides whether a program may replace a function. Fixes: 51081a3f25c7 ("bpf: track changes_pkt_data property for global functions") Signed-off-by: Josef Bacik Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261017230950.802052-10-alexei.starovoitov@gmail.com [ sashal: Moved the change from cfg.c to the matching visit_insn() call in verifier.c, folding the BPF_FUNC_dynptr_write check into the existing single-line bpf_helper_call() condition. ] Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 39f3e2aea0d9e..e39b28012a44f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -15668,7 +15668,10 @@ static int visit_insn(int t, struct bpf_verifier_env *env) mark_prune_point(env, t); mark_jmp_point(env, t); } - if (bpf_helper_call(insn) && bpf_helper_changes_pkt_data(insn->imm)) + /* nobody knows yet whether the dynptr is that of an skb */ + if (bpf_helper_call(insn) && + (bpf_helper_changes_pkt_data(insn->imm) || + insn->imm == BPF_FUNC_dynptr_write)) mark_subprog_changes_pkt_data(env, t); if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) { struct bpf_kfunc_call_arg_meta meta; -- 2.53.0