[PATCH] dup_fd() part 4 - race fix
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 9 May 2008 01:19:42 +0000 (21:19 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 16 May 2008 21:22:46 +0000 (17:22 -0400)
commitadbecb128cd2cc5d14b0ebef6d020ced0efd0ec6
treeba0f7c202e364002eedc999526ac07262f21dae4
parentafbec7fff4928c273a1f1bb14dfdfdf62688a193
[PATCH] dup_fd() part 4 - race fix

Parent _can_ be a clone task, contrary to the comment.  Moreover,
more files could be opened while we allocate a copy, in which case
we end up copying only part into new descriptor table.  Since what
we get _is_ affected by all changes in the old range, we can get
rather weird effects - e.g.
dup2(0, 1024); close(0);
in parallel with fork() resulting in child that sees the effect of
close(), but not that of dup2() done just before that close().

What we need is to recalculate the open_count after having reacquired
->file_lock and if external fdtable we'd just allocated is too small for
it, free the sucker and redo allocation.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/file.c