Skip to content

Commit d946f3c

Browse files
Martin KaFai LauAlexei Starovoitov
authored andcommitted
bpf: Check skb->transport_header is set in bpf_skb_check_mtu
The bpf_skb_check_mtu helper needs to use skb->transport_header when the BPF_MTU_CHK_SEGS flag is used: bpf_skb_check_mtu(skb, ifindex, &mtu_len, 0, BPF_MTU_CHK_SEGS) The transport_header is not always set. There is a WARN_ON_ONCE report when CONFIG_DEBUG_NET is enabled + skb->gso_size is set + bpf_prog_test_run is used: WARNING: CPU: 1 PID: 2216 at ./include/linux/skbuff.h:3071 skb_gso_validate_network_len bpf_skb_check_mtu bpf_prog_3920e25740a41171_tc_chk_segs_flag # A test in the next patch bpf_test_run bpf_prog_test_run_skb For a normal ingress skb (not test_run), skb_reset_transport_header is performed but there is plan to avoid setting it as described in commit 2170a1f ("net: no longer reset transport_header in __netif_receive_skb_core()"). This patch fixes the bpf helper by checking skb_transport_header_was_set(). The check is done just before skb->transport_header is used, to avoid breaking the existing bpf prog. The WARN_ON_ONCE is limited to bpf_prog_test_run, so targeting bpf-next. Fixes: 34b2021 ("bpf: Add BPF-helper for MTU checking") Cc: Jesper Dangaard Brouer <[email protected]> Reported-by: Kaiyan Mei <[email protected]> Reported-by: Yinhao Hu <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 4f7bc83 commit d946f3c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/core/filter.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6429,9 +6429,12 @@ BPF_CALL_5(bpf_skb_check_mtu, struct sk_buff *, skb,
64296429
*/
64306430
if (skb_is_gso(skb)) {
64316431
ret = BPF_MTU_CHK_RET_SUCCESS;
6432-
if (flags & BPF_MTU_CHK_SEGS &&
6433-
!skb_gso_validate_network_len(skb, mtu))
6434-
ret = BPF_MTU_CHK_RET_SEGS_TOOBIG;
6432+
if (flags & BPF_MTU_CHK_SEGS) {
6433+
if (!skb_transport_header_was_set(skb))
6434+
return -EINVAL;
6435+
if (!skb_gso_validate_network_len(skb, mtu))
6436+
ret = BPF_MTU_CHK_RET_SEGS_TOOBIG;
6437+
}
64356438
}
64366439
out:
64376440
*mtu_len = mtu;

0 commit comments

Comments
 (0)