[8553] in bugtraq
Re: Xinetd /tmp race?
daemon@ATHENA.MIT.EDU (Casper Dik)
Sat Nov 14 15:56:47 1998
Date: Sat, 14 Nov 1998 12:27:17 +0100
Reply-To: Casper Dik <casper@HOLLAND.SUN.COM>
From: Casper Dik <casper@HOLLAND.SUN.COM>
X-To: Glynn Clements <glynn@SENSEI.CO.UK>
To: BUGTRAQ@NETSPACE.ORG
In-Reply-To: Your message of "Thu, 12 Nov 1998 20:43:57 GMT."
<13899.18573.790989.190546@cerise.sensei.co.uk>
>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