]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
kcm: fix a socket double free
authorWANG Cong <xiyou.wangcong@gmail.com>
Mon, 29 Aug 2016 04:28:26 +0000 (21:28 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 24 Sep 2016 08:09:25 +0000 (10:09 +0200)
commit581a20a6dac54203f3a5318a747b072cfc5b959b
treec8a4c353433aa99d0bd39911267bb5a534f0006e
parentd13b39d070ef00ca77a9888d535d3f725606d64a
kcm: fix a socket double free

[ Upstream commit c0338aff2260ea6c092806312dbb154cec07a242 ]

Dmitry reported a double free on kcm socket, which could
be easily reproduced by:

#include <unistd.h>
#include <sys/syscall.h>

int main()
{
  int fd = syscall(SYS_socket, 0x29ul, 0x5ul, 0x0ul, 0, 0, 0);
  syscall(SYS_ioctl, fd, 0x89e2ul, 0x20a98000ul, 0, 0, 0);
  return 0;
}

This is because on the error path, after we install
the new socket file, we call sock_release() to clean
up the socket, which leaves the fd pointing to a freed
socket. Fix this by calling sys_close() on that fd
directly.

Fixes: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/kcm/kcmsock.c