Re: [PATCH] gen_init_cpio: Avoid race between call to stat() andcall to open()

From: Michal Marek
Date: Wed Dec 29 2010 - 08:25:30 EST


On Fri, Dec 24, 2010 at 05:33:48PM -0500, Jeff Garzik wrote:
> On 12/24/2010 03:28 PM, Jesper Juhl wrote:
> >Hi,
> >
> >In usr/gen_init_cpio.c::cpio_mkfile() a call to stat() is made based on
> >pathname, subsequently the file is open()'ed and then the value of the
> >initial stat() call is used to allocate a buffer. This is not safe since
> >the file may change between the call to stat() and the call to open().
> >Safer to just open() the file and then do fstat() using the filedescriptor
> >returned by open.
> >
> >
> >Signed-off-by: Jesper Juhl<jj@xxxxxxxxxxxxx>
>
> Acked-by: Jeff Garzik <jgarzik@xxxxxxxxxx>

Looks like an academic issue to me, but the kernel should promote good
programming practices :). Applied to kbuild-2.6.git#kbuild, thanks.

Michal
--
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/