From: ebiederm@xmission.com (Eric W. Biederman)
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: davem@davemloft.net, viro@ftp.linux.org.uk,
alan@lxorguk.ukuu.org.uk, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fix race in AF_UNIX
Date: Thu, 21 Jun 2007 09:18:38 -0600 [thread overview]
Message-ID: <m17ipxfi9d.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <E1HxgeN-0006Io-00@dorka.pomaz.szeredi.hu> (Miklos Szeredi's message of "Mon, 11 Jun 2007 11:57:27 +0200")
Miklos Szeredi <miklos@szeredi.hu> writes:
> [CC'd Al Viro and Alan Cox, restored patch]
>
>> > There are races involving the garbage collector, that can throw away
>> > perfectly good packets with AF_UNIX sockets in them.
>> >
>> > The problems arise when a socket goes from installed to in-flight or
>> > vice versa during garbage collection. Since gc is done with a
>> > spinlock held, this only shows up on SMP.
>> >
>> > Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
>>
>> I'm going to hold off on this one for now.
>>
>> Holding all of the read locks kind of defeats the purpose of using
>> the per-socket lock.
>>
>> Can't you just lock purely around the receive queue operation?
>
> That's already protected by the receive queue spinlock. The race
> however happens _between_ pushing the root set and marking of the
> in-flight but reachable sockets.
>
> If in that space any of the AF_UNIX sockets goes from in-flight to
> installed into a file descriptor, the garbage collector can miss it.
> If we want to protect against this using unix_sk(s)->readlock, then we
> have to hold all of them for the duration of the marking.
>
> Al, Alan, you have more experience with this piece of code. Do you
> have better ideas about how to fix this?
I haven't looked at the code closely enough to be confident of
changing something in this area. However the classic solution to this
kind of gc problem is to mark things that are manipulated during
garbage collection as dirty (not orphaned).
It should be possible to fix this problem by simply changing gc_tree
when we perform a problematic manipulation of a passed socket, such
as installing a passed socket into the file descriptors of a process.
Essentially the idea is moving the current code in the direction of
an incremental gc algorithm.
If I understand the race properly. What happens is that we dequeue
a socket (which has packets in it passing sockets) before the
garbage collector gets to it. Therefore the garbage collector
never processes that socket. So it sounds like we just
need to call maybe_unmark_and_push or possibly just wait for
the garbage collector to complete when we do that and the packet
we have pulled out
So just looking at this quickly. It looks like we need to hold
the u->readlock mutex in garbage.c while looking at the receive
queue. Otherwise we may be processing a packet and have
the file descriptors in limbo. Either that or we need
to slightly extend the scope of the receive queue lock on the
receive side.
Additionally we need to modify unix_notinflight to mark the sockets
as inuse, or to at least wait for the garbage collection to complete.
While being very careful to not add a deadlock scenario.
The require changes to fix this without adding heavy handed locking
look a bit nasty to make.
I half suspect switching to one of the simpler incremental garbage
collection algorithms might not be equally easy to implement and
give us more performance at the same time. Having a garbage collector
that can block has advantages.
The practical problem is you can't modify the list of pushed object
aka gc_tree without holding a lock. And we never drop the
unix_table_lock.
Anyway hopefully that is enough fodder for someone to come up with
a light weight fix for this problem.
Eric
next prev parent reply other threads:[~2007-06-21 15:24 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-02 21:50 [PATCH] fix race in AF_UNIX Miklos Szeredi
2007-06-02 22:11 ` Arnaldo Carvalho de Melo
2007-06-04 9:45 ` Miklos Szeredi
2007-06-05 7:02 ` David Miller
2007-06-05 7:42 ` Miklos Szeredi
2007-06-05 7:55 ` David Miller
2007-06-05 8:11 ` Miklos Szeredi
2007-06-05 8:19 ` David Miller
2007-06-05 20:11 ` David Miller
2007-06-06 0:31 ` David Miller
2007-06-06 5:26 ` Miklos Szeredi
2007-06-06 5:41 ` David Miller
2007-06-06 8:08 ` Miklos Szeredi
2007-06-06 8:12 ` David Miller
2007-06-08 1:47 ` David Miller
2007-06-11 9:57 ` Miklos Szeredi
2007-06-18 7:49 ` Miklos Szeredi
2007-06-18 7:57 ` David Miller
2007-06-18 8:20 ` Miklos Szeredi
2007-06-18 9:18 ` David Miller
2007-06-18 9:29 ` Miklos Szeredi
2007-06-18 9:35 ` David Miller
2007-06-18 9:44 ` Miklos Szeredi
2007-06-18 9:48 ` David Miller
2007-06-18 9:55 ` Miklos Szeredi
2007-06-18 9:59 ` David Miller
2007-06-18 10:32 ` Thomas Graf
2007-06-18 10:39 ` Miklos Szeredi
2007-06-18 10:43 ` Thomas Graf
2007-06-18 12:01 ` Alan Cox
2007-06-18 10:40 ` Thomas Graf
2007-06-18 10:47 ` Miklos Szeredi
2007-06-18 10:51 ` David Miller
2007-06-18 10:55 ` Miklos Szeredi
2007-06-18 11:02 ` David Miller
2007-06-18 11:06 ` Miklos Szeredi
2007-06-18 11:09 ` David Miller
2007-06-18 11:46 ` Miklos Szeredi
2007-06-18 11:47 ` Alan Cox
2007-06-18 11:45 ` Jan Engelhardt
2007-06-18 12:00 ` Miklos Szeredi
2007-06-21 15:18 ` Eric W. Biederman [this message]
2007-06-23 8:48 ` Miklos Szeredi
2007-06-23 16:42 ` Eric W. Biederman
2007-06-26 8:54 ` Miklos Szeredi
2007-06-26 15:24 ` Eric W. Biederman
2007-06-04 9:53 ` Miklos Szeredi
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=m17ipxfi9d.fsf@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=netdev@vger.kernel.org \
--cc=viro@ftp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.