0022-sctp-do-not-peel-off-an-assoc-from-one-netns-to-anot.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Xin Long <[email protected]>
  3. Date: Thu, 7 Dec 2017 16:07:00 +0100
  4. Subject: [PATCH] sctp: do not peel off an assoc from one netns to another one
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Now when peeling off an association to the sock in another netns, all
  9. transports in this assoc are not to be rehashed and keep use the old
  10. key in hashtable.
  11. As a transport uses sk->net as the hash key to insert into hashtable,
  12. it would miss removing these transports from hashtable due to the new
  13. netns when closing the sock and all transports are being freeed, then
  14. later an use-after-free issue could be caused when looking up an asoc
  15. and dereferencing those transports.
  16. This is a very old issue since very beginning, ChunYu found it with
  17. syzkaller fuzz testing with this series:
  18. socket$inet6_sctp()
  19. bind$inet6()
  20. sendto$inet6()
  21. unshare(0x40000000)
  22. getsockopt$inet_sctp6_SCTP_GET_ASSOC_ID_LIST()
  23. getsockopt$inet_sctp6_SCTP_SOCKOPT_PEELOFF()
  24. This patch is to block this call when peeling one assoc off from one
  25. netns to another one, so that the netns of all transport would not
  26. go out-sync with the key in hashtable.
  27. Note that this patch didn't fix it by rehashing transports, as it's
  28. difficult to handle the situation when the tuple is already in use
  29. in the new netns. Besides, no one would like to peel off one assoc
  30. to another netns, considering ipaddrs, ifaces, etc. are usually
  31. different.
  32. Reported-by: ChunYu Wang <[email protected]>
  33. Signed-off-by: Xin Long <[email protected]>
  34. Acked-by: Marcelo Ricardo Leitner <[email protected]>
  35. Acked-by: Neil Horman <[email protected]>
  36. Signed-off-by: David S. Miller <[email protected]>
  37. CVE-2017-15115
  38. (cherry picked from commit df80cd9b28b9ebaa284a41df611dbf3a2d05ca74)
  39. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  40. Acked-by: Colin Ian King <[email protected]>
  41. Acked-by: Stefan Bader <[email protected]>
  42. Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]>
  43. Signed-off-by: Fabian Grünbichler <[email protected]>
  44. ---
  45. net/sctp/socket.c | 4 ++++
  46. 1 file changed, 4 insertions(+)
  47. diff --git a/net/sctp/socket.c b/net/sctp/socket.c
  48. index 8d760863bc41..52f388e0448e 100644
  49. --- a/net/sctp/socket.c
  50. +++ b/net/sctp/socket.c
  51. @@ -4894,6 +4894,10 @@ int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
  52. struct socket *sock;
  53. int err = 0;
  54. + /* Do not peel off from one netns to another one. */
  55. + if (!net_eq(current->nsproxy->net_ns, sock_net(sk)))
  56. + return -EINVAL;
  57. +
  58. if (!asoc)
  59. return -EINVAL;
  60. --
  61. 2.14.2