https://bugs.kde.org/show_bug.cgi?id=525805

            Bug ID: 525805
           Summary: pam_kwallet_init sends the environment with `env`,
                    which shell-quotes values since coreutils 9.12, so
                    ksecretd cannot reach the session bus and the wallet
                    is never unlocked
    Classification: Frameworks and Libraries
           Product: kwallet-pam
      Version First 6.7.5
       Reported In:
          Platform: Slackware
                OS: Linux
            Status: REPORTED
          Severity: major
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

KWallet is no longer unlocked at login. pam_kwallet_init hands the session
environment to the
PAM-launched ksecretd with `env`, and coreutils 9.12 changed `env` to
shell-quote the values it
prints. ksecretd therefore stores DBUS_SESSION_BUS_ADDRESS with the quotes
inside the value,
cannot connect to the session bus, and exits 1 before it ever opens the wallet.

STEPS TO REPRODUCE
1. A system with coreutils >= 9.12, SDDM, Plasma/X11, kwallet-pam and ksecretd.
2. Wallet password identical to the login password, so PAM unlocking applies.
3. Log in at SDDM by typing the password.

OBSERVED RESULT
The wallet stays locked and the first application that wants it shows a
password prompt.
Nothing is logged: pam_kwallet5 reports success, and pam_kwallet.c:393 closes
the daemon's
stderr before execve, so the daemon's own diagnosis is discarded. Pointing
pam_kwallet5's
kwalletd= at a wrapper that gives ksecretd a real stderr shows what it was
trying to say:

    kf.wallet.ksecretd: ksecretd5: client connected
    kf.wallet.ksecretd: ksecretd5: client disconnected
    kf.dbusaddons: DBus session bus not found. To circumvent this problem try
the following command (with bash):
        export $(dbus-launch)
    ksecretd exited status 1

EXPECTED RESULT
The wallet is unlocked at login, as it was with coreutils <= 9.11.

CAUSE
coreutils 9.12 NEWS, "Changes in behavior":

    'env' and 'printenv' now quote printed environment variables honoring the
QUOTING_STYLE
    environment variable, defaulting to shell-escape style.

/usr/libexec/pam_kwallet_init does:

    env | socat STDIN UNIX-CONNECT:$PAM_KWALLET5_LOGIN

ksecretd's waitForEnvironment() (kwallet 6.30.0,
src/runtime/ksecretd/main.cpp:64-95, unchanged
on master 4bc1cb00bb) reads that with fgets and putenv's each line verbatim, so
values needing
shell quoting arrive with the quotes as part of the value:

    DBUS_SESSION_BUS_ADDRESS='unix:path=/tmp/dbus-XXXXXXXXXX,guid=...'

KDBusService then finds no usable session bus and main.cpp exits 1 before
pamOpen() is reached.

EVIDENCE
- `env` prints MINICOM='-c on', while printenv, the shell and `env -0` all give
-c on.
- Capturing what pam_kwallet_init sent at a real login: 5 quoted values
including the bus
  address, while every running process's own /proc/<pid>/environ had none.
- Reproduced away from a real session: launching /usr/bin/ksecretd exactly as
PAM does
  (--pam-login <pipe-fd> <socket-fd>, key down the pipe, environment down the
socket) against a
  private dbus-run-session bus. With the address quoted it exits 1 with the
message above; with
  it unquoted, everything else equal, it stays up and registers
org.kde.ksecretd,
  org.kde.secretservicecompat and org.freedesktop.secrets.
- Timing: coreutils 9.12 was installed at 00:06; the first login after it, at
00:17, is the
  first failure, and every login before that unlocked the wallet.
- Fix confirmed at a real login: with QUOTING_STYLE=literal the daemon logs
  "Wallet opened by PAM" and no prompt appears.

SUGGESTED FIX (one line, in pam_kwallet_init)

    QUOTING_STYLE=literal env | socat STDIN UNIX-CONNECT:$PAM_KWALLET5_LOGIN

`env -0` is also unaffected by the coreutils change, but would need ksecretd to
read
NUL-delimited entries.

RELATED ROBUSTNESS ISSUES (independent of coreutils)
- pam_kwallet.c:393 closes fd 2 before execve, so the daemon's errors are
discarded at login and
  this failure leaves no trace anywhere on the system.
- waitForEnvironment() putenv's every line with no validation, and the handoff
protocol has no
  framing or escaping, so a corrupt value is accepted silently.
- A failed KDBusService registration exits 1 without telling PAM or the user,
so the wallet just
  stays locked.
- Minor, seen while reading that function: the accepted socket is never closed
(only a dup of it
  is fclosed), and the 1000-byte line buffer splits longer entries such as
LS_COLORS into bogus
  extra variables.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Slackware-current, kernel 6.18.52, X11 session via SDDM
0.21.0
KDE Plasma Version: 6.7.5
KDE Frameworks Version: 6.30.0 (kwallet 6.30.0, kdbusaddons 6.30.0)
Qt Version: 6.11.2
kwallet-pam: 6.7.5
coreutils: 9.12 (the trigger; 9.11 is unaffected)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to