net: unix: fix inflight counting bug in garbage collector
authorMiklos Szeredi <mszeredi@suse.cz>
Sun, 9 Nov 2008 19:50:02 +0000 (19:50 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 13 Nov 2008 17:55:58 +0000 (09:55 -0800)
commitdc56d50c44eb80aca5ce60e881c6444f39c82461
treebda9b439a104e1514fb1727ce9cfef7b7b83390d
parentc17e612bc777ee07543e076ebb149b8a71fc1217
net: unix: fix inflight counting bug in garbage collector

commit 6209344f5a3795d34b7f2c0061f49802283b6bdd upstream

Previously I assumed that the receive queues of candidates don't
change during the GC.  This is only half true, nothing can be received
from the queues (see comment in unix_gc()), but buffers could be added
through the other half of the socket pair, which may still have file
descriptors referring to it.

This can result in inc_inflight_move_tail() erronously increasing the
"inflight" counter for a unix socket for which dec_inflight() wasn't
previously called.  This in turn can trigger the "BUG_ON(total_refs <
inflight_refs)" in a later garbage collection run.

Fix this by only manipulating the "inflight" counter for sockets which
are candidates themselves.  Duplicating the file references in
unix_attach_fds() is also needed to prevent a socket becoming a
candidate for GC while the skb that contains it is not yet queued.

Reported-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/net/af_unix.h
net/unix/af_unix.c
net/unix/garbage.c