Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Invalid pointer arithmetic `kskb->head + kskb->end` breaks 32-bit compilation and cross-architecture CO-RE portability.
--
--- Patch [6]: [PATCH bpf-next v7 6/6] selftests/bpf: tc_tunnel - validate decap GSO and encapsulation state ---
commit 51cad3ba4cd10bce6b9c9134b5e4188fc76f034c
Author: Nick Hudson <[email protected]>
selftests/bpf: tc_tunnel - validate decap GSO and encapsulation state
This commit tightens tc_tunnel tests by verifying post-decap tunnel
state for both GSO and non-GSO packets. It enforces DECAP flags and
ensures proper clearing of gso_type bits and encapsulation state.
> diff --git a/tools/testing/selftests/bpf/progs/test_tc_tunnel.c b/tools/testing/selftests/bpf/progs/test_tc_tunnel.c
> --- a/tools/testing/selftests/bpf/progs/test_tc_tunnel.c
> +++ b/tools/testing/selftests/bpf/progs/test_tc_tunnel.c
[ ... ]
> @@ -655,6 +688,40 @@ static int decap_internal(struct __sk_buff *skb, int off, int len, char proto)
> if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_MAC, flags))
> return TC_ACT_SHOT;
>
> + kskb = bpf_cast_to_kern_ctx(skb);
> + shinfo = bpf_core_cast(kskb->head + kskb->end, struct skb_shared_info);
^^^^^^^^^^^^^^^^^^^^^
[Severity: Medium]
Does this pointer arithmetic break compilation on 32-bit architectures?
Since kskb->end is a pointer on 32-bit systems (rather than an integer offset
like it is on 64-bit), adding kskb->head and kskb->end together attempts to add
two pointers, which is invalid in C.
Additionally, CO-RE does not translate this pointer-integer addition to a single
pointer dereference when cross-compiled on 64-bit and run on 32-bit kernels,
which can lead to a garbage pointer dereference.
Is there a safer way to calculate the skb_shared_info offset in decap_internal
that is portable across both 32-bit and 64-bit architectures?
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.