From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zg8tmtyylji0my4xnjeumjiw.icoremail.net (zg8tmtyylji0my4xnjeumjiw.icoremail.net [162.243.161.220]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF7F63BE14A; Mon, 15 Jun 2026 14:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.161.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781532886; cv=none; b=JZyER3YRTYCi0sYc5ZUOEdysYiwXUEm74gvLPT1MIDFg602fVFo+jpL3pmtcRXs2HcGTkcldi5c7qWjCbUmnJiFKKJYsauUpztCalUypUZKjfqt3w+IXR9tUOECAgKNtz+z6CSnaKIb65jrve1+jOh2/aZOAFVEZuhlEz15seqc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781532886; c=relaxed/simple; bh=y8XD9SDah6p33tm7vzsCNC5aTdZwzbpIQ+iS7NxPN9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bTOnkpN2pBAHFcOgPnCoBnou1nfYUePTOqhtG61El93CCBi0J7845o72/d36xxrcgD2rEMvaGtBO6i4Jzd2nFOBS+jl2mqOdUKcH+bSZkvr8Ml6Vjku3HOnGbHgIp+Fh8/tJ1+40ulFaMD4S1wjMgdv4/4RMLtmIUbiwDw1Rh3E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mails.tsinghua.edu.cn; spf=pass smtp.mailfrom=mails.tsinghua.edu.cn; dkim=pass (1024-bit key) header.d=mails.tsinghua.edu.cn header.i=@mails.tsinghua.edu.cn header.b=qz0NkDmb; arc=none smtp.client-ip=162.243.161.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mails.tsinghua.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mails.tsinghua.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mails.tsinghua.edu.cn header.i=@mails.tsinghua.edu.cn header.b="qz0NkDmb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mails.tsinghua.edu.cn; s=dkim; h=Received:From:To:Cc:Subject: Date:Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=R6JVmQKUTslaGY65rvpMFq9qLt0NLyDloL SNgMPYWjo=; b=qz0NkDmbLzlWedm+mpX8yV6GwSVsWwYNNTWKoE+jKNTZsjGRGK gPjKSueDtvbsdWCqn3axfUI75N5MHBmI8h947/4J/dQbGXVVzL4xKn9ABRH4IoDQ pDcOYd88DkGVLkhUmIP7Kan4ghh7Fyho4l2vu+I/f3vkwJzL4mlqkJ3Ww= Received: from c9a6c405b3f2.. (unknown [202.112.238.121]) by web4 (Coremail) with SMTP id ywQGZQBXaZ69CDBqq7FKAg--.53046S2; Mon, 15 Jun 2026 22:14:30 +0800 (CST) From: Yiyang Chen To: bpf@vger.kernel.org Cc: Yiyang Chen , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , John Fastabend , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf v3 0/2] bpf: Fix packet pointer invalidation for skb dynptr writes Date: Mon, 15 Jun 2026 14:14:05 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:ywQGZQBXaZ69CDBqq7FKAg--.53046S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuF1UWr47uw1xArW3ur1xXwb_yoW5Ar4xpa yrGryaq34kXF17ZFnrAF48Z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backed dynptr writer kfuncs can mutate skb packet data. The verifier does not currently treat those kfuncs as packet-changing. A direct packet pointer checked before the call can stay usable after the write. bpf_dynptr_write() already clears packet pointers through the helper path. Teach kfunc argument checking to do the same for skb and skb-meta dynptr destinations. For static CFG analysis, conservatively classify dynptr writer kfuncs as packet-changing so global subprogram summaries are correct even before register states exist. Keep source-only dynptr arguments unchanged. v3 also treats unspecialized global-subprogram dynptr arguments as possibly packet-backed in the precise verifier path. This covers packet pointer invalidation inside a global subprogram body where the argument may point to an skb dynptr provided by the caller. Validation: Rebase: fetched bpf-next origin/master on 2026-06-15; series base is e4287bf34f97a ("selftests/bpf: Work around llvm stack overflow in crypto progs"). Without this series: linux-stable-v7.0.12 accepts the three original stale packet pointer cases; linux-mainline-v7.1-rc7 accepts the three original stale packet pointer cases; the source-only bpf_dynptr_copy() control loads on both kernels. With this series applied: patched bpf-next rejects the five stale packet pointer cases with "invalid mem access 'scalar'"; the source-only bpf_dynptr_copy() control still loads; QEMU direct-runner reports PATCH008_SUMMARY failures=0 total=6. Build and style checks: git diff --check HEAD~2..HEAD: OK checkpatch.pl --strict --no-tree: OK make O=$BUILD kernel/bpf/verifier.o kernel/bpf/cfg.o: OK make O=$BUILD -j$(nproc) bzImage: OK dynptr_fail.bpf.o build against patched vmlinux BTF: OK v2: https://lore.kernel.org/bpf/cover.1781525896.git.chenyy23@mails.tsinghua.edu.cn/ Signed-off-by: Yiyang Chen --- Changes in v3: - Rebased onto fetched bpf-next origin/master (e4287bf34f97a). - Split static CFG packet-changing detection from precise checked-argument invalidation. - Treat unspecialized global subprogram dynptr arguments as possibly packet-backed for writer invalidation. - Add global subprogram regression tests for caller-side and local stale packet pointer invalidation. Changes in v2: - Resend as a properly threaded series. No code changes. Yiyang Chen (2): bpf: Fix packet pointer invalidation for skb dynptr writes selftests/bpf: Add skb dynptr writer packet invalidation tests include/linux/bpf_verifier.h | 3 + kernel/bpf/cfg.c | 2 +- kernel/bpf/verifier.c | 79 +++++++++- .../testing/selftests/bpf/progs/dynptr_fail.c | 140 ++++++++++++++++++ 4 files changed, 222 insertions(+), 2 deletions(-) base-commit: e4287bf34f97a88c7d9322f5bde828724c073a6b -- 2.34.1