History

gre: fix a possible skb leak

commit 68c331631143 ("v4 GRE: Add TCP segmentation offload for GRE") added a possible skb leak, because it frees only the head of segment list, in case a skb_linearize() call fails. This patch adds a kfree_skb_list() helper to fix the bug.

Eric Dumazet committed 13 years ago

Commit bd8a7031 parent 2b7a5db3 files · +14 −9Browse files

Unified · Split

3 files
  1. include/linux/skbuff.h +1 −0
  2. net/core/skbuff.c +12 −8
  3. net/ipv4/gre.c +1 −1
include/linux/skbuff.h+1−0
@@ -627,6 +627,7 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb) · 626 unmodified lines
627627 }
628628
629629 extern void kfree_skb(struct sk_buff *skb);
630+extern void kfree_skb_list(struct sk_buff *segs);
630631 extern void skb_tx_error(struct sk_buff *skb);
631632 extern void consume_skb(struct sk_buff *skb);
632633 extern void __kfree_skb(struct sk_buff *skb);
net/core/skbuff.c+12−8
@@ -483,15 +483,8 @@ EXPORT_SYMBOL(skb_add_rx_frag); · 482 unmodified lines
483483
484484 static void skb_drop_list(struct sk_buff **listp)
485485 {
486− struct sk_buff *list = *listp;
487−
486+ kfree_skb_list(*listp);
488487 *listp = NULL;
489−
490− do {
491− struct sk_buff *this = list;
492− list = list->next;
493− kfree_skb(this);
494− } while (list);
495488 }
496489
497490 static inline void skb_drop_fraglist(struct sk_buff *skb)
@@ -651,6 +644,17 @@ void kfree_skb(struct sk_buff *skb) · 153 unmodified lines
651644 }
652645 EXPORT_SYMBOL(kfree_skb);
653646
647+void kfree_skb_list(struct sk_buff *segs)
648+{
649+ while (segs) {
650+ struct sk_buff *next = segs->next;
651+
652+ kfree_skb(segs);
653+ segs = next;
654+ }
655+}
656+EXPORT_SYMBOL(kfree_skb_list);
657+
654658 /**
655659 * skb_tx_error - report an sk_buff xmit error
656660 * @skb: buffer that triggered an error
net/ipv4/gre.c+1−1
@@ -178,7 +178,7 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb, · 177 unmodified lines
178178
179179 err = __skb_linearize(skb);
180180 if (err) {
181− kfree_skb(segs);
181+ kfree_skb_list(segs);
182182 segs = ERR_PTR(err);
183183 goto out;
184184 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t