Skip to content

Commit c3c7c25

Browse files
Eric Dumazetdavem330
authored andcommitted
net: gro: fix possible panic in skb_gro_receive()
commit 2e71a6f (net: gro: selective flush of packets) added a bug for skbs using frag_list. This part of the GRO stack is rarely used, as it needs skb not using a page fragment for their skb->head. Most drivers do use a page fragment, but some of them use GFP_KERNEL allocations for the initial fill of their RX ring buffer. napi_gro_flush() overwrite skb->prev that was used for these skb to point to the last skb in frag_list. Fix this using a separate field in struct napi_gro_cb to point to the last fragment. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 93b174a commit c3c7c25

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,9 @@ struct napi_gro_cb {
14881488

14891489
/* Used in ipv6_gro_receive() */
14901490
int proto;
1491+
1492+
/* used in skb_gro_receive() slow path */
1493+
struct sk_buff *last;
14911494
};
14921495

14931496
#define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)

net/core/dev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,8 @@ static int napi_gro_complete(struct sk_buff *skb)
34513451
struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK];
34523452
int err = -ENOENT;
34533453

3454+
BUILD_BUG_ON(sizeof(struct napi_gro_cb) > sizeof(skb->cb));
3455+
34543456
if (NAPI_GRO_CB(skb)->count == 1) {
34553457
skb_shinfo(skb)->gso_size = 0;
34563458
goto out;

net/core/skbuff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,7 +3004,7 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb)
30043004
skb_shinfo(nskb)->gso_size = pinfo->gso_size;
30053005
pinfo->gso_size = 0;
30063006
skb_header_release(p);
3007-
nskb->prev = p;
3007+
NAPI_GRO_CB(nskb)->last = p;
30083008

30093009
nskb->data_len += p->len;
30103010
nskb->truesize += p->truesize;
@@ -3030,8 +3030,8 @@ int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb)
30303030

30313031
__skb_pull(skb, offset);
30323032

3033-
p->prev->next = skb;
3034-
p->prev = skb;
3033+
NAPI_GRO_CB(p)->last->next = skb;
3034+
NAPI_GRO_CB(p)->last = skb;
30353035
skb_header_release(skb);
30363036

30373037
done:

0 commit comments

Comments
 (0)