]> www.pilppa.org Git - linux-2.6-omap-h63xx.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)
commit278a3de5abc7901805689a66340b5af9882b4f9a
treec18ffd5992fb38e3a6322b220fb56a1da6e5aa77
parent007a880d627aee0e854e793099bb33d0c1130678
[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