0073-kernel-add-fix-for-CVE-2016-7117.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Tue, 11 Oct 2016 00:46:56 +0200
  3. Subject: kernel: add fix for CVE-2016-7117
  4. diff --git a/target/linux/generic/patches-3.18/010-net-Fix-use-after-free-in-the-recvmmsg-exit-path.patch b/target/linux/generic/patches-3.18/010-net-Fix-use-after-free-in-the-recvmmsg-exit-path.patch
  5. new file mode 100644
  6. index 0000000..98da375
  7. --- /dev/null
  8. +++ b/target/linux/generic/patches-3.18/010-net-Fix-use-after-free-in-the-recvmmsg-exit-path.patch
  9. @@ -0,0 +1,95 @@
  10. +From cdd1fd36f4b67d9fdbeb1a4d16025192d44a3e8b Mon Sep 17 00:00:00 2001
  11. +Message-Id: <cdd1fd36f4b67d9fdbeb1a4d16025192d44a3e8b.1476139573.git.mschiffer@universe-factory.net>
  12. +From: Arnaldo Carvalho de Melo <acme@redhat.com>
  13. +Date: Mon, 14 Mar 2016 09:56:35 -0300
  14. +Subject: [PATCH] net: Fix use after free in the recvmmsg exit path
  15. +
  16. +[ Upstream commit 34b88a68f26a75e4fded796f1a49c40f82234b7d ]
  17. +
  18. +The syzkaller fuzzer hit the following use-after-free:
  19. +
  20. + Call Trace:
  21. + [<ffffffff8175ea0e>] __asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:295
  22. + [<ffffffff851cc31a>] __sys_recvmmsg+0x6fa/0x7f0 net/socket.c:2261
  23. + [< inline >] SYSC_recvmmsg net/socket.c:2281
  24. + [<ffffffff851cc57f>] SyS_recvmmsg+0x16f/0x180 net/socket.c:2270
  25. + [<ffffffff86332bb6>] entry_SYSCALL_64_fastpath+0x16/0x7a
  26. + arch/x86/entry/entry_64.S:185
  27. +
  28. +And, as Dmitry rightly assessed, that is because we can drop the
  29. +reference and then touch it when the underlying recvmsg calls return
  30. +some packets and then hit an error, which will make recvmmsg to set
  31. +sock->sk->sk_err, oops, fix it.
  32. +
  33. +Reported-and-Tested-by: Dmitry Vyukov <dvyukov@google.com>
  34. +Cc: Alexander Potapenko <glider@google.com>
  35. +Cc: Eric Dumazet <edumazet@google.com>
  36. +Cc: Kostya Serebryany <kcc@google.com>
  37. +Cc: Sasha Levin <sasha.levin@oracle.com>
  38. +Fixes: a2e2725541fa ("net: Introduce recvmmsg socket syscall")
  39. +http://lkml.kernel.org/r/20160122211644.GC2470@redhat.com
  40. +Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  41. +Signed-off-by: David S. Miller <davem@davemloft.net>
  42. +Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
  43. +---
  44. + net/socket.c | 38 +++++++++++++++++++-------------------
  45. + 1 file changed, 19 insertions(+), 19 deletions(-)
  46. +
  47. +diff --git a/net/socket.c b/net/socket.c
  48. +index 02fc7c8..7f61789 100644
  49. +--- a/net/socket.c
  50. ++++ b/net/socket.c
  51. +@@ -2410,31 +2410,31 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
  52. + break;
  53. + }
  54. +
  55. +-out_put:
  56. +- fput_light(sock->file, fput_needed);
  57. +-
  58. + if (err == 0)
  59. +- return datagrams;
  60. ++ goto out_put;
  61. +
  62. +- if (datagrams != 0) {
  63. ++ if (datagrams == 0) {
  64. ++ datagrams = err;
  65. ++ goto out_put;
  66. ++ }
  67. ++
  68. ++ /*
  69. ++ * We may return less entries than requested (vlen) if the
  70. ++ * sock is non block and there aren't enough datagrams...
  71. ++ */
  72. ++ if (err != -EAGAIN) {
  73. + /*
  74. +- * We may return less entries than requested (vlen) if the
  75. +- * sock is non block and there aren't enough datagrams...
  76. ++ * ... or if recvmsg returns an error after we
  77. ++ * received some datagrams, where we record the
  78. ++ * error to return on the next call or if the
  79. ++ * app asks about it using getsockopt(SO_ERROR).
  80. + */
  81. +- if (err != -EAGAIN) {
  82. +- /*
  83. +- * ... or if recvmsg returns an error after we
  84. +- * received some datagrams, where we record the
  85. +- * error to return on the next call or if the
  86. +- * app asks about it using getsockopt(SO_ERROR).
  87. +- */
  88. +- sock->sk->sk_err = -err;
  89. +- }
  90. +-
  91. +- return datagrams;
  92. ++ sock->sk->sk_err = -err;
  93. + }
  94. ++out_put:
  95. ++ fput_light(sock->file, fput_needed);
  96. +
  97. +- return err;
  98. ++ return datagrams;
  99. + }
  100. +
  101. + SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,
  102. +--
  103. +2.10.0
  104. +