]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
unix: fix a race condition in unix_release()
authorPaul Moore <pmoore@redhat.com>
Mon, 25 Mar 2013 03:18:33 +0000 (03:18 +0000)
committerPaul Gortmaker <paul.gortmaker@windriver.com>
Mon, 10 Feb 2014 21:10:51 +0000 (16:10 -0500)
commitb34a6044b346f2277fe6e2318db1da2abfd1bf65
tree3ed2a8c69361eddb9aa97998032061e5c6b4c835
parenteb8896864a982080bb25627bdabcfce8561adce4
unix: fix a race condition in unix_release()

commit ded34e0fe8fe8c2d595bfa30626654e4b87621e0 upstream.

As reported by Jan, and others over the past few years, there is a
race condition caused by unix_release setting the sock->sk pointer
to NULL before properly marking the socket as dead/orphaned.  This
can cause a problem with the LSM hook security_unix_may_send() if
there is another socket attempting to write to this partially
released socket in between when sock->sk is set to NULL and it is
marked as dead/orphaned.  This patch fixes this by only setting
sock->sk to NULL after the socket has been marked as dead; I also
take the opportunity to make unix_release_sock() a void function
as it only ever returned 0/success.

Dave, I think this one should go on the -stable pile.

Special thanks to Jan for coming up with a reproducer for this
problem.

Reported-by: Jan Stancek <jan.stancek@gmail.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
net/unix/af_unix.c