Re: [PATCH] fs: clear close-on-exec flag as part of put_unused_fd()

From: Yann Droneaud
Date: Thu Dec 12 2013 - 05:46:11 EST


Hi,

Le mercredi 11 dÃcembre 2013 Ã 23:36 +0100, Mateusz Guzik a Ãcrit :
> On Wed, Dec 11, 2013 at 10:08:27PM +0100, Yann Droneaud wrote:
> > @@ -806,8 +803,6 @@ static int do_dup2(struct files_struct *files,
> > __set_open_fd(fd, fdt);
> > if (flags & O_CLOEXEC)
> > __set_close_on_exec(fd, fdt);
> > - else
> > - __clear_close_on_exec(fd, fdt);
> > spin_unlock(&files->file_lock);
> >
> > if (tofree)
>
> From my reading this will break at least the following:
> fd = open(..., .. | O_CLOEXEC);
> dup2(whatever, fd);
>
> now fd has O_CLOEXEC even though it should not
>

Thanks for the review.

You're right.

I've misunderstood the portion of the code handling the case where the
destination fd is already marked as used: -EBUSY is only returned when
the file descriptor is allocaged but not yet installed.

So close-on-exec flag must be cleared in do_dup2().

Regards.

--
Yann Droneaud
OPTEYA


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/