Skip to content

avoid race between systemd-logind and systemd-udevd in setting ACLs#36444

Merged
poettering merged 9 commits intosystemd:mainfrom
yuwata:login-udev-lock-seat
May 14, 2025
Merged

avoid race between systemd-logind and systemd-udevd in setting ACLs#36444
poettering merged 9 commits intosystemd:mainfrom
yuwata:login-udev-lock-seat

Conversation

@yuwata
Copy link
Member

@yuwata yuwata commented Feb 19, 2025

Follow-up for #36408.
Hopefully fixes #24026, #28512, and/or #23547.

@github-actions github-actions bot added udev login please-review PR is ready for (re-)review by a maintainer labels Feb 19, 2025
@yuwata yuwata added this to the v258 milestone Feb 19, 2025
@yuwata
Copy link
Member Author

yuwata commented Feb 19, 2025

Follow-up for #36408.
Not sure, but may fix #24026, #28512, and/or #23547.

@yuwata yuwata force-pushed the login-udev-lock-seat branch from e70fded to b66f6d2 Compare February 19, 2025 17:22
@yuwata yuwata added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels Feb 19, 2025
@wxphaha
Copy link

wxphaha commented Feb 20, 2025

If access to the stat file is locked, is it possible that udev reads the old state file first, but then sets the acl after logind?

@poettering
Copy link
Member

hmm, i wonder if it wouldn't be nicer to just drop the acl mgmt from logind and only do it in udev, and simple trigger the devices again when the session changes? seems much nicer to me as there would be a single owner for ACLs adjustments, not two which fight.

@yuwata
Copy link
Member Author

yuwata commented Feb 25, 2025

hmm, i wonder if it wouldn't be nicer to just drop the acl mgmt from logind and only do it in udev, and simple trigger the devices again when the session changes? seems much nicer to me as there would be a single owner for ACLs adjustments, not two which fight.

Hmmmm, that potentially causes infinite loop...

  1. logind triggers uevent in seat_set_active(),
  2. udev processes the uevent, and broadcasts the result,
  3. logind receives the result, manager_dispatch_device_udev() -> manager_process_seat_device() -> seat_start() -> seat_read_active_vt() -> seat_active_vt_changed() -> seat_set_active() OUCH!

@yuwata
Copy link
Member Author

yuwata commented Feb 25, 2025

Maybe, the potential loop can be avoided by using SYNTH_UUID= property in uevent. I will try later.

@yuwata yuwata force-pushed the login-udev-lock-seat branch from b66f6d2 to bcfa6da Compare February 27, 2025 03:36
@github-actions github-actions bot added build-system util-lib sd-device meson please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Feb 27, 2025
@yuwata yuwata marked this pull request as draft February 27, 2025 03:45
@yuwata yuwata removed the please-review PR is ready for (re-)review by a maintainer label Feb 27, 2025
@yuwata yuwata force-pushed the login-udev-lock-seat branch 2 times, most recently from 61af723 to df9d025 Compare February 27, 2025 04:23
@github-actions github-actions bot added the tests label Feb 27, 2025
@yuwata yuwata marked this pull request as ready for review February 27, 2025 09:59
@github-actions github-actions bot added the please-review PR is ready for (re-)review by a maintainer label Feb 27, 2025
@yuwata
Copy link
Member Author

yuwata commented Feb 28, 2025

@poettering Updated. PTAL.

@yuwata yuwata force-pushed the login-udev-lock-seat branch from df9d025 to 06b2e0d Compare March 4, 2025 10:31
@yuwata yuwata force-pushed the login-udev-lock-seat branch from 13285c2 to 2303cb9 Compare May 13, 2025 16:16
yuwata added 9 commits May 14, 2025 02:06
This also makes device_in_subsystem() and device_is_devtype() return
negative error on critical error
…vent

When udevd broadcasts an event for e.g. a graphics device with master-of-seat
tag, then previously manager_process_seat_device() was called twice for
the event.

With this commit, the function is called only once even for an event for
such device.
…tting ACLs

Previously, both udevd and logind modifies ACLs of a device node. Hence,
there exists a race something like the following:
1. udevd reads an old state file,
2. logind updates the state file, and apply new ACLs,
3. udevd applies ACLs based on the old state file.

This makes logind not update ACLs but trigger uevents for relevant
devices to make ACLs updated by udevd.
As it is now only used by udev-builtin-uaccess.c.

This also makes devnode_acl() use fd rather than path to device node.
@yuwata yuwata force-pushed the login-udev-lock-seat branch from 2303cb9 to 003c6fa Compare May 13, 2025 17:06
@yuwata
Copy link
Member Author

yuwata commented May 13, 2025

@poettering Thank you for the review. All requests are addressed. PTAL.

@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels May 14, 2025
@poettering poettering merged commit 798d140 into systemd:main May 14, 2025
36 of 43 checks passed
@github-actions github-actions bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label May 14, 2025
@yuwata yuwata deleted the login-udev-lock-seat branch May 14, 2025 16:11
@bluca
Copy link
Member

bluca commented May 23, 2025

Commit 'login,udev: avoid race between systemd-logind and systemd-udevd in setting ACLs' introduced a regression, and permission checks for users owning a session no longer works. Eg: in GNOME, when already logged in clicking on suspend/reboot/poweroff in the menu asks the user for authentication, while it didn't before

poettering added a commit that referenced this pull request Sep 23, 2025
github-merge-queue bot pushed a commit to NixOS/nixpkgs that referenced this pull request Oct 20, 2025
This PR systemd/systemd#36444 caused this bug
systemd/systemd#39043, which is fixed in
this PR systemd/systemd#39071. In short,
`uaccess` doesn't work with `OPTIONS+="static_node=..."` udev rules,
and `/dev/snd/timer` is a static node. 258.1 needs to wait for the
next staging cycle, so for now let's just use a non-static node.
@bendlas
Copy link

bendlas commented Nov 24, 2025

I've recently gotten a regression on one of my machines, which I've bisected to c960ca2

  • Run startx on a tty
  • Switch to a different tty
  • Switch back
    • REGRESSION screen stays blank
  • When trying to to switch to another tty again, chvt blocks until the startx process is killed

This only happens on one of my machines (AMD EPYC 7642, Supermicro H12SSL-i, Radeon RX 6700XT), not on any of my other AMD machines; on various 6.17 kernels.

I'd be happy to help with tracing this, if somebody tells me what to look at. For now, I'll keep using v257

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

Development

Successfully merging this pull request may close these issues.

Keyboard not available immediately in X11 / display manager after the boot on some machine

7 participants