082-ipv6-ip6_fragment-fix-headroom-tests-and-skb-leak.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From: Florian Westphal <fw@strlen.de>
  2. Date: Thu, 17 Sep 2015 11:24:48 +0100
  3. Subject: [PATCH] ipv6: ip6_fragment: fix headroom tests and skb leak
  4. David Woodhouse reports skb_under_panic when we try to push ethernet
  5. header to fragmented ipv6 skbs:
  6. skbuff: skb_under_panic: text:c1277f1e len:1294 put:14 head:dec98000
  7. data:dec97ffc tail:0xdec9850a end:0xdec98f40 dev:br-lan
  8. [..]
  9. ip6_finish_output2+0x196/0x4da
  10. David further debugged this:
  11. [..] offending fragments were arriving here with skb_headroom(skb)==10.
  12. Which is reasonable, being the Solos ADSL card's header of 8 bytes
  13. followed by 2 bytes of PPP frame type.
  14. The problem is that if netfilter ipv6 defragmentation is used, skb_cow()
  15. in ip6_forward will only see reassembled skb.
  16. Therefore, headroom is overestimated by 8 bytes (we pulled fragment
  17. header) and we don't check the skbs in the frag_list either.
  18. We can't do these checks in netfilter defrag since outdev isn't known yet.
  19. Furthermore, existing tests in ip6_fragment did not consider the fragment
  20. or ipv6 header size when checking headroom of the fraglist skbs.
  21. While at it, also fix a skb leak on memory allocation -- ip6_fragment
  22. must consume the skb.
  23. I tested this e1000 driver hacked to not allocate additional headroom
  24. (we end up in slowpath, since LL_RESERVED_SPACE is 16).
  25. If 2 bytes of headroom are allocated, fastpath is taken (14 byte
  26. ethernet header was pulled, so 16 byte headroom available in all
  27. fragments).
  28. Reported-by: David Woodhouse <dwmw2@infradead.org>
  29. Diagnosed-by: David Woodhouse <dwmw2@infradead.org>
  30. Signed-off-by: Florian Westphal <fw@strlen.de>
  31. Closes 20532
  32. ---
  33. --- a/net/ipv6/ip6_output.c
  34. +++ b/net/ipv6/ip6_output.c
  35. @@ -600,20 +600,22 @@ int ip6_fragment(struct sk_buff *skb, in
  36. }
  37. mtu -= hlen + sizeof(struct frag_hdr);
  38. + hroom = LL_RESERVED_SPACE(rt->dst.dev);
  39. if (skb_has_frag_list(skb)) {
  40. int first_len = skb_pagelen(skb);
  41. struct sk_buff *frag2;
  42. if (first_len - hlen > mtu ||
  43. ((first_len - hlen) & 7) ||
  44. - skb_cloned(skb))
  45. + skb_cloned(skb) ||
  46. + skb_headroom(skb) < (hroom + sizeof(struct frag_hdr)))
  47. goto slow_path;
  48. skb_walk_frags(skb, frag) {
  49. /* Correct geometry. */
  50. if (frag->len > mtu ||
  51. ((frag->len & 7) && frag->next) ||
  52. - skb_headroom(frag) < hlen)
  53. + skb_headroom(frag) < (hlen + hroom + sizeof(struct frag_hdr)))
  54. goto slow_path_clean;
  55. /* Partially cloned skb? */
  56. @@ -630,8 +632,6 @@ int ip6_fragment(struct sk_buff *skb, in
  57. err = 0;
  58. offset = 0;
  59. - frag = skb_shinfo(skb)->frag_list;
  60. - skb_frag_list_init(skb);
  61. /* BUILD HEADER */
  62. *prevhdr = NEXTHDR_FRAGMENT;
  63. @@ -639,8 +639,11 @@ int ip6_fragment(struct sk_buff *skb, in
  64. if (!tmp_hdr) {
  65. IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
  66. IPSTATS_MIB_FRAGFAILS);
  67. - return -ENOMEM;
  68. + err = -ENOMEM;
  69. + goto fail;
  70. }
  71. + frag = skb_shinfo(skb)->frag_list;
  72. + skb_frag_list_init(skb);
  73. __skb_pull(skb, hlen);
  74. fh = (struct frag_hdr *)__skb_push(skb, sizeof(struct frag_hdr));
  75. @@ -738,7 +741,6 @@ slow_path:
  76. */
  77. *prevhdr = NEXTHDR_FRAGMENT;
  78. - hroom = LL_RESERVED_SPACE(rt->dst.dev);
  79. troom = rt->dst.dev->needed_tailroom;
  80. /*