Bugtraq mailing list archives

Re: Xinetd /tmp race?


From: casper () HOLLAND SUN COM (Casper Dik)
Date: Sat, 14 Nov 1998 12:27:17 +0100


1. I don't think that this is safe over NFS.

Not with NFSv2, but it is safe w/ NFSv3.

The Linux open(2) manpage says:

      O_EXCL When used with O_CREAT, if the file already  exists
             it  is  an error and the open will fail.  O_EXCL is
             broken on NFS file systems, programs which rely  on
             it for performing locking tasks will contain a race
             condition.  The solution for performing atomic file
             locking using a lockfile is to create a unique file
             on the same fs (e.g.,  incorporating  hostname  and
             pid),  use  link(2)  to make a link to the lockfile
             and use stat(2) on the unique file to check if  its
             link  count  has  increased  to  2.  Do not use the
             return value of the link() call.

2. The current behaviour is to append to an existing file if it
exists, or to create a new file if it doesn't. Adding O_EXCL would
break this behaviour.

IMHO, a better approach in this case would be to use a directory which
isn't world-writable e.g. /var/run, /var/log etc.

Seconded.

Casper



Current thread: