bpf: Fix packet pointer invalidation for skb dynptr writes
Subsystems (4)
v2 cover bpf: Fix packet pointer invalidation for skb dynptr writes
skb-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.
Keep source-only dynptr arguments unchanged.
Validation:
Without this series:
linux-stable-v7.0.12 accepts the three stale packet pointer cases;
linux-mainline-v7.1-rc7 accepts the three stale packet pointer cases;
the source-only bpf_dynptr_copy() control loads on both kernels. With this series applied:
patched bpf-next rejects the three stale packet pointer cases with "invalid mem access 'scalar'";
the source-only bpf_dynptr_copy() control still loads.
Build and style checks:
git diff --check: OK
checkpatch.pl --strict --no-tree: OK
make O=$BUILD kernel/bpf/verifier.o: OK
make O=$BUILD -j$(nproc) bzImage: OK
dynptr_fail.bpf.o build against patched vmlinux BTF: OK---
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 | 1 + kernel/bpf/verifier.c | 62 ++++++++++++- .../testing/selftests/bpf/progs/dynptr_fail.c | 89 +++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-)
base-commit: e4287bf34f97a88c7d9322f5bde828724c073a6b
Signature · 1 line
2.34.1
PATCH v2 1/2 bpf: Fix packet pointer invalidation for skb dynptr writes
skb-backed dynptr writer kfuncs can mutate skb packet storage. The verifier currently treats kfunc calls as packet-changing only for bpf_xdp_pull_data().
That leaves direct packet pointers usable after skb dynptr writer kfuncs. The helper path already clears packet pointers for bpf_dynptr_write().
Mark kfunc calls packet-changing when argument 0 is a writable skb or skb-meta dynptr destination. This covers bpf_dynptr_copy(), bpf_dynptr_memset(), and probe/copy-from-user dynptr writers. Source-only dynptr arguments are left unchanged.
--- include/linux/bpf_verifier.h | 1 + kernel/bpf/verifier.c | 62 +++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-)
include/linux/bpf_verifier.h +1 -0
@@ -1448,6 +1448,7 @@ struct bpf_kfunc_call_arg_meta {/* Out parameters */ u8 release_regno;bool r0_rdonly; +bool pkt_dynptr_write;u32 ret_btf_id;u64 r0_size;u32 subprogno;
kernel/bpf/verifier.c +61 -1
86 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Static CFG analysis incorrectly assumes dynptr writers do not change packet data, leading to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Static CFG analysis incorrectly assumes dynptr writers do not change packet data, leading to Use-After-Free via global subprograms and freplace. --
commit 1c2eddecfcf22d7859e70204534b70a21c8883bc
Author: Yiyang Chen <[email protected]>
bpf: Fix packet pointer invalidation for skb dynptr writes
This patch modifies the verifier to treat skb dynptr writer kfuncs as packet-changing operations, ensuring that direct packet pointers are invalidated after calls like bpf_dynptr_copy or bpf_dynptr_memset.
Quoted 4 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
kernel/bpf/verifier.c static bool is_kfunc_bpf_preempt_enable(struct bpf_kfunc_call_arg_meta *meta) · line 11265
Quoted 8 lines
kernel/bpf/verifier.c +3
-1@@ -11229,7 +11260,33 @@ static bool is_kfunc_bpf_preempt_enable(struct bpf_kfunc_call_arg_meta *meta)bool bpf_is_kfunc_pkt_changing (struct bpf_kfunc_call_arg_meta *meta) { -return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data]; +return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data] || + meta->pkt_dynptr_write; +}
[Severity: High]
Does this modification cause issues during the control flow graph analysis phase?
Looking at kernel/bpf/cfg.c, check_cfg() calls bpf_is_kfunc_pkt_changing() using a statically fetched meta where register states are not yet available:
kernel/bpf/cfg.c:check_cfg() {
...
if (ret == 0 && bpf_is_kfunc_pkt_changing(&meta))
mark_subprog_changes_pkt_data(env, t);
...
}Since pkt_dynptr_write is only evaluated later during check_kfunc_args() based on register states, will it always be false during CFG analysis?
If so, it seems this might leave the changes_pkt_data flag incorrectly set to false for subprograms mutating packets via dynptr writers.
Could this lead to use-after-free scenarios with global subprograms or freplace? For example, if a global subprogram's dynptr argument is defaulted to BPF_DYNPTR_TYPE_LOCAL in btf_prepare_func_args():
kernel/bpf/verifier.c:btf_prepare_func_args() {
...
} else if (arg->arg_type == ARG_PTR_TO_DYNPTR) {
__mark_dynptr_reg(reg, BPF_DYNPTR_TYPE_LOCAL, true, ++env->id_gen, 0);
...
}Will the dynptr write evade detection entirely, leaving the caller with stale, uninvalidated packet pointers?
Quoted 6 lines
kernel/bpf/verifier.c +6
-0+ +static bool dynptr_type_pkt_data (enum bpf_dynptr_type type) +{ +return type ==BPF_DYNPTR_TYPE_SKB || + type ==BPF_DYNPTR_TYPE_SKB_META ; +}
[ ... ]
Quoted 9 lines
kernel/bpf/verifier.c +3
-0@@ -12214,6 +12271,9 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ &meta->ref_obj, &meta->dynptr);if (ret <0 )return ret; +if (is_kfunc_pkt_dynptr_writer (meta, i) && +dynptr_type_pkt_data (meta->dynptr.type)) + meta->pkt_dynptr_write = true;break ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 2/2 selftests/bpf: Add skb dynptr writer packet invalidation tests
In reply to Yiyang ChenAdd verifier tests for direct packet pointers kept live across skb dynptr writer kfunc calls.
The writer cases must reject because stale packet pointers must not remain usable after the kfunc can mutate skb packet storage.
Add a bpf_dynptr_copy() control where the skb dynptr is only the source. That case must continue to load because it does not write through the skb-backed dynptr.
--- .../testing/selftests/bpf/progs/dynptr_fail.c | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+)
tools/testing/selftests/bpf/progs/dynptr_fail.c +89 -0
@@ -1274,6 +1274,95 @@ int skb_invalid_data_slice4(struct __sk_buff *skb)return SK_PASS ; } +char dynptr_kfunc_data[8 ] ="test" ; +char dynptr_kfunc_dst[8 ]; + +extern int bpf_dynptr_copy(const struct bpf_dynptr *dst, __u64 dst_off, + const struct bpf_dynptr *src, __u64 src_off, + __u64 size) __ksym __weak; +extern int bpf_dynptr_memset(const struct bpf_dynptr *ptr, __u64 offset, + __u64 size, __u8 val) __ksym __weak; +extern int bpf_probe_read_kernel_dynptr(const struct bpf_dynptr *dptr, + __u64 off, __u64 size, + const void *unsafe_ptr__ign) __ksym __weak; + +/* Direct packet pointers are invalidated after a dynptr kfunc writes to an skb */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_dynptr_memset (&ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +/* Direct packet pointers are invalidated after bpf_dynptr_copy() writes to an skb */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_copy_dst(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &dst); +bpf_dynptr_from_mem (dynptr_kfunc_data,sizeof (dynptr_kfunc_data),0 , &src); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +/* this should fail */ +return *data; +} + +/* Direct packet pointers stay valid when an skb dynptr is only copied from */ +SEC("?tc") +__success +int skb_pkt_ptr_valid_after_dynptr_copy_src (struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &src); +bpf_dynptr_from_mem (dynptr_kfunc_dst,sizeof (dynptr_kfunc_dst),0 , &dst); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +return *data; +} + +/* Direct packet pointers are invalidated after probe-read writes to an skb dynptr */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_probe_read_kernel_dynptr(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_probe_read_kernel_dynptr (&ptr,0 ,1 , dynptr_kfunc_data); + +/* this should fail */ +return *data; +} +/* Read-only skb data slice is invalidated on write to skb metadata */ SEC("?tc") __failure __msg("invalid mem access 'scalar'")
Signature · 1 line
2.34.1
v3 cover bpf: Fix packet pointer invalidation for skb dynptr writes
In reply to Yiyang Chenskb-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: OKv2:
https://lore.kernel.org/bpf/[email protected]/
---
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
Signature · 1 line
2.34.1
PATCH v3 1/2 bpf: Fix packet pointer invalidation for skb dynptr writes
skb-backed dynptr writer kfuncs can mutate packet data, but the verifier leaves checked direct packet pointers usable after kfunc calls. The bpf_dynptr_write() helper already invalidates packet pointers through clear_all_pkt_pointers(). Make skb dynptr writer kfuncs follow the same rule.
Keep two verifier predicates for this. CFG analysis runs before register states are available, so conservatively mark dynptr writer kfuncs as packet-changing for subprogram summaries. The normal verifier path uses the checked dynptr argument and invalidates only when the written dynptr is, or may be, skb-backed.
Global subprogram dynptr arguments are prepared as unspecialized local dynptr pointers, so treat CONST_PTR_TO_DYNPTR local dynptr writer destinations as possibly packet-backed. This keeps packet pointer invalidation sound both after global subprogram calls and inside global subprogram bodies.
--- include/linux/bpf_verifier.h | 3 ++ kernel/bpf/cfg.c | 2 +- kernel/bpf/verifier.c | 79 +++++++++++++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 2 deletions(-)
include/linux/bpf_verifier.h +3 -0
@@ -1448,6 +1448,7 @@ struct bpf_kfunc_call_arg_meta {/* Out parameters */ u8 release_regno;bool r0_rdonly; +bool pkt_dynptr_write;u32 ret_btf_id;u64 r0_size;u32 subprogno;
@@ -1502,6 +1503,8 @@ static inline bool bpf_is_kfunc_sleepable(struct bpf_kfunc_call_arg_meta *meta) {return meta->kfunc_flags &KF_SLEEPABLE ; } + +bool bpf_kfunc_may_change_pkt_data (struct bpf_kfunc_call_arg_meta *meta);bool bpf_is_kfunc_pkt_changing (struct bpf_kfunc_call_arg_meta *meta);struct bpf_iarray *bpf_iarray_realloc (struct bpf_iarray *old,size_t n_elem);int bpf_copy_insn_array_uniq (struct bpf_map *map,u32 start,u32 end,u32 *off);
kernel/bpf/cfg.c +1 -1
@@ -516,7 +516,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 &&bpf_is_kfunc_sleepable (&meta))mark_subprog_might_sleep (env, t); -if (ret ==0 &&bpf_is_kfunc_pkt_changing (&meta)) +if (ret ==0 &&bpf_kfunc_may_change_pkt_data (&meta))mark_subprog_changes_pkt_data (env, t);if (ret ==0 &&bpf_is_throw_kfunc (insn))mark_subprog_might_throw (env, t);
kernel/bpf/verifier.c +78 -1
105 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The bpf_dynptr_write helper fails to invalidate packet pointers in global subprograms, leading to a Use-After-Free vulnerability. --
commit a8b2f9ebe5479e8968087326226bb472f13ee1e0
Author: Yiyang Chen <[email protected]>
bpf: Fix packet pointer invalidation for skb dynptr writes
This patch ensures that skb-backed dynptr writer kfuncs invalidate checked direct packet pointers, following the same rule as the bpf_dynptr_write() helper. It updates the CFG analysis to mark these kfuncs as packet-changing and invalidates packet pointers when the dynptr might be skb-backed.
[ ... ]
kernel/bpf/cfg.c static int visit_insn(int t, struct bpf_verifier_env *env) · line 520
Quoted 11 lines
kernel/bpf/cfg.c +1
-1@@ -516,7 +516,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 &&bpf_is_kfunc_sleepable (&meta))mark_subprog_might_sleep (env, t); -if (ret ==0 &&bpf_is_kfunc_pkt_changing (&meta)) +if (ret ==0 &&bpf_kfunc_may_change_pkt_data (&meta))mark_subprog_changes_pkt_data (env, t);
[Severity: Critical]
This is a pre-existing issue, but since this patch aims to make kfuncs follow the same rule as the bpf_dynptr_write() helper, could there be a similar regression with the helper itself?
When bpf_dynptr_write() is called within a global subprogram using an unspecialized LOCAL dynptr argument that is actually backed by an skb, does it fail to invalidate packet pointers?
In cfg.c:visit_insn(), CFG analysis appears to miss the side-effect of bpf_dynptr_write() because the helper cannot be included in bpf_helper_changes_pkt_data() without triggering a verifier bug in check_helper_call() (due to its arg1_type being ARG_PTR_TO_DYNPTR instead of ARG_PTR_TO_CTX).
Furthermore, during the normal verification path in verifier.c:check_helper_call(), does the check:
if (dynptr_type == BPF_DYNPTR_TYPE_SKB || dynptr_type == BPF_DYNPTR_TYPE_SKB_META) changes_data = true;
fail to identify BPF_DYNPTR_TYPE_LOCAL arguments from global subprograms that may be skb-backed?
If packet pointers are not invalidated, writing to the dynptr might pull the skb and reallocate the packet buffer, leaving old packet pointers pointing to freed memory and resulting in a use-after-free.
Quoted 2 lines
kernel/bpf/cfg.c +0
-0if (ret ==0 &&bpf_is_throw_kfunc (insn))mark_subprog_might_throw (env, t);
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 18 lines · Yiyang Chen
skb-backed dynptr writer kfuncs can mutate packet data, but the verifier leaves checked direct packet pointers usable after kfunc calls. The
bpf_dynptr_write()helper already invalidates packet pointers throughclear_all_pkt_pointers(). Make skb dynptr writer kfuncs follow the same rule.Keep two verifier predicates for this. CFG analysis runs before register states are available, so conservatively mark dynptr writer kfuncs as packet-changing for subprogram summaries. The normal verifier path uses the checked dynptr argument and invalidates only when the written dynptr is, or may be, skb-backed.
Global subprogram dynptr arguments are prepared as unspecialized local dynptr pointers, so treat
CONST_PTR_TO_DYNPTRlocal dynptr writer destinations as possibly packet-backed. This keeps packet pointer invalidation sound both after global subprogram calls and inside global subprogram bodies.
Quoted 4 lines
Fixes daec295a7094 ("bpf/helpers: Introduce bpf_dynptr_copy kfunc")Fixes a498ee7576de ("bpf: Implement dynptr copy kfuncs")Fixes 5fc5d8fded57 ("bpf: Add bpf_dynptr_memset() kfunc")Signed-off-by Yiyang Chen <[email protected]>
nack.
pw-bot: cr
Thanks, agreed that the previous version used bpf_is_kfunc_pkt_changing() incorrectly. I will rework the fix.
Yiyang
Quoted 3 lines · Yiyang Chen
Thanks, agreed that the previous version used
bpf_is_kfunc_pkt_changing()incorrectly. I will rework the fix.
Pls don't. There is nothing to fix.
I saw your reply after v5 had already been sent. Please disregard this series.
Sorry for the noise.
PATCH v3 2/2 selftests/bpf: Add skb dynptr writer packet invalidation tests
In reply to Yiyang ChenAdd verifier tests for skb dynptr writer kfuncs that must invalidate checked direct packet pointers. Cover bpf_dynptr_memset(), bpf_dynptr_copy() when the skb dynptr is the destination, and probe-read into an skb dynptr.
Keep a source-only bpf_dynptr_copy() case as a positive control, since copying from an skb dynptr into memory does not mutate packet data.
Add global subprogram regressions for stale caller packet pointers after a dynptr writer call and stale packet pointer use inside a global subprogram whose dynptr argument may be skb-backed.
--- .../testing/selftests/bpf/progs/dynptr_fail.c | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+)
tools/testing/selftests/bpf/progs/dynptr_fail.c +140 -0
@@ -1274,6 +1274,146 @@ int skb_invalid_data_slice4(struct __sk_buff *skb)return SK_PASS ; } +char dynptr_kfunc_data[8 ] ="test" ; +char dynptr_kfunc_dst[8 ]; + +extern int bpf_dynptr_copy(const struct bpf_dynptr *dst, __u64 dst_off, + const struct bpf_dynptr *src, __u64 src_off, + __u64 size) __ksym __weak; +extern int bpf_dynptr_memset(const struct bpf_dynptr *ptr, __u64 offset, + __u64 size, __u8 val) __ksym __weak; +extern int bpf_probe_read_kernel_dynptr(const struct bpf_dynptr *dptr, + __u64 off, __u64 size, + const void *unsafe_ptr__ign) __ksym __weak; + +__noinline int global_dynptr_kfunc_memset(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_memset (ptr,0 ,1 ,0 ); +} + +__noinline int global_dynptr_kfunc_memset_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_memset (ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +/* Direct packet pointers are invalidated after a dynptr kfunc writes to an skb */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_dynptr_memset (&ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +/* Global subprogs with dynptr writer kfuncs invalidate caller packet pointers */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_kfunc_memset (&ptr); + +/* this should fail */ +return *data; +} + +/* Global subprog dynptr args may be packet-backed and must invalidate locally */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_memset(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_kfunc_memset_and_read (skb, &ptr); +} + +/* Direct packet pointers are invalidated after bpf_dynptr_copy() writes to an skb */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_copy_dst(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &dst); +bpf_dynptr_from_mem (dynptr_kfunc_data,sizeof (dynptr_kfunc_data),0 , &src); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +/* this should fail */ +return *data; +} + +/* Direct packet pointers stay valid when an skb dynptr is only copied from */ +SEC("?tc") +__success +int skb_pkt_ptr_valid_after_dynptr_copy_src (struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &src); +bpf_dynptr_from_mem (dynptr_kfunc_dst,sizeof (dynptr_kfunc_dst),0 , &dst); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +return *data; +} + +/* Direct packet pointers are invalidated after probe-read writes to an skb dynptr */ +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_probe_read_kernel_dynptr(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_probe_read_kernel_dynptr (&ptr,0 ,1 , dynptr_kfunc_data); + +/* this should fail */ +return *data; +} +/* Read-only skb data slice is invalidated on write to skb metadata */ SEC("?tc") __failure __msg("invalid mem access 'scalar'")
Signature · 1 line
2.34.1
v4 cover bpf: Fix packet pointer invalidation for skb dynptr writes
In reply to Yiyang Chenskb-backed dynptr writers may mutate packet data and therefore must invalidate checked direct packet pointers. The normal verifier path had coverage for bpf_dynptr_write() with concrete skb dynptrs, but missed unspecialized global subprogram dynptr arguments. skb dynptr writer kfuncs also did not participate in packet pointer invalidation.
Fix both paths by adding conservative static CFG predicates for bpf_dynptr_write() and skb dynptr writer kfuncs, while keeping the normal verifier invalidation tied to the checked dynptr argument. Extend dynptr_fail coverage for helper and kfunc writes, including global subprogram caller-side and callee-side cases.
Validation, rebased and tested on bpf.git master 8cd9520d35a6 ("Linux 7.1"):
git diff --check HEAD~2..HEAD: OK
scripts/checkpatch.pl --strict --no-tree: OK
make O=/tmp/patch008-v4-bpf-build olddefconfig: OK
make O=/tmp/patch008-v4-bpf-build -j$(nproc) \
kernel/bpf/verifier.o kernel/bpf/cfg.o: OK
clang --target=bpfel ... dynptr_fail.c: OK
make O=/tmp/patch008-v4-bpf-build -j$(nproc) bzImage: OK
QEMU replay on 7.1.0-g5a2ca20101d9: PATCH008_SUMMARY failures=0 total=8Changes in v4:
- Rebase from bpf-next to current bpf.git master 8cd9520d35a6 to resolve
CI conflict.
- Address the helper-side global subprogram case for bpf_dynptr_write().
- Keep bpf_helper_changes_pkt_data() precise and add a separate static bpf_helper_may_change_pkt_data() predicate for CFG summaries.
- Keep kfunc CFG summaries conservative while preserving checked-argument precision in the normal verifier path.
- Extend selftests and QEMU replay coverage with bpf_dynptr_write() global-subprogram cases.
- Link to v3: https://patch.msgid.link/[email protected]
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 + include/linux/filter.h | 5 + kernel/bpf/cfg.c | 4 +- kernel/bpf/verifier.c | 88 ++++++++- .../testing/selftests/bpf/progs/dynptr_fail.c | 183 ++++++++++++++++++ 5 files changed, 278 insertions(+), 5 deletions(-)
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
Signature · 1 line
2.34.1
PATCH v4 1/2 bpf: Fix packet pointer invalidation for skb dynptr writes
skb-backed dynptr writers can mutate packet data, but not all verifier paths invalidate checked direct packet pointers after those writes.
bpf_dynptr_write() handles skb and skb-meta dynptrs in the normal helper path, but global subprogram dynptr arguments are verified as unspecialized local dynptr pointers. Treat CONST_PTR_TO_DYNPTR local arguments as possibly packet-backed for packet pointer invalidation.
Global subprogram summaries are computed during CFG analysis before register states exist. Add conservative static CFG predicates for bpf_dynptr_write() and skb dynptr writer kfuncs so caller-side packet pointers are invalidated after global calls that may write packet data.
Keep the normal verifier invalidation precise: helpers and kfuncs still use the checked dynptr argument and only invalidate when the written dynptr is, or may be, skb-backed. Source-only dynptr arguments remain unchanged.
--- include/linux/bpf_verifier.h | 3 ++ include/linux/filter.h | 5 ++ kernel/bpf/cfg.c | 4 +- kernel/bpf/verifier.c | 88 ++++++++++++++++++++++++++++++++++-- 4 files changed, 95 insertions(+), 5 deletions(-)
include/linux/bpf_verifier.h +3 -0
@@ -1332,6 +1332,7 @@ struct bpf_kfunc_call_arg_meta {u32 ref_obj_id;u8 release_regno;bool r0_rdonly; +bool pkt_dynptr_write;u32 ret_btf_id;u64 r0_size;u32 subprogno;
@@ -1389,6 +1390,8 @@ static inline bool bpf_is_kfunc_sleepable(struct bpf_kfunc_call_arg_meta *meta) {return meta->kfunc_flags &KF_SLEEPABLE ; } + +bool bpf_kfunc_may_change_pkt_data (struct bpf_kfunc_call_arg_meta *meta);bool bpf_is_kfunc_pkt_changing (struct bpf_kfunc_call_arg_meta *meta);struct bpf_iarray *bpf_iarray_realloc (struct bpf_iarray *old,size_t n_elem);int bpf_copy_insn_array_uniq (struct bpf_map *map,u32 start,u32 end,u32 *off);
include/linux/filter.h +5 -0
@@ -1172,6 +1172,11 @@ void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bpu64 arch_bpf_timed_may_goto (void );u64 bpf_check_timed_may_goto (struct bpf_timed_may_goto *);bool bpf_helper_changes_pkt_data (enum bpf_func_id func_id); +static inline bool bpf_helper_may_change_pkt_data (enum bpf_func_id func_id) +{ +return bpf_helper_changes_pkt_data (func_id) || + func_id == BPF_FUNC_dynptr_write; +}static inline bool bpf_dump_raw_ok (const struct cred *cred) {
kernel/bpf/cfg.c +2 -2
@@ -483,7 +483,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 && fp->might_sleep)mark_subprog_might_sleep (env, t); -if (bpf_helper_changes_pkt_data (insn->imm)) +if (bpf_helper_may_change_pkt_data (insn->imm))mark_subprog_changes_pkt_data (env, t);if (insn->imm == BPF_FUNC_tail_call) { ret =visit_abnormal_return_insn (env, t);
@@ -516,7 +516,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 &&bpf_is_kfunc_sleepable (&meta))mark_subprog_might_sleep (env, t); -if (ret ==0 &&bpf_is_kfunc_pkt_changing (&meta)) +if (ret ==0 &&bpf_kfunc_may_change_pkt_data (&meta))mark_subprog_changes_pkt_data (env, t);if (ret ==0 &&bpf_is_throw_kfunc (insn))mark_subprog_might_throw (env, t);
kernel/bpf/verifier.c +85 -3
126 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Bypasses in the packet pointer invalidation logic for global subprogram dynptrs allow Use-After-Free of reallocated SKB data. --
commit 3d7aef2edf3e68f7deac1e4457119dd95d6770d0
Author: Yiyang Chen <[email protected]>
bpf: Fix packet pointer invalidation for skb dynptr writes
skb-backed dynptr writers can mutate packet data, but not all verifier paths invalidate checked direct packet pointers after those writes. This patch treats CONST_PTR_TO_DYNPTR local arguments as possibly packet-backed for packet pointer invalidation.
Quoted 4 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
Quoted 9 lines
kernel/bpf/verifier.c +5
-0@@ -9155,6 +9155,23 @@ static void clear_all_pkt_pointers(struct bpf_verifier_env *env) })); } +static bool dynptr_type_pkt_data (enum bpf_dynptr_type type) +{ +return type ==BPF_DYNPTR_TYPE_SKB || + type ==BPF_DYNPTR_TYPE_SKB_META ; +}
kernel/bpf/verifier.c static void clear_all_pkt_pointers(struct bpf_verifier_env *env) · line 9172
Quoted 10 lines
kernel/bpf/verifier.c +10
-0+ +static bool dynptr_may_be_pkt_data (const struct bpf_reg_state *reg, +enum bpf_dynptr_type type) +{ +if (dynptr_type_pkt_data (type)) +return true; + +/* Global subprog dynptr args are verified as unspecialized LOCAL. */ +return reg->type ==CONST_PTR_TO_DYNPTR && + type ==BPF_DYNPTR_TYPE_LOCAL ;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: Critical]
This is a pre-existing issue, but does this incomplete fix leave two bypasses for packet pointer invalidation?
First, if the BPF program clones the global dynptr using bpf_dynptr_clone(), the clone is stored on the stack and typed as PTR_TO_STACK (inheriting BPF_DYNPTR_TYPE_LOCAL). If a dynptr writer like bpf_dynptr_write() is then called on the clone, it appears dynptr_may_be_pkt_data() will return false since the register type is PTR_TO_STACK instead of CONST_PTR_TO_DYNPTR. This would skip clear_all_pkt_pointers() entirely.
Second, if the BPF program obtains a direct slice from the global dynptr via bpf_dynptr_slice_rdwr(), the returned pointer gets the type PTR_TO_MEM | DYNPTR_TYPE_LOCAL. If a dynptr writer is subsequently called on the original global dynptr, clear_all_pkt_pointers() is triggered but fails to invalidate the slice because reg_is_dynptr_slice_pkt() explicitly ignores DYNPTR_TYPE_LOCAL slices:
kernel/bpf/verifier.c:reg_is_dynptr_slice_pkt() {
return base_type(reg->type) == PTR_TO_MEM &&
(reg->type &
(DYNPTR_TYPE_SKB | DYNPTR_TYPE_XDP | DYNPTR_TYPE_SKB_META));
}Could both scenarios allow a Use-After-Free read/write on the reallocated skb data?
Quoted 2 lines
kernel/bpf/verifier.c +2
-0+} +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v4 2/2 selftests/bpf: Add skb dynptr writer packet invalidation tests
In reply to Yiyang ChenAdd verifier tests for stale direct packet pointers after skb dynptr writes through bpf_dynptr_write() and dynptr writer kfuncs.
Cover global subprogram cases for both caller-side packet pointer invalidation and local packet pointer invalidation inside the subprogram body. These cases exercise the static CFG summary path and the precise verifier path for unspecialized global dynptr arguments.
Also cover direct kfunc writes through bpf_dynptr_memset(), bpf_dynptr_copy() when the skb dynptr is the destination, and probe-read into an skb dynptr. Keep a source-only bpf_dynptr_copy() case as a positive control.
--- .../testing/selftests/bpf/progs/dynptr_fail.c | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+)
tools/testing/selftests/bpf/progs/dynptr_fail.c +183 -0
@@ -1232,6 +1232,189 @@ int skb_invalid_data_slice4(struct __sk_buff *skb)return SK_PASS ; } +char dynptr_writer_data[8 ] ="test" ; +char dynptr_writer_dst[8 ]; + +extern int bpf_dynptr_copy(struct bpf_dynptr *dst, __u64 dst_off, + struct bpf_dynptr *src, __u64 src_off, + __u64 size) __ksym __weak; +extern int bpf_dynptr_memset(struct bpf_dynptr *ptr, __u64 offset, + __u64 size, __u8 val) __ksym __weak; +extern int bpf_probe_read_kernel_dynptr(struct bpf_dynptr *dptr, + __u64 off, __u64 size, + const void *unsafe_ptr__ign) __ksym __weak; + +__noinline int global_dynptr_helper_write(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); +} + +__noinline int global_dynptr_helper_write_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); + +/* this should fail */ +return *data; +} + +__noinline int global_dynptr_kfunc_memset(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_memset (ptr,0 ,1 ,0 ); +} + +__noinline int global_dynptr_kfunc_memset_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_memset (ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_write(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_helper_write (&ptr); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_write(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_helper_write_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_dynptr_memset (&ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_kfunc_memset (&ptr); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_memset(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_kfunc_memset_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_copy_dst(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &dst); +bpf_dynptr_from_mem (dynptr_writer_data,sizeof (dynptr_writer_data),0 , &src); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__success +int skb_pkt_ptr_valid_after_dynptr_copy_src (struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &src); +bpf_dynptr_from_mem (dynptr_writer_dst,sizeof (dynptr_writer_dst),0 , &dst); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_probe_read_kernel_dynptr(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_probe_read_kernel_dynptr (&ptr,0 ,1 , dynptr_writer_data); + +/* this should fail */ +return *data; +} +/* Read-only skb data slice is invalidated on write to skb metadata */ SEC("?tc") __failure __msg("invalid mem access 'scalar'")
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH bpf v4 2/2] selftests/bpf: Add skb dynptr writer packet invalidation tests
This patch series was NACKed by Alexei Starovoitov in v3 with the comment "nack. pw-bot: cr" (change requested). The companion verifier fix patch (patch 1/2 in the series) was rejected, which blocks…
Quoted 179 lines
tools/testing/selftests/bpf/progs/dynptr_fail.c +172
-0@@ -1232,6 +1232,189 @@ int skb_invalid_data_slice4(struct __sk_buff *skb)return SK_PASS ; } +char dynptr_writer_data[8 ] ="test" ; +char dynptr_writer_dst[8 ]; + +extern int bpf_dynptr_copy(struct bpf_dynptr *dst, __u64 dst_off, + struct bpf_dynptr *src, __u64 src_off, + __u64 size) __ksym __weak; +extern int bpf_dynptr_memset(struct bpf_dynptr *ptr, __u64 offset, + __u64 size, __u8 val) __ksym __weak; +extern int bpf_probe_read_kernel_dynptr(struct bpf_dynptr *dptr, + __u64 off, __u64 size, + const void *unsafe_ptr__ign) __ksym __weak; + +__noinline int global_dynptr_helper_write(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); +} + +__noinline int global_dynptr_helper_write_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); + +/* this should fail */ +return *data; +} + +__noinline int global_dynptr_kfunc_memset(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_memset (ptr,0 ,1 ,0 ); +} + +__noinline int global_dynptr_kfunc_memset_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_memset (ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_write(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_helper_write (&ptr); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_write(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_helper_write_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_dynptr_memset (&ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_kfunc_memset (&ptr); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_memset(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_kfunc_memset_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_copy_dst(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &dst); +bpf_dynptr_from_mem (dynptr_writer_data,sizeof (dynptr_writer_data),0 , &src); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__success +int skb_pkt_ptr_valid_after_dynptr_copy_src (struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &src); +bpf_dynptr_from_mem (dynptr_writer_dst,sizeof (dynptr_writer_dst),0 , &dst); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_probe_read_kernel_dynptr(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr;
tools/testing/selftests/bpf/progs/dynptr_fail.c int skb_invalid_data_slice4(struct __sk_buff *skb) · line 1416
Quoted 10 lines
tools/testing/selftests/bpf/progs/dynptr_fail.c +10
-0+ +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_probe_read_kernel_dynptr (&ptr,0 ,1 , dynptr_writer_data); + +/* this should fail */ +return *data; +}
This patch series was NACKed by Alexei Starovoitov in v3 with the comment "nack. pw-bot: cr" (change requested). The companion verifier fix patch (patch 1/2 in the series) was rejected, which blocks this selftest patch from landing. A v4 was posted to address the helper-side bpf_dynptr_write() case, but has not yet received maintainer feedback.
Are there plans to address the maintainer feedback and resubmit the series?
Reference: https://lore.kernel.org/bpf/[email protected]/
---
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/27557183694
v5 cover bpf: Fix packet pointer invalidation for skb dynptr writes
In reply to Yiyang Chenskb-backed dynptr writers may mutate packet data and therefore must invalidate checked direct packet pointers. The normal verifier path had coverage for bpf_dynptr_write() with concrete skb dynptrs, but missed unspecialized global subprogram dynptr arguments. skb dynptr writer kfuncs also did not participate in packet pointer invalidation.
Fix both paths by adding conservative static CFG predicates for bpf_dynptr_write() and skb dynptr writer kfuncs, while keeping the normal verifier invalidation tied to the checked dynptr argument. Track when a LOCAL dynptr may actually be packet-backed, and propagate that state through dynptr clones and returned dynptr slices.
Validation, rebased and tested on bpf.git master 0e0611827f33
("Merge tag 'pull-fixes' of gitolite.kernel.org:pub/scm/linux/kernel/git/viro/vfs"):
git diff --check HEAD~2..HEAD: OK
scripts/checkpatch.pl --strict --no-tree: OK
make O=/tmp/patch008-v4-bpf-build -j16 \
kernel/bpf/verifier.o kernel/bpf/cfg.o kernel/bpf/states.o: OK
clang --target=bpfel ... dynptr_fail.c: OK
make O=/tmp/patch008-v4-bpf-build -j16 bzImage: OK
QEMU replay on 7.1.0-g7feeed42d8b9:
PATCH008_SUMMARY failures=0 total=10Changes in v5:
- Carry maybe-packet-backed dynptr state for unspecialized global subprogram dynptr arguments.
- Propagate that state through bpf_dynptr_clone() and dynptr slice returns.
- Invalidate LOCAL-typed dynptr slices when they may refer to packet data.
- Include the new dynptr state bit in stack state pruning comparisons.
- Add selftests for the global-dynptr clone and LOCAL-slice bypasses.
- Rebase onto bpf.git master 0e0611827f33.
- Link to v4: https://patch.msgid.link/[email protected]
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 | 6 + include/linux/filter.h | 5 + kernel/bpf/cfg.c | 4 +- kernel/bpf/states.c | 2 + kernel/bpf/verifier.c | 145 +++++++++-- .../testing/selftests/bpf/progs/dynptr_fail.c | 238 ++++++++++++++++++ 6 files changed, 382 insertions(+), 18 deletions(-)
base-commit: 0e0611827f3349d0a2ac121c023a6d3260dcecdb
Signature · 1 line
2.34.1
PATCH v5 1/2 bpf: Fix packet pointer invalidation for skb dynptr writes
skb-backed dynptr writers can mutate packet data, but not all verifier paths invalidate checked direct packet pointers after those writes.
bpf_dynptr_write() handles skb and skb-meta dynptrs in the normal helper path, but global subprogram dynptr arguments are verified as unspecialized local dynptr pointers. Treat such arguments as possibly packet-backed for packet pointer invalidation.
Carry that possibly-packet-backed state through dynptr clones and dynptr slices. Otherwise a global subprogram can clone its dynptr argument and write through the stack clone, or obtain a LOCAL-typed dynptr slice and write through the original dynptr, without invalidating packet pointers or slice pointers that may refer to reallocated skb data.
Global subprogram summaries are computed during CFG analysis before register states exist. Add conservative static CFG predicates for bpf_dynptr_write() and skb dynptr writer kfuncs so caller-side packet pointers are invalidated after global calls that may write packet data.
Keep the normal verifier invalidation precise: helpers and kfuncs still use the checked dynptr argument and only invalidate when the written dynptr is, or may be, skb-backed. Source-only dynptr arguments remain unchanged.
--- include/linux/bpf_verifier.h | 6 ++ include/linux/filter.h | 5 ++ kernel/bpf/cfg.c | 4 +- kernel/bpf/states.c | 2 + kernel/bpf/verifier.c | 145 +++++++++++++++++++++++++++++++---- 5 files changed, 144 insertions(+), 18 deletions(-)
include/linux/bpf_verifier.h +6 -0
@@ -66,11 +66,13 @@ struct bpf_reg_state {struct {/* for PTR_TO_MEM | PTR_TO_MEM_OR_NULL */ u32 mem_size;u32 dynptr_id;/* for dynptr slices */ +bool dynptr_may_be_pkt_data;/* for dynptr slices */ };/* For dynptr stack slots */ struct {enum bpf_dynptr_type type; +bool may_be_pkt_data;/* A dynptr is 16 bytes so it takes up 2 stack slots. * We need to track which slot is the first slot * to protect against cases where the user may try to
@@ -1332,6 +1334,7 @@ struct bpf_kfunc_call_arg_meta {u32 ref_obj_id;u8 release_regno;bool r0_rdonly; +bool pkt_dynptr_write;u32 ret_btf_id;u64 r0_size;u32 subprogno;
@@ -1365,6 +1368,7 @@ struct bpf_kfunc_call_arg_meta {enum bpf_dynptr_type type;u32 id;u32 ref_obj_id; +bool may_be_pkt_data; } initialized_dynptr;struct {u8 spi;
@@ -1389,6 +1393,8 @@ static inline bool bpf_is_kfunc_sleepable(struct bpf_kfunc_call_arg_meta *meta) {return meta->kfunc_flags &KF_SLEEPABLE ; } + +bool bpf_kfunc_may_change_pkt_data (struct bpf_kfunc_call_arg_meta *meta);bool bpf_is_kfunc_pkt_changing (struct bpf_kfunc_call_arg_meta *meta);struct bpf_iarray *bpf_iarray_realloc (struct bpf_iarray *old,size_t n_elem);int bpf_copy_insn_array_uniq (struct bpf_map *map,u32 start,u32 end,u32 *off);
include/linux/filter.h +5 -0
@@ -1172,6 +1172,11 @@ void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bpu64 arch_bpf_timed_may_goto (void );u64 bpf_check_timed_may_goto (struct bpf_timed_may_goto *);bool bpf_helper_changes_pkt_data (enum bpf_func_id func_id); +static inline bool bpf_helper_may_change_pkt_data (enum bpf_func_id func_id) +{ +return bpf_helper_changes_pkt_data (func_id) || + func_id == BPF_FUNC_dynptr_write; +}static inline bool bpf_dump_raw_ok (const struct cred *cred) {
kernel/bpf/cfg.c +2 -2
@@ -483,7 +483,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 && fp->might_sleep)mark_subprog_might_sleep (env, t); -if (bpf_helper_changes_pkt_data (insn->imm)) +if (bpf_helper_may_change_pkt_data (insn->imm))mark_subprog_changes_pkt_data (env, t);if (insn->imm == BPF_FUNC_tail_call) { ret =visit_abnormal_return_insn (env, t);
@@ -516,7 +516,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 &&bpf_is_kfunc_sleepable (&meta))mark_subprog_might_sleep (env, t); -if (ret ==0 &&bpf_is_kfunc_pkt_changing (&meta)) +if (ret ==0 &&bpf_kfunc_may_change_pkt_data (&meta))mark_subprog_changes_pkt_data (env, t);if (ret ==0 &&bpf_is_throw_kfunc (insn))mark_subprog_might_throw (env, t);
kernel/bpf/states.c +2 -0
@@ -798,6 +798,8 @@ static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old, old_reg = &old->stack[spi].spilled_ptr; cur_reg = &cur->stack[spi].spilled_ptr;if (old_reg->dynptr.type != cur_reg->dynptr.type || + old_reg->dynptr.may_be_pkt_data != + cur_reg->dynptr.may_be_pkt_data || old_reg->dynptr.first_slot != cur_reg->dynptr.first_slot || !check_ids (old_reg->ref_obj_id, cur_reg->ref_obj_id, idmap))return false;
kernel/bpf/verifier.c +129 -16
280 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 20 lines · Yiyang Chen
skb-backed dynptr writers can mutate packet data, but not all verifier paths invalidate checked direct packet pointers after those writes.
bpf_dynptr_write()handles skb and skb-meta dynptrs in the normal helper path, but global subprogram dynptr arguments are verified as unspecialized local dynptr pointers. Treat such arguments as possibly packet-backed for packet pointer invalidation.Carry that possibly-packet-backed state through dynptr clones and dynptr slices. Otherwise a global subprogram can clone its dynptr argument and write through the stack clone, or obtain a LOCAL-typed dynptr slice and write through the original dynptr, without invalidating packet pointers or slice pointers that may refer to reallocated skb data.
Global subprogram summaries are computed during CFG analysis before register states exist. Add conservative static CFG predicates for
bpf_dynptr_write()and skb dynptr writer kfuncs so caller-side packet pointers are invalidated after global calls that may write packet data.
Quoted 4 lines
Keep the normal verifier invalidation precise: helpers and kfuncs still use the checked dynptr argument and only invalidate when the written dynptr is, or may be, skb-backed. Source-only dynptr arguments remain unchanged.
Nack.
Nothing to fix.
pw-bot: cr
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Use-After-Free due to lost packet-ness for ARG_PTR_TO_MEM in global subprograms --
commit 92dda8a7f4645930c007cf11da0767480bfbc820
Author: Yiyang Chen <[email protected]>
bpf: Fix packet pointer invalidation for skb dynptr writes
This commit fixes a missing packet pointer invalidation bug for skb dynptrs. It adds conservative static CFG predicates to track when global subprograms might modify packet data through dynptrs, ensuring proper caller-side invalidation.
Quoted 3 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
kernel/bpf/verifier.c static int do_check_common(struct bpf_verifier_env *env, int subprog) · line 18881
Quoted 8 lines
kernel/bpf/verifier.c +1
-0@@ -18763,6 +18875,7 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog) }else if (arg->arg_type == (ARG_PTR_TO_DYNPTR |MEM_RDONLY )) {/* assume unspecial LOCAL dynptr type */ __mark_dynptr_reg (reg,BPF_DYNPTR_TYPE_LOCAL , true, ++env->id_gen); + reg->dynptr.may_be_pkt_data = true; }else if (base_type (arg->arg_type) ==ARG_PTR_TO_MEM ) { reg->type =PTR_TO_MEM ; reg->type |= arg->arg_type &
[Severity: Critical]
This is a pre-existing issue, but does this generic memory pointer need similar packet-ness tracking to prevent a use-after-free regression?
When a global subprogram expects a pointer to a sized type, it is categorized as ARG_PTR_TO_MEM. The caller might pass a direct packet pointer or a packet-backed dynptr slice, which is allowed if bounds checks are satisfied.
Because the register state is zero-initialized and not explicitly updated here, the dynptr_may_be_pkt_data flag remains false. If the subprogram then calls a packet-reallocating helper like bpf_xdp_adjust_head(), the clear_all_pkt_pointers() routine might fail to invalidate this register since reg_is_dynptr_slice_pkt() would return false.
Can the subprogram then continue to access the reallocated and freed packet memory?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/2 selftests/bpf: Add skb dynptr writer packet invalidation tests
In reply to Yiyang ChenAdd verifier tests for stale direct packet pointers after skb dynptr writes through bpf_dynptr_write() and dynptr writer kfuncs.
Cover global subprogram cases for both caller-side packet pointer invalidation and local packet pointer invalidation inside the subprogram body. These cases exercise the static CFG summary path and the precise verifier path for unspecialized global dynptr arguments.
Also cover global subprogram bypasses where the dynptr argument is first cloned to the stack, and where a LOCAL-typed dynptr slice is taken before the original dynptr is written.
Also cover direct kfunc writes through bpf_dynptr_memset(), bpf_dynptr_copy() when the skb dynptr is the destination, and probe-read into an skb dynptr. Keep a source-only bpf_dynptr_copy() case as a positive control.
--- .../testing/selftests/bpf/progs/dynptr_fail.c | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+)
tools/testing/selftests/bpf/progs/dynptr_fail.c +238 -0
@@ -1232,6 +1232,244 @@ int skb_invalid_data_slice4(struct __sk_buff *skb)return SK_PASS ; } +char dynptr_writer_data[8 ] ="test" ; +char dynptr_writer_dst[8 ]; + +extern int bpf_dynptr_copy(struct bpf_dynptr *dst, __u64 dst_off, + struct bpf_dynptr *src, __u64 src_off, + __u64 size) __ksym __weak; +extern int bpf_dynptr_memset(struct bpf_dynptr *ptr, __u64 offset, + __u64 size, __u8 val) __ksym __weak; +extern int bpf_probe_read_kernel_dynptr(struct bpf_dynptr *dptr, + __u64 off, __u64 size, + const void *unsafe_ptr__ign) __ksym __weak; + +__noinline int global_dynptr_helper_write(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); +} + +__noinline int global_dynptr_helper_write_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); + +/* this should fail */ +return *data; +} + +__noinline int global_dynptr_clone_write_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr clone; + +if (data +1 > data_end) +return SK_DROP ; +if (bpf_dynptr_clone (ptr, &clone)) +return SK_DROP ; + +bpf_dynptr_write (&clone,0 , dynptr_writer_data,1 ,0 ); + +/* this should fail */ +return *data; +} + +__noinline int global_dynptr_slice_write_and_read(struct bpf_dynptr *ptr) +{ +__u8 buffer[1 ] = {}; +__u8 *data; + + data =bpf_dynptr_slice_rdwr (ptr,0 , buffer,sizeof (buffer)); +if (!data) +return SK_DROP ; + +bpf_dynptr_write (ptr,0 , dynptr_writer_data,1 ,0 ); + +/* this should fail */ +return *data; +} + +__noinline int global_dynptr_kfunc_memset(struct bpf_dynptr *ptr) +{ +return bpf_dynptr_memset (ptr,0 ,1 ,0 ); +} + +__noinline int global_dynptr_kfunc_memset_and_read(struct __sk_buff *skb, +struct bpf_dynptr *ptr) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_memset (ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_write(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_helper_write (&ptr); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_write(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_helper_write_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_clone_write(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_clone_write_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_slice_invalid_after_global_dynptr_write(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_slice_write_and_read (&ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_dynptr_memset (&ptr,0 ,1 ,0 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_memset(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_kfunc_memset (&ptr); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_inside_global_dynptr_memset(struct __sk_buff *skb) +{ +struct bpf_dynptr ptr; + +bpf_dynptr_from_skb (skb,0 , &ptr); + +return global_dynptr_kfunc_memset_and_read (skb, &ptr); +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_dynptr_copy_dst(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &dst); +bpf_dynptr_from_mem (dynptr_writer_data,sizeof (dynptr_writer_data),0 , &src); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +/* this should fail */ +return *data; +} + +SEC("?tc") +__success +int skb_pkt_ptr_valid_after_dynptr_copy_src (struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr dst, src; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &src); +bpf_dynptr_from_mem (dynptr_writer_dst,sizeof (dynptr_writer_dst),0 , &dst); +bpf_dynptr_copy (&dst,0 , &src,0 ,1 ); + +return *data; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_probe_read_kernel_dynptr(struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr; + +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +bpf_probe_read_kernel_dynptr (&ptr,0 ,1 , dynptr_writer_data); + +/* this should fail */ +return *data; +} +/* Read-only skb data slice is invalidated on write to skb metadata */ SEC("?tc") __failure __msg("invalid mem access 'scalar'")
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH bpf v5 2/2] selftests/bpf: Add skb dynptr writer packet invalidation tests
These new cases all assert __failure with __msg("invalid mem access 'scalar'"), meaning they expect the verifier to invalidate the direct packet pointer after a skb dynptr write.
Quoted 8 lines
tools/testing/selftests/bpf/progs/dynptr_fail.c +0
-0@@ -1232,6 +1232,244 @@ int skb_invalid_data_slice4(struct __sk_buff *skb)return SK_PASS ; }
[ ... ]
Quoted 7 lines
tools/testing/selftests/bpf/progs/dynptr_fail.c +7
-0+SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int skb_pkt_ptr_invalid_after_global_dynptr_write (struct __sk_buff *skb) +{ +__u8 *data = (void *)(long )skb->data; +__u8 *data_end = (void *)(long )skb->data_end; +struct bpf_dynptr ptr;
tools/testing/selftests/bpf/progs/dynptr_fail.c int skb_invalid_data_slice4(struct __sk_buff *skb) · line 1336
Quoted 10 lines
tools/testing/selftests/bpf/progs/dynptr_fail.c +10
-0+ +if (data +1 > data_end) +return SK_DROP ; + +bpf_dynptr_from_skb (skb,0 , &ptr); +global_dynptr_helper_write (&ptr); + +/* this should fail */ +return *data; +}
These new cases all assert __failure with __msg("invalid mem access 'scalar'"), meaning they expect the verifier to invalidate the direct packet pointer after a skb dynptr write.
This expectation matches the verifier behavior change in the companion patch 1/2 of the series. That verifier change was rejected during review:
Alexei Starovoitov replied "Nack. You misunderstand what bpf_is_kfunc_pkt_changing() is doing." and later "There is nothing to fix.", stating the existing verifier behavior is correct.
If the existing verifier behavior is correct and packet pointers are not invalidated by these dynptr writes, would these __failure expectations hold? It looks like they encode the disputed behavior from the rejected patch 1/2, so should this selftest patch land on its own?
The author appears to have agreed in the discussion and withdrawn the series. Was this patch intended to be dropped along with patch 1/2?
---
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/27565623381