]> git.baikalelectronics.ru Git - kernel.git/commit
[AF_UNIX]: Fix datagram connect race causing an OOPS.
authorDavid S. Miller <davem@sunset.davemloft.net>
Thu, 31 May 2007 22:19:20 +0000 (15:19 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Mon, 4 Jun 2007 01:08:42 +0000 (18:08 -0700)
commit6a0376393780504bc779b989b19322f9c9156337
treec18ffd5992fb38e3a6322b220fb56a1da6e5aa77
parent2355e813f256997b65ec4d4e1cf4f19a9553d67d
[AF_UNIX]: Fix datagram connect race causing an OOPS.

Based upon an excellent bug report and initial patch by
Frederik Deweerdt.

The UNIX datagram connect code blindly dereferences other->sk_socket
via the call down to the security_unix_may_send() function.

Without locking 'other' that pointer can go NULL via unix_release_sock()
which does sock_orphan() which also marks the socket SOCK_DEAD.

So we have to lock both 'sk' and 'other' yet avoid all kinds of
potential deadlocks (connect to self is OK for datagram sockets and it
is possible for two datagram sockets to perform a simultaneous connect
to each other).  So what we do is have a "double lock" function similar
to how we handle this situation in other areas of the kernel.  We take
the lock of the socket pointer with the smallest address first in
order to avoid ABBA style deadlocks.

Once we have them both locked, we check to see if SOCK_DEAD is set
for 'other' and if so, drop everything and retry the lookup.

Signed-off-by: David S. Miller <davem@davemloft.net>
net/unix/af_unix.c