`usermod` does not `fsync()` `passwd.lock` file. After hard system reset (power loss) and repeating `usermod` command it fails to read PID from the file since the file becomes empty. Error message: usermod: cannot lock /etc/passwd; try again later.
I suggest using flock() instead
This message is a reminder that Fedora 31 is nearing its end of life. Fedora will stop maintaining and issuing updates for Fedora 31 on 2020-11-24. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as EOL if it remains open with a Fedora 'version' of '31'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, simply change the 'version' to a later Fedora version. Thank you for reporting this issue and we are sorry that we were not able to fix it before Fedora 31 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora, you are encouraged change the 'version' to a later Fedora version prior this bug is closed as described in the policy above. Although we aim to fix as many bugs as possible during every release's lifetime, sometimes those efforts are overtaken by events. Often a more recent Fedora release includes newer upstream software that fixes bugs or makes them obsolete.
Still actual in Fedora 32. Strace: openat(AT_FDCWD, "/etc/passwd.742053", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 7 getpid() = 742053 write(7, "742053\0", 7) = 7 close(7) = 0 link("/etc/passwd.742053", "/etc/passwd.lock") = 0 unlink("/etc/passwd.742053") = 0 As you can see, no fsync() / fadatasync() after writing pid. After reboot file may become empty. To test you can make empty file /etc/passwd.lock and test that usermod will fail.
Moving the version to rawhide, since the problem still exists. As for the solution. Flock file locking can't be used because it doesn't assure process synchronization. So, I've proposed a PR upstream to force file sync after write in lock file: https://github.com/shadow-maint/shadow/pull/293. If you'd like to test it I can create a scratch build, but please tell me which fedora version you are using.
Huge thanks. One more thing (another bug) According to the strace, it opens /etc/passwd with O_TRUNC and writes new contents. If power outage happened at this point, FS may reveal en empty file. In order to overcome, it MUST: 1. open temporary file in the same dir (i.e. in /etc) in secure way like mkostemp() 2. copy owner, group, permissions, possibly some attributes (selinux? extended?) 3. fill it with new data 4. fdatasync() 5. close(tmpfile) 5. move("/etc/passwd.tmp", "/etc/passwd") 6. dirfd = open("/etc", O_DIRECTIRY|O_RDONLY) 7. fdatasync(dirfd) 8. close(dirfd) This is the only way to securely replace a file.
Since this is another bug I'd recommend you to open a new ticket. Indeed, I'd recommend you to open that ticket upstream as it'll get more attention there than in bugzilla (unlikely issue with low impact).
> Flock file locking can't be used because it doesn't assure process synchronization. It's not true. flock() syscall DOES assure inter-process synchronisation.
(In reply to Коренберг Марк from comment #7) > > Flock file locking can't be used because it doesn't assure process synchronization. > > It's not true. flock() syscall DOES assure inter-process synchronisation. Yes, sorry, I misunderstood the explanation in https://gavv.github.io/articles/file-locks/ about flock().
It is irrelevant that flock does it. We cannot change the locking mechanism unless we ensure that anything including third party apps that might be writing to /etc/passwd uses the same mechanism.
* master 599cc003daf833bffdc9cbe0d33dc8b3e7ec74c8 - commonio: force lock file sync
Thanks! About file truncation: https://bugzilla.redhat.com/show_bug.cgi?id=1895831
FEDORA-2020-8425d61a06 has been submitted as an update to Fedora 33. https://bodhi.fedoraproject.org/updates/FEDORA-2020-8425d61a06
FEDORA-2020-8425d61a06 has been pushed to the Fedora 33 testing repository. In short time you'll be able to install the update with the following command: `sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2020-8425d61a06` You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-8425d61a06 See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.
FEDORA-2020-c3d81fda83 has been submitted as an update to Fedora 32. https://bodhi.fedoraproject.org/updates/FEDORA-2020-c3d81fda83
FEDORA-2020-c3d81fda83 has been pushed to the Fedora 32 testing repository. In short time you'll be able to install the update with the following command: `sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2020-c3d81fda83` You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-c3d81fda83 See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.
FEDORA-2020-8425d61a06 has been pushed to the Fedora 33 stable repository. If problem still persists, please make note of it in this bug report.
FEDORA-2020-c3d81fda83 has been pushed to the Fedora 32 stable repository. If problem still persists, please make note of it in this bug report.