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.
Unified · Split
| @@ -627,6 +627,7 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb) · 626 unmodified lines | |||
| 627 | } | 627 | } |
| 628 | 628 | ||
| 629 | extern void kfree_skb(struct sk_buff *skb); | 629 | extern void kfree_skb(struct sk_buff *skb); |
| 630 | extern void kfree_skb_list(struct sk_buff *segs); | ||
| 630 | extern void skb_tx_error(struct sk_buff *skb); | 631 | extern void skb_tx_error(struct sk_buff *skb); |
| 631 | extern void consume_skb(struct sk_buff *skb); | 632 | extern void consume_skb(struct sk_buff *skb); |
| 632 | extern void __kfree_skb(struct sk_buff *skb); | 633 | extern void __kfree_skb(struct sk_buff *skb); |
| @@ -483,15 +483,8 @@ EXPORT_SYMBOL(skb_add_rx_frag); · 482 unmodified lines | |||
| 483 | 483 | ||
| 484 | static void skb_drop_list(struct sk_buff **listp) | 484 | static void skb_drop_list(struct sk_buff **listp) |
| 485 | { | 485 | { |
| 486 | struct sk_buff *list = *listp; | 486 | kfree_skb_list(*listp); |
| 487 | |||
| 488 | *listp = NULL; | 487 | *listp = NULL; |
| 489 | |||
| 490 | do { | ||
| 491 | struct sk_buff *this = list; | ||
| 492 | list = list->next; | ||
| 493 | kfree_skb(this); | ||
| 494 | } while (list); | ||
| 495 | } | 488 | } |
| 496 | 489 | ||
| 497 | static inline void skb_drop_fraglist(struct sk_buff *skb) | 490 | static inline void skb_drop_fraglist(struct sk_buff *skb) |
| @@ -651,6 +644,17 @@ void kfree_skb(struct sk_buff *skb) · 153 unmodified lines | |||
| 651 | } | 644 | } |
| 652 | EXPORT_SYMBOL(kfree_skb); | 645 | EXPORT_SYMBOL(kfree_skb); |
| 653 | 646 | ||
| 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 | |||
| 654 | /** | 658 | /** |
| 655 | * skb_tx_error - report an sk_buff xmit error | 659 | * skb_tx_error - report an sk_buff xmit error |
| 656 | * @skb: buffer that triggered an error | 660 | * @skb: buffer that triggered an error |
| @@ -178,7 +178,7 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb, · 177 unmodified lines | |||
| 178 | 178 | ||
| 179 | err = __skb_linearize(skb); | 179 | err = __skb_linearize(skb); |
| 180 | if (err) { | 180 | if (err) { |
| 181 | kfree_skb(segs); | 181 | kfree_skb_list(segs); |
| 182 | segs = ERR_PTR(err); | 182 | segs = ERR_PTR(err); |
| 183 | goto out; | 183 | goto out; |
| 184 | } | 184 | } |