[pkg-apparmor] Bug#1144467: Resolving ldap users via nslcd fails due to disconnected path of its socket

karollupi6 at gmail.com karollupi6 at gmail.com
Mon Nov 16 14:18:50 GMT 2026


Control: tags -1 + patch

Hi,

I reproduced this bug in VMs and checked where the fix is in each suite.
A tested patch for trixie is attached.

Where the fix is
----------------

  trixie  4.1.0-1    affected, but only with a kernel >= 6.17 (for example
                     from trixie-backports). Not with the stock 6.12 kernel.
  forky   4.1.8-3    has both upstream commits (checked the shipped
                     profile only, not tested).
  sid     5.0.2-5.1  has the attach_disconnected.path flag (MR 2004), but
                     not the nslcd rule (MR 2170, commit 2df456d8). That
                     commit was merged to apparmor-5.0 (d1d120e7) a week
                     after 5.0.2 was tagged.

Reproduction on trixie
----------------------

Debian 13 genericcloud image, apparmor 4.1.0-1, libpam-modules-bin 1.7.0-5.
slapd, nslcd 0.9.13-1, libnss-ldapd, libpam-ldapd and nscd on the same
host, one LDAP user (posixAccount + shadowAccount), "passwd, group, shadow:
files ldap" in nsswitch.conf, PAM stack as written by pam-auth-update
(setup-ldap.sh; for the login test I also set "PerSourcePenalties no" in
sshd_config, otherwise sshd starts to refuse the source after a few
denied logins). The test is 100 ssh password logins of the LDAP user
(logins.sh) and 300 runs of "unix_chkpwd ldapuser chkexpiry" as root
(loop.sh).

  kernel 6.12.116+deb13 (stock), 1 CPU:   60 of 60 logins succeed,
                                          0 of 300 helper runs fail
  kernel 7.2.12-1~bpo13+1, 1 CPU:         29 to 53 of 100 logins denied
                                          (four runs), 23 to 110 of 300
                                          helper runs fail (five runs)
  kernel 7.2.12-1~bpo13+1, 2 CPUs:        2 to 6 of 300 helper runs fail
                                          (three runs)

The share varies a lot between runs, because it is a race (see below).

The denied logins show the messages from the original report:

  unix_chkpwd: could not obtain user info (ldapuser)
  sshd-session: fatal: Access denied for user ldapuser by PAM account
    configuration [preauth]
  audit: apparmor="ALLOWED" operation="file_perm" class="file"
    info="Failed name lookup - disconnected path" error=-13
    profile="unix-chkpwd" name="run/nslcd/socket" comm="unix_chkpwd"
    requested_mask="r" denied_mask="r"

Why it fails, and only sometimes
--------------------------------

- nslcd.service sets ProtectSystem=strict and PrivateTmp=yes, so nslcd runs
  in its own mount namespace and its socket is a disconnected path for
  unix_chkpwd.
- Since 6.17 the kernel checks the path of the peer socket on every read()
  and write() of a unix socket (aa_unix_file_perm -> unix_fs_perm ->
  aa_path_perm). path_name() returns the failed lookup as an error also
  for a profile in complain mode. That is why the log says "ALLOWED" and
  the read still fails.
- As far as I can tell from the code, the check is skipped once nslcd has
  closed its end of the connection (the peer's path.dentry is NULL then).
  So the result depends on whether unix_chkpwd reads before or after nslcd
  closes, which explains "the same operation succeeds later".
- nscd answers the passwd lookups, but shadow lookups always go to nslcd.
- pam_unix 1.7.0 runs the helper for every user whose passwd field is "x".

One thing that may be worth forwarding to the kernel side: trixie pins
the 4.0 ABI, and for such policy __aa_path_perm() skips the rule check for
PATH_SOCK_COND. But profile_path_perm() calls path_name() before that, so
the failed lookup of a disconnected socket path still denies the access.
On trixie with the flag set and no rule for the nslcd socket, nothing is
denied or logged, also in enforce mode. Current mainline has the same
order. I have not reported this anywhere else.

Patch for trixie
----------------

The attached diff adds two patches to debian/patches (cherry-picks of
upstream 353c5bd9 and 2df456d8, both part of 4.1.8). After
put-all-profiles-in-complain-mode.sh the profile line becomes

  profile unix-chkpwd /{,usr/}{,s}bin/unix_chkpwd flags=(complain,attach_disconnected.path=/att/unix-chkpwd/) {

With that profile:

  kernel 7.2.12-1~bpo13+1, 1 CPU:   100 of 100 logins succeed,
                                    0 of 300 helper runs fail
  kernel 6.12.116+deb13, 1 CPU:     profile loads, 60 of 60 logins succeed,
                                    0 of 300 helper runs fail

On trixie the flag alone is enough because of the ABI; the nslcd rule is
there to match 4.1.8. I assembled the source package with dpkg-source -b
and tested the resulting profile, but I did not build the binary packages.

Suggested changelog entry:

  * unix-chkpwd: attach disconnected paths and allow the nslcd socket.
    Fixes LDAP logins with nslcd on kernels >= 6.17, for example from
    trixie-backports (Closes: #1144467)

Would you consider this for a trixie point release? I can file the
trixie-pu bug or change the patch if you prefer it another way.

sid
---

On sid (kernel 7.3.4+deb14, apparmor 5.0.2-5.1) as shipped, logins work,
but every lookup logs

  apparmor="ALLOWED" operation="connect" class="file" profile="unix-chkpwd"
    name="/att/unix-chkpwd/run/nslcd/socket" requested_mask="wr"

With the profile in enforce mode 300 of 300 helper runs fail and the login
is denied with the same sshd message as above. Adding
"/att/unix-chkpwd/run/nslcd/socket rw," fixes it (0 of 300 fail, login
succeeds). Upstream commit 2df456d8 applies to the 5.0.2-5.1 profile
unchanged.

Seen in the same enforce test, and not part of this bug: the helper cannot
log to the journal. The profile allows
/att/unix-chkpwd/run/systemd/journal/dev-log, but on this image (dracut
initrd, systemd 262) the name has no /run:

  apparmor="DENIED" operation="sendmsg" class="file" profile="unix-chkpwd"
    name="/att/unix-chkpwd/systemd/journal/dev-log" requested_mask="w"

I can file that separately if it is useful.

Workaround for trixie with a backports kernel
---------------------------------------------

In /etc/apparmor.d/unix-chkpwd change "flags=(complain)" to
"flags=(complain,attach_disconnected.path=/att/unix-chkpwd/)", then run
"apparmor_parser -r /etc/apparmor.d/unix-chkpwd".

Disclosure: I did the reproduction and the analysis with an AI coding
assistant (Claude) on my own machines. The scripts are attached and I can
send full logs.

Regards,
Karchi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: apparmor_4.1.0-1+deb13u1_unix-chkpwd.diff
Type: text/x-diff
Size: 4339 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-apparmor-team/attachments/20261116/6592890f/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup-ldap.sh
Type: text/x-sh
Size: 1261 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-apparmor-team/attachments/20261116/6592890f/attachment.sh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loop.sh
Type: text/x-sh
Size: 432 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-apparmor-team/attachments/20261116/6592890f/attachment-0001.sh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logins.sh
Type: text/x-sh
Size: 782 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-apparmor-team/attachments/20261116/6592890f/attachment-0002.sh>


More information about the pkg-apparmor-team mailing list