UPSTREAM: net: Fix use after free in the recvmmsg exit path
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 14 Mar 2016 12:56:35 +0000 (09:56 -0300)
committerMin Chong <mchong@google.com>
Mon, 8 Aug 2016 06:22:14 +0000 (23:22 -0700)
commitee247d4205fdee14675c4068c7fbb2c8118ba4ce
treefe98fd4192afaf7d4e520a8ab6f14e4a67b3fc79
parentf3d9c312b89966b6d1ff9e4c503a7ae6d38e0176
UPSTREAM: net: Fix use after free in the recvmmsg exit path

(cherry picked from commit 34b88a68f26a75e4fded796f1a49c40f82234b7d)

The syzkaller fuzzer hit the following use-after-free:

  Call Trace:
   [<ffffffff8175ea0e>] __asan_report_load8_noabort+0x3e/0x40 mm/kasan/report.c:295
   [<ffffffff851cc31a>] __sys_recvmmsg+0x6fa/0x7f0 net/socket.c:2261
   [<     inline     >] SYSC_recvmmsg net/socket.c:2281
   [<ffffffff851cc57f>] SyS_recvmmsg+0x16f/0x180 net/socket.c:2270
   [<ffffffff86332bb6>] entry_SYSCALL_64_fastpath+0x16/0x7a
  arch/x86/entry/entry_64.S:185

And, as Dmitry rightly assessed, that is because we can drop the
reference and then touch it when the underlying recvmsg calls return
some packets and then hit an error, which will make recvmmsg to set
sock->sk->sk_err, oops, fix it.

Reported-and-Tested-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Fixes: a2e2725541fa ("net: Introduce recvmmsg socket syscall")
http://lkml.kernel.org/r/20160122211644.GC2470@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Change-Id: I2adb0faf595b7b634d9b739dfdd1a47109e20ecb
Bug: 30515201
net/socket.c