Skip to content

Commit 2cbb259

Browse files
borkmannMartin KaFai Lau
authored andcommitted
bpf: Reject negative head_room in __bpf_skb_change_head
Yinhao et al. recently reported: Our fuzzing tool was able to create a BPF program which triggered the below BUG condition inside pskb_expand_head. [ 23.016047][T10006] kernel BUG at net/core/skbuff.c:2232! [...] [ 23.017301][T10006] RIP: 0010:pskb_expand_head+0x1519/0x1530 [...] [ 23.021249][T10006] Call Trace: [ 23.021387][T10006] <TASK> [ 23.021507][T10006] ? __pfx_pskb_expand_head+0x10/0x10 [ 23.021725][T10006] __bpf_skb_change_head+0x22a/0x520 [ 23.021939][T10006] bpf_skb_change_head+0x34/0x1b0 [ 23.022143][T10006] ___bpf_prog_run+0xf70/0xb670 [ 23.022342][T10006] __bpf_prog_run32+0xed/0x140 [...] The problem is that in __bpf_skb_change_head() we need to reject a negative head_room as otherwise this propagates all the way to the pskb_expand_head() from skb_cow(). For example, if the BPF test infra passes a skb with gso_skb:1 to the BPF helper with a negative head_room of -22, then this gets passed into skb_cow(). __skb_cow() in this example calculates a delta of -86 which gets aligned to -64, and then triggers BUG_ON(nhead < 0). Thus, reject malformed negative input. Fixes: 3a0af8f ("bpf: BPF for lightweight tunnel infrastructure") Reported-by: Yinhao Hu <[email protected]> Reported-by: Kaiyan Mei <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Reviewed-by: Dongliang Mu <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 8ce93aa commit 2cbb259

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3877,7 +3877,8 @@ static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38773877
u32 new_len = skb->len + head_room;
38783878
int ret;
38793879

3880-
if (unlikely(flags || (!skb_is_gso(skb) && new_len > max_len) ||
3880+
if (unlikely(flags || (int)head_room < 0 ||
3881+
(!skb_is_gso(skb) && new_len > max_len) ||
38813882
new_len < skb->len))
38823883
return -EINVAL;
38833884

0 commit comments

Comments
 (0)