Summary: | Unprivileged local user can prevent other users logging in by locking utx.active | ||||||
---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Davin McCall <davmac> | ||||
Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> | ||||
Status: | Open --- | ||||||
Severity: | Affects Many People | CC: | cem, crest, ed, emaste, jilles, kib, secteam, sigsys | ||||
Priority: | Normal | Keywords: | needs-qa, security | ||||
Version: | CURRENT | Flags: | koobs:
maintainer-feedback?
(secteam) |
||||
Hardware: | Any | ||||||
OS: | Any | ||||||
URL: | https://davmac.wordpress.com/2019/05/04/bad-utmp-implementations-in-glibc-and-freebsd/ | ||||||
Attachments: |
|
Description
Davin McCall
2018-11-27 20:03:48 UTC
(a) sort of breaks the libc getutxent APIs for ordinary users. Happily, the getutxent APIs do not try to use locking to get a consistent snapshot of the file, so (b) should fix the problem just fine. https://github.com/freebsd/freebsd/blob/master/lib/libc/gen/getutxent.c Created attachment 199629 [details]
Proposed patch (untested)
CC recent committers (and original author) to lib/libc/gen/pututxline.c who may be able to review attachment 199629 [details] by cem@
Hi there, Instead of going down this road, what are your thoughts on the following? - Tossing out the use of O_EXLOCK entirely and leave the file writing as it is now, - Using a single lock file acquisition in pututxline() to serialise write access all data files in one go. This likely makes the code a bit simpler/lighter, while also improving the sequential consistency guarantees between the data files. (In reply to Ed Schouten from comment #4) Sure, that approach seems unobjectionable to me. Is there any reason to keep this "service" in a flat file? Would it be acceptable to turn it into a directory with one file per user or even require writes to go through a daemon serializing writes and using atomic updates (rename and fsync a temp file)= (In reply to crest from comment #6) Sure, we could! The file format/backend used by this API can now be changed to work any way we want. When I implemented utmpx for FreeBSD, the goal was to first see if we could eliminate any direct access to underlying storage, which has now been realised. That said, to solve this specific issue, there is no need to do anything that drastic. (In reply to Ed Schouten from comment #7) On FreeBSD, we guarantee that reader never see torn writes, assuming writer always write single record using one atomic write(2) syscall, and similarly reader uses single atomic read(2) syscall to get the record. My guess is that if you get rid of stdio(3) use with its buffers, then you can drop O_EXCLOCK and the issue disappears. No, that's not the case. The code does more than simply write a record into the file at a certain offset. It also reads entries to determine what the offset is at which the record should be placed. It's insufficient to replace this code by something that doesn't use file locking. There may be race conditions in which you end up overwriting recently created login session entries. |