possible open/unlink race condition?

Mikhail Kruk (meshko@cs.brandeis.edu)
Wed, 14 May 2003 17:41:23 -0400 (EDT)


I'm seeing a possible race condition on 2.4.18. It seems that the
following scenario is possible:

process 1 process 2

open(filename, O_CREATE)
start creating file
put an entry into the directory cache

<CONTEXT SWITCH>
opendir()
readdir() // returns "filename"
unlink(filename) // success
access(filename) // it's gone

<CONTEXTSWITCH>
write the directory update on disk
result: file is resurrected but process 2 thinks it deleted it

-----------------------

The description of file creation in the process 1 is completely made up, I
don't really know how it works and I'm only starting to look at the
kernel, but I just would like to know if something like this is at all
possible. I.e. is it possible that process 1 creates file, process 2
sees that file in a directory and unlinks it, and then process 1 does
something inside the same open call, which resurrects the file?

It really looks like this is happening (very rarely) in an
application I'm debugging.

please cc me, I'm not on the list

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