Article View: linux.kernel.netdev
Article #4398Re: [PATCH bpf-next v2 43/43] bpf: Refuse packet slices for packet-changing helpers
From: bot+bpf-ci
Date: Sat, 17 Oct 2026 17:17
Date: Sat, 17 Oct 2026 17:17
89 lines
9039 bytes
9039 bytes
--===============2037395697687729854==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
> bpf: Refuse packet slices for packet-changing helpers
TL;DR: Refusing slices for bpf_skb_store_bytes() may be unneeded after the
previous patch and would newly reject previously safe programs with -EACCES;
the commit message's freed-head claim may be stale.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -9693,6 +9693,16 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p
> if (err)
> return err;
>
> + /*
> + * A slice of a packet is packet data under another name. A helper which
> + * may reallocate the packet must not go on reading from the old one.
> + */
> + if (is_helper(meta) && reg_is_dynptr_slice_pkt(reg) &&
> + bpf_helper_changes_pkt_data(meta->func_id)) {
> + verbose(env, "function access to the packet is not allowed\n");
> + return -EACCES;
> + }
> +
> if (arg_type_is_raw_mem(arg_type))
> meta->arg_raw_mem.mask |= BIT(slot);
>
The commit message says of bpf_skb_store_bytes() that "the helper then reads
the old head, which has been freed". Is that still true after the previous
patch in this series, 0bd8e7a834ac ("bpf: Follow the head if an skb is
written from a slice")?
That patch changed the helper to:
BPF_CALL_5(bpf_skb_store_bytes, ...)
{
...
if (unlikely(bpf_try_make_writable_from(skb, offset + len, &from)))
return -EFAULT;
...
memmove(ptr, from, len);
and bpf_try_make_writable_from() moves 'from' to the new head when it points
into [skb->head, skb_end_pointer(skb)). So bpf_skb_store_bytes() no longer
reads the old head after a reallocation. Only bpf_lwt_push_encap(),
bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_action() still read their
hdr/from/param after skb_cow_head() or bpf_try_make_writable() without
following the head.
The result also looks inconsistent with the suggested alternative. The
commit message recommends bpf_dynptr_write(), and the verifier still accepts
a slice as its source. For an skb dynptr that ends up in the same code:
case BPF_DYNPTR_TYPE_SKB:
return __bpf_skb_store_bytes(dst->data, dst->offset + offset, src, len, flags);
A program in tc, sk_skb or lwt_xmit that does:
p = bpf_dynptr_slice(&ptr, off, buf, n);
bpf_skb_store_bytes(skb, off2, p, n, 0);
has been accepted since 2012c867c800 and is safe with the previous patch
applied. With this patch it fails to load with -EACCES ("function access to
the packet is not allowed"), via check_helper_call() -> check_func_args() ->
check_func_arg() with is_helper(meta) true, reg typed
PTR_TO_MEM|DYNPTR_TYPE_SKB, and bpf_helper_changes_pkt_data(BPF_FUNC_skb_store_bytes)
returning true.
Should the refusal be limited to the helpers that still read the source
after reallocating the head (or should those helpers follow the head too),
so that bpf_skb_store_bytes() keeps accepting slices? Either way, should the
commit message stop listing bpf_skb_store_bytes() as reading freed memory?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/39051545464
--===============2037395697687729854==--
Technical Details
Message-ID:
<5ed879575ebbfbb3da9c8c6922ac0a3c13e01637c1d6a01d13c001bf15eff8cc@mail.kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347831-linux-kernel-netdev=dewy.ruReferences:
<20261017163745.3341787-44-alexei.starovoitov@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347831-linux-kernel-netdev=dewy.ru From: bot+bpf-ci@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf-next v2 43/43] bpf: Refuse packet slices for packet-changing helpers Date: Sat, 17 Oct 2026 17:17:10 +0000 (UTC) Organization: Usenet Network Message-ID: <5ed879575ebbfbb3da9c8c6922ac0a3c13e01637c1d6a01d13c001bf15eff8cc@mail.kernel.org> References: <20261017163745.3341787-44-alexei.starovoitov@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2037395697687729854==" Injection-Info: usenet.network; logging-data="3095060"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:6UPtUTmW7+UzZEGcCffUkjpngaU= sha256:imOwnCf9CG7nj5wzq/qPrYNNdANmIKc4phANP1xzHlQ= sha1:4l2YgrXuj3dbmW2DwB1+4w6NWoQ= sha256:Hq6r/Hm4+d/WPBKXko22zvvJKs+GQmBzrw8sgCE5ZWo= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id E11C811073F; Sat, 17 Oct 2026 20:24:05 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.64 X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yNtb2YbTCohK; Sat, 17 Oct 2026 20:24:02 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-347831-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id EF81C11073A; Sat, 17 Oct 2026 20:23:53 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 0D1382FE12; Sat, 17 Oct 2026 17:17:39 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05B803BFAF7; Sat, 17 Oct 2026 17:17:13 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KGd6BB7s" X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C98893939A4; Sat, 17 Oct 2026 17:17:11 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792257432; cv=none; b=OTZ9V7VyXJqYTj2VLNUckWPikNC5v3Lz2nFaEUjAmHM71XqoWS2LJIn9EnoGdkuvZMhDc3H18eZALGcOoAlO9Yq0d3yJy3KJJ55p/j56DIFFmH4s0bGu/+3iRDFkFGkcDV16tKlpEKlSoXnRF053PVqaWuW6NcU1g5+9Z5vGmdU= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792257432; c=relaxed/simple; bh=+UMkhZlKP+53Zedn1FweZE7bdjUDdByfB+7t/dNu5a4=; h=Content-Type:MIME-Version:Message-Id:In-Reply-To:References: Subject:From:To:Cc:Date; b=rsoNiRy26EOpohc1YzNETqKuB190kHv0QhZC7pSHEeVZzCSbzR6ef+oReqFfM3ubEoyzAMWH7f+gHI6FMMaNN9n3KgRUidkUeQP6NlPcwpUCBYIIIWnEqKaQLIexZO1BpSaHQFCXKpplvm/g7GLKZEFhNiM+0vKYu5J0hF/LjyY= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KGd6BB7s; arc=none smtp.client-ip=100.103.45.18 X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ED2D1F000C4; Sat, 17 Oct 2026 17:17:10 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792257431; bh=EJNR5K+W76SOP8eD3TWI1W34xOeqGBMNv8XIRZynEyc=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=KGd6BB7svaYa75s3jgt14JDbKXgwB7TR/bLrBxq+7/O3Msrr4MhfAkfO8o9S4vsVD 5zcZZD0rC4Uwv4biZ0lD/BcBkve296vEdua5PnTW6/NEoEdZAAqQhC2ZbuQW1wFjvL H41eTc/kbA10yZGagmg/7B4cbOi9sb9auV2677KTansjsKSa3JR02dXuMJoRWRnu8k FsPtb/FnfP7mjgztidbZ/JuDvdrO0d80K3+NtSGfUKL/8PQomuJbTveSbIyhLQziij o2U8V7C3pq7LdzDMk1JcEI3ZAfyAh48mX/dIVWgJnA9hIEAnDNIFlPjPHatyIUQWPr OnDfE7cwgwbrg== X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-In-Reply-To: <20261017163745.3341787-44-alexei.starovoitov@gmail.com> X-Cc: daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,netdev@vger.kernel.org,josef@toxicpanda.com,mason@kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev