Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Don't redirect packets with invalid pkt_len

Syzbot found an issue [1]: fq_codel_drop() try to drop a flow whitout any
skbs, that is, the flow->head is null.
The root cause, as the [2] says, is because that bpf_prog_test_run_skb()
run a bpf prog which redirects empty skbs.
So we should determine whether the length of the packet modified by bpf
prog or others like bpf_prog_test is valid before forwarding it directly.

LINK: [1] https://syzkaller.appspot.com/bug?id=0b84da80c2917757915afa89f7738a9d16ec96c5
LINK: [2] https://www.spinics.net/lists/netdev/msg777503.html

Reported-by: syzbot+7a12909485b94426aceb@syzkaller.appspotmail.com
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20220715115559.139691-1-shaozhengchao@huawei.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Zhengchao Shao and committed by
Alexei Starovoitov
fd189422 92f61973

+12
+8
include/linux/skbuff.h
··· 2459 2459 2460 2460 #endif /* NET_SKBUFF_DATA_USES_OFFSET */ 2461 2461 2462 + static inline void skb_assert_len(struct sk_buff *skb) 2463 + { 2464 + #ifdef CONFIG_DEBUG_NET 2465 + if (WARN_ONCE(!skb->len, "%s\n", __func__)) 2466 + DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false); 2467 + #endif /* CONFIG_DEBUG_NET */ 2468 + } 2469 + 2462 2470 /* 2463 2471 * Add data to an sk_buff 2464 2472 */
+3
net/bpf/test_run.c
··· 955 955 { 956 956 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb; 957 957 958 + if (!skb->len) 959 + return -EINVAL; 960 + 958 961 if (!__skb) 959 962 return 0; 960 963
+1
net/core/dev.c
··· 4168 4168 bool again = false; 4169 4169 4170 4170 skb_reset_mac_header(skb); 4171 + skb_assert_len(skb); 4171 4172 4172 4173 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP)) 4173 4174 __skb_tstamp_tx(skb, NULL, NULL, skb->sk, SCM_TSTAMP_SCHED);