0005-sctp-fix-dst-refcnt-leak-in-sctp_v4_get_dst.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Tommi Rantala <[email protected]>
  3. Date: Mon, 5 Feb 2018 21:48:14 +0200
  4. Subject: [PATCH] sctp: fix dst refcnt leak in sctp_v4_get_dst
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Fix dst reference count leak in sctp_v4_get_dst() introduced in commit
  9. 410f03831 ("sctp: add routing output fallback"):
  10. When walking the address_list, successive ip_route_output_key() calls
  11. may return the same rt->dst with the reference incremented on each call.
  12. The code would not decrement the dst refcount when the dst pointer was
  13. identical from the previous iteration, causing the dst refcnt leak.
  14. Testcase:
  15. ip netns add TEST
  16. ip netns exec TEST ip link set lo up
  17. ip link add dummy0 type dummy
  18. ip link add dummy1 type dummy
  19. ip link add dummy2 type dummy
  20. ip link set dev dummy0 netns TEST
  21. ip link set dev dummy1 netns TEST
  22. ip link set dev dummy2 netns TEST
  23. ip netns exec TEST ip addr add 192.168.1.1/24 dev dummy0
  24. ip netns exec TEST ip link set dummy0 up
  25. ip netns exec TEST ip addr add 192.168.1.2/24 dev dummy1
  26. ip netns exec TEST ip link set dummy1 up
  27. ip netns exec TEST ip addr add 192.168.1.3/24 dev dummy2
  28. ip netns exec TEST ip link set dummy2 up
  29. ip netns exec TEST sctp_test -H 192.168.1.2 -P 20002 -h 192.168.1.1 -p 20000 -s -B 192.168.1.3
  30. ip netns del TEST
  31. In 4.4 and 4.9 kernels this results to:
  32. [ 354.179591] unregister_netdevice: waiting for lo to become free. Usage count = 1
  33. [ 364.419674] unregister_netdevice: waiting for lo to become free. Usage count = 1
  34. [ 374.663664] unregister_netdevice: waiting for lo to become free. Usage count = 1
  35. [ 384.903717] unregister_netdevice: waiting for lo to become free. Usage count = 1
  36. [ 395.143724] unregister_netdevice: waiting for lo to become free. Usage count = 1
  37. [ 405.383645] unregister_netdevice: waiting for lo to become free. Usage count = 1
  38. ...
  39. Fixes: 410f03831 ("sctp: add routing output fallback")
  40. Fixes: 0ca50d12f ("sctp: fix src address selection if using secondary addresses")
  41. Signed-off-by: Tommi Rantala <[email protected]>
  42. Acked-by: Marcelo Ricardo Leitner <[email protected]>
  43. Acked-by: Neil Horman <[email protected]>
  44. Signed-off-by: David S. Miller <[email protected]>
  45. Signed-off-by: Fabian Grünbichler <[email protected]>
  46. ---
  47. net/sctp/protocol.c | 10 ++++------
  48. 1 file changed, 4 insertions(+), 6 deletions(-)
  49. diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
  50. index 6a38c2503649..91813e686c67 100644
  51. --- a/net/sctp/protocol.c
  52. +++ b/net/sctp/protocol.c
  53. @@ -514,22 +514,20 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
  54. if (IS_ERR(rt))
  55. continue;
  56. - if (!dst)
  57. - dst = &rt->dst;
  58. -
  59. /* Ensure the src address belongs to the output
  60. * interface.
  61. */
  62. odev = __ip_dev_find(sock_net(sk), laddr->a.v4.sin_addr.s_addr,
  63. false);
  64. if (!odev || odev->ifindex != fl4->flowi4_oif) {
  65. - if (&rt->dst != dst)
  66. + if (!dst)
  67. + dst = &rt->dst;
  68. + else
  69. dst_release(&rt->dst);
  70. continue;
  71. }
  72. - if (dst != &rt->dst)
  73. - dst_release(dst);
  74. + dst_release(dst);
  75. dst = &rt->dst;
  76. break;
  77. }
  78. --
  79. 2.14.2