Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 672776 - sys-libs/pam-1.3.1-r1 with USE=-filecaps: unix_chkpwd fails with "check pass; user unknown"
Summary: sys-libs/pam-1.3.1-r1 with USE=-filecaps: unix_chkpwd fails with "check pass;...
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Mikle Kolyada (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-08 22:21 UTC by Louis Sautier (sbraz)
Modified: 2018-12-09 15:51 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Louis Sautier (sbraz) gentoo-dev 2018-12-08 22:21:53 UTC
Hi,
I noticed that nginx's PAM auth module wasn't working so I straced it and noticed that it could not access shadow:
[pid  2677] openat(AT_FDCWD, "/etc/shadow", O_RDONLY|O_CLOEXEC) = -1 EACCES (Permission denied)
Logs contain the following entry:
unix_chkpwd[2677]: check pass; user unknown

This is easy to reproduce with
echo -e "<pwd>\0" | /sbin/unix_chkpwd <username> nonull

The unix_chkpwd binary has the right permissions:
# ls -l /sbin/unix_chkpwd
-rws--x--x 1 root root 35216 Dec  8 22:15 /sbin/unix_chkpwd

The following code is the cause of the problem, it forces unix_chkpwd to setuid to the calling user (nginx in my case):
https://github.com/linux-pam/linux-pam/blob/3b77a78d575b8ab56bb0e828499df328d55c925f/modules/pam_unix/unix_chkpwd.c#L139
https://github.com/linux-pam/linux-pam/commit/6ccbba1cf178e9de46347e2f9df76f69aebcec20

Debian worked around it at the time:
https://gitlab.gnugen.ch/fvessaz/pkg-pam/commit/9c123bbb6b25524e768b54506117a9acfe82409e

Nowadays, it looks like Debian has setgid set for the binary but not setuid. Archlinux has both. Wth setgid, the additional problematic setuid call doesn't prevent unix_chkpwd from working any more so perhaps we could simply change the perms from 4711 to 2711?
Comment 1 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2018-12-09 15:28:53 UTC
Yes, we are using filecaps, so if you disable this ist is your responsibility
Comment 2 Louis Sautier (sbraz) gentoo-dev 2018-12-09 15:45:46 UTC
(In reply to Mikle Kolyada from comment #1)
> Yes, we are using filecaps, so if you disable this ist is your responsibility

I didn't disable it myself, the systemd stage3 has it disabled:
https://gitweb.gentoo.org/proj/releng.git/commit/?id=6ca51d9ebebcf52984a80a6db95ab8623d95d1f3
Comment 3 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2018-12-09 15:51:21 UTC
(In reply to Louis Sautier (sbraz) from comment #2)
> (In reply to Mikle Kolyada from comment #1)
> > Yes, we are using filecaps, so if you disable this ist is your responsibility
> 
> I didn't disable it myself, the systemd stage3 has it disabled:
> https://gitweb.gentoo.org/proj/releng.git/commit/
> ?id=6ca51d9ebebcf52984a80a6db95ab8623d95d1f3

then blame them