Skip to content

shadow-utils write locks with NUL-terminated contents while uutils/shadow does not. #399

In review

Description

@cqjjjzr

See https://github.com/shadow-maint/shadow/blob/763e75e12be2b389f527502aa66dbca8ae7c8610/lib/commonio.c#L111

stprintf_a(buf, "%lu", (unsigned long) pid);
len = (ssize_t) strlen (buf) + 1;
if (write_full(fd, buf, len) == -1) {

and with shadow-utils + strace I got:

write(5<.../etc/subuid.633201>, "633201\0", 7) = 7
write(6<.../etc/subgid.633201>, "633201\0", 7) = 7

while uutils/shadow doesn't.

This itself does not pose a compatibility issue since users are not expected to have both running on the same system live. However, there maybe edge cases (e.g. switching between the two). Additionally, I ran into this because I was trying to reuse uutils's uu_shadow_core in another small util of mine to handle locking.

This may cause the following:

  1. shadow-utils holds a lock containing 633201\0.
  2. uutils’ trim().parse::<i32>() rejects the NUL.
  3. uutils interprets the parse failure as a stale lock and deletes it.
  4. uutils can then acquire the lock while shadow-utils is still working, breaking mutual exclusion.

A PR is possible if you decided this to be fixed.

Activity

  1. pierre-warnier commented on Dec 5, 2026

    @pierre-warnier
    Collaborator

    Thanks @cqjjjzr, confirmed on Ubuntu 26.04: vipw, vigr and useradd all write the pid followed by a NUL, and our parser deleted such a live lock as stale. Fixed in #427, which writes the same bytes and reads both forms; you are credited in the commit.

  2. cqjjjzr commented on Dec 5, 2026

    @cqjjjzr
    Author

    @pierre-warnier Thank you very much for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions