From: David Miller <davem@davemloft.net>
To: rweikusat@mobileactivedefense.com
Cc: dvyukov@google.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, viro@ZenIV.linux.org.uk
Subject: Re: [PATCH] af_unix: Fix splice-bind deadlock
Date: Mon, 04 Jan 2016 23:23:28 -0500 (EST) [thread overview]
Message-ID: <20160104.232328.2119620215364418586.davem@davemloft.net> (raw)
In-Reply-To: <87d1ti1ogp.fsf@doppelsaurus.mobileactivedefense.com>
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Date: Sun, 03 Jan 2016 18:56:38 +0000
> On 2015/11/06, Dmitry Vyukov reported a deadlock involving the splice
> system call and AF_UNIX sockets,
>
> http://lists.openwall.net/netdev/2015/11/06/24
>
> The situation was analyzed as
>
> (a while ago) A: socketpair()
> B: splice() from a pipe to /mnt/regular_file
> does sb_start_write() on /mnt
> C: try to freeze /mnt
> wait for B to finish with /mnt
> A: bind() try to bind our socket to /mnt/new_socket_name
> lock our socket, see it not bound yet
> decide that it needs to create something in /mnt
> try to do sb_start_write() on /mnt, block (it's
> waiting for C).
> D: splice() from the same pipe to our socket
> lock the pipe, see that socket is connected
> try to lock the socket, block waiting for A
> B: get around to actually feeding a chunk from
> pipe to file, try to lock the pipe. Deadlock.
>
> on 2015/11/10 by Al Viro,
>
> http://lists.openwall.net/netdev/2015/11/10/4
>
> The patch fixes this by removing the kern_path_create related code from
> unix_mknod and executing it as part of unix_bind prior acquiring the
> readlock of the socket in question. This means that A (as used above)
> will sb_start_write on /mnt before it acquires the readlock, hence, it
> won't indirectly block B which first did a sb_start_write and then
> waited for a thread trying to acquire the readlock. Consequently, A
> being blocked by C waiting for B won't cause a deadlock anymore
> (effectively, both A and B acquire two locks in opposite order in the
> situation described above).
>
> Dmitry Vyukov(<dvyukov@google.com>) tested the original patch.
>
> Signed-off-by: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Applied and queued up for -stable, thanks Rainer.
prev parent reply other threads:[~2016-01-05 4:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-27 20:13 [PATCH] af_unix: Fix splice-bind deadlock Rainer Weikusat
2015-12-29 10:58 ` Hannes Frederic Sowa
2015-12-31 19:36 ` Rainer Weikusat
2016-01-03 18:03 ` Rainer Weikusat
2016-01-04 23:25 ` Hannes Frederic Sowa
2016-01-06 14:45 ` Rainer Weikusat
2016-01-03 18:04 ` Rainer Weikusat
2016-01-03 18:56 ` Rainer Weikusat
2016-01-05 4:23 ` David Miller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160104.232328.2119620215364418586.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=dvyukov@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rweikusat@mobileactivedefense.com \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).