Thanks for the detailed report with suggested fix -- I've uploaded
1.4.0-4 with your suggested fix, please test it if you are able to as
I've no easy way to test this in a live forky desktop environment.

/Simon

Heinz Pechtl <[email protected]> writes:

> Package: libpam-u2f
> Version: 1.4.0-3+b2
> Severity: important
>
> Subject: pam_u2f second factor broken in polkit dialogs: sandboxed 
> [email protected] blocks /dev/hidraw* and u2f_keys
>
> Description:
>   Since polkit 127, polkit-agent-helper-1 is socket-activated and
>   runs in a strict systemd sandbox (unit
>   [email protected], shipped by polkitd 127+). The PAM
>   stack of the polkit authentication dialog (e.g. /etc/pam.d/polkit-1,
>   which includes common-auth) is executed inside this helper process.
>
>   With pam_u2f enabled (pam-auth-update;
>   'auth [success=1 default=ignore] pam_u2f.so' in
>   /etc/pam.d/common-auth), U2F/YubiKey second-factor authentication
>   fails in all polkit dialogs (pkexec, KDE System Settings, ...),
>   while the exact same authentication works in sudo, getty/login and
>   GDM, which do not run in this sandbox.
>
>   Root cause: the shipped unit enables
>       PrivateDevices=yes
>       DevicePolicy=closed
>       ProtectHome=yes
>   which prevents pam_u2f from
>       1) opening the YubiKey (a USB HID device, /dev/hidraw*), and
>       2) reading the key mapping file ~/.config/Yubico/u2f_keys.
>
>   The polkit-agent-helper(8) man page (SANDBOXING section) states
>   that PAM module vendors should ship a systemd drop-in that relaxes
>   only the specific directives their module requires. Arch and NixOS
>   ship exactly such a drop-in for pam_u2f (see References); the
>   Debian package libpam-u2f does not, so U2F authentication is
>   broken out of the box with polkit >= 127.
>
> Steps to reproduce:
>   1. Install libpam-u2f and enroll a key:
>        pam-auth-update  (enable libpam-u2f)
>        u2f-prepare      (creates ~/.config/Yubico/u2f_keys)
>      A YubiKey 4/5 (U2F) must be plugged in (/dev/hidraw*).
>   2. Log into a graphical session that uses a polkit agent
>      (Polkit-KDE agent / Plasma on this system).
>   3. Trigger a polkit authorization, e.g.:
>        run0
>   4. When the authentication dialog appears, touch the YubiKey.
>
> Expected result:
>   The dialog authenticates via the U2F touch (as it does with sudo).
>
> Actual result:
>   The U2F touch is not accepted; authentication fails or silently
>   falls back to the password module.
>
> Workaround (confirmed in the upstream threads, referenced below):
>   sudo systemctl edit [email protected]  and add:
>
>     [Service]
>     ProtectHome=read-only
>     PrivateDevices=no
>     DeviceAllow=/dev/urandom r
>     DeviceAllow=char-hidraw rw
>
>   then: sudo systemctl daemon-reload
>   (Trade-off: the root-running helper gets full /dev and read-only
>   access to /home again; polkit maintainers call this the correct
>   way to solve the issue.)
>
> Suggested fix:
>   Ship a vendor drop-in with the libpam-u2f package, e.g.
>   /usr/lib/systemd/system/[email protected]/pam-u2f.conf:
>
>     [Service]
>     ProtectHome=read-only
>     PrivateDevices=no
>     DeviceAllow=/dev/urandom r
>     DeviceAllow=char-hidraw rw
>
>   (This is what Arch ships for pam_u2f; see References. If pam_u2f
>   can be made to work with the device sandbox kept active, a
>   narrower override with only
>   'DeviceAllow=char-hidraw rw', 'DeviceAllow=/dev/urandom r' and
>   'ProtectHome=read-only' would be preferable.)
>
> Journal excerpt (reproduced before applying the workaround):
> Nov 29 10:05:17 earth systemd[1]: Starting 
> polkit-agent-helper@0-4122-1601_41079-1000.service - Authorization Manager 
> Agent Helper (PID 1601/UID 1000)...
> Nov 29 10:05:17 earth polkit-agent-helper-1[8247]: PAM (polkit-1) 
> /usr/lib/pam.d is not supported on this system; see 
> /usr/share/doc/libpam0g/Debian-PAM-MiniPolicy.gz
> Nov 29 10:05:17 earth polkit-agent-helper-1[8247]: polkit-agent-helper-1: 
> pam_authenticate failed: Authentication failure
> Nov 29 10:05:17 earth systemd[1]: Starting 
> polkit-agent-helper@1-36881-1601_41079-1000.service - Authorization Manager 
> Agent Helper (PID 1601/UID 1000)...
> Nov 29 10:05:17 earth systemd[1]: 
> polkit-agent-helper@0-4122-1601_41079-1000.service: Deactivated successfully.
> Nov 29 10:05:17 earth systemd[1]: Finished 
> polkit-agent-helper@0-4122-1601_41079-1000.service - Authorization Manager 
> Agent Helper (PID 1601/UID 1000).
> Nov 29 10:05:17 earth polkit-agent-helper-1[8268]: PAM (polkit-1) 
> /usr/lib/pam.d is not supported on this system; see 
> /usr/share/doc/libpam0g/Debian-PAM-MiniPolicy.gz
> Nov 29 10:05:17 earth polkit-agent-helper-1[8268]: polkit-agent-helper-1: 
> pam_authenticate failed: Authentication failure
> Nov 29 10:05:17 earth systemd[1]: Starting 
> polkit-agent-helper@2-24609-1601_41079-1000.service - Authorization Manager 
> Agent Helper (PID 1601/UID 1000)...
> Nov 29 10:05:18 earth polkit-agent-helper-1[8273]: PAM (polkit-1) 
> /usr/lib/pam.d is not supported on this system; see 
> /usr/share/doc/libpam0g/Debian-PAM-MiniPolicy.gz
> Nov 29 10:05:18 earth polkit-agent-helper-1[8273]: polkit-agent-helper-1: 
> pam_authenticate failed: Authentication failure
> Nov 29 10:05:18 earth systemd[1]: 
> polkit-agent-helper@1-36881-1601_41079-1000.service: Deactivated successfully.
> Nov 29 10:05:18 earth systemd[1]: Finished 
> polkit-agent-helper@1-36881-1601_41079-1000.service - Authorization Manager 
> Agent Helper (PID 1601/UID 1000).
> Nov 29 10:05:18 earth systemd[1]: 
> polkit-agent-helper@2-24609-1601_41079-1000.service: Deactivated successfully.
> Nov 29 10:05:18 earth systemd[1]: Finished 
> polkit-agent-helper@2-24609-1601_41079-1000.service - Authorization Manager 
> Agent Helper (PID 1601/UID 1000).
>
> System information:
>   Kernel:          7.3.6+deb14-amd64 (Debian 7.3.6-1, 2026-11-24), x86_64
>   Distribution:    Debian GNU/Linux forky/sid (Debian 14)
>   systemd:         262.2-1
>   glibc:           2.43 (2.43-7)
>   polkitd:         128-1
>   libpam-u2f:      1.4.0-3+b2
>   polkit-kde-agent-1: 4:6.7.4-1
>   libpam-runtime:  1.7.0-8
>   YubiKey:         Bus 001 Device 005: ID 1050:0407
>                    Yubico.com Yubikey 4/5 OTP+U2F+CCID
>                    (present as /dev/hidraw0..6)
>   PAM config:      /etc/pam.d/common-auth, Primary block:
>                    auth [success=1 default=ignore] pam_u2f.so
>   No local drop-in for [email protected] is present;
>   the as-shipped unit contains (among others):
>     PrivateDevices=yes, DevicePolicy=closed, ProtectHome=yes,
>     ProtectSystem=strict, PrivateNetwork=yes, NoNewPrivileges=yes
>
> References:
>   - https://github.com/polkit-org/polkit/issues/622
>     (polkit 127 sandbox breaks pam_u2f; polkit maintainer: the
>     drop-in above is "the correct way to solve these issues")
>   - https://github.com/Yubico/pam-u2f/issues/389
>     (same breakage reported; Arch's shipped fix discussed)
>   - Arch fix commit:
>     
> https://gitlab.archlinux.org/archlinux/packaging/packages/pam-u2f/-/commit/888507cc6e4307e8acdfccec8718b7be559b08e9
>   - man 8 polkit-agent-helper, section "SANDBOXING"
>

Attachment: signature.asc
Description: PGP signature

Reply via email to