Skip to content

Commit fa5ef65

Browse files
Fred Liborkmann
authored andcommitted
bpf: Fix a segment issue when downgrading gso_size
Linearize the skb when downgrading gso_size because it may trigger a BUG_ON() later when the skb is segmented as described in [1,2]. Fixes: 2be7e21 ("bpf: add bpf_skb_adjust_room helper") Signed-off-by: Fred Li <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/all/[email protected] [1] Link: https://lore.kernel.org/all/[email protected] [2] Link: https://lore.kernel.org/bpf/[email protected]
1 parent 13c9b70 commit fa5ef65

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

net/core/filter.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,13 +3548,20 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
35483548
if (skb_is_gso(skb)) {
35493549
struct skb_shared_info *shinfo = skb_shinfo(skb);
35503550

3551-
/* Due to header grow, MSS needs to be downgraded. */
3552-
if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO))
3553-
skb_decrease_gso_size(shinfo, len_diff);
3554-
35553551
/* Header must be checked, and gso_segs recomputed. */
35563552
shinfo->gso_type |= gso_type;
35573553
shinfo->gso_segs = 0;
3554+
3555+
/* Due to header growth, MSS needs to be downgraded.
3556+
* There is a BUG_ON() when segmenting the frag_list with
3557+
* head_frag true, so linearize the skb after downgrading
3558+
* the MSS.
3559+
*/
3560+
if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO)) {
3561+
skb_decrease_gso_size(shinfo, len_diff);
3562+
if (shinfo->frag_list)
3563+
return skb_linearize(skb);
3564+
}
35583565
}
35593566

35603567
return 0;

0 commit comments

Comments
 (0)