Re: agetty and fcntl_setlck()

Marek Michalkiewicz (marekm@i17linuxb.ists.pwr.wroc.pl)
Mon, 20 May 1996 10:49:32 +0200 (MET DST)


Andrew Walker:
> What you're probably seeing is that the routines to write wtmp/utmp
> are calling flock() to lock these files while updating them. So as
> far as the kernel goes there's nothing to fix. You'll probably be able
> to spot the extraneous flock()->fcntl() call by strace'ing agetty.

Yes, it's not really a kernel issue, but since we are talking about
locks I think I should mention it here. Updating wtmp doesn't need
any locking at all - open() with O_APPEND ensures writes at the end
of file. Some programs unfortunately do it (util-linux login for
example). This allows an easy denial of service - any user can open
wtmp and hold a lock on it (a shared lock is enough). Locks should
not be used on important system files which are world readable -
a separate file which is mode 0600 should be used for locking (see
lckpwdf() in libc >= 5.3.5 - can't just lock /etc/passwd, so it does
fcntl() locks on a zero length file /etc/.pwd.lock).

It's OK to use locks, say, on the user's mailbox - but one should be
careful when locking important system files...

Marek