unix_chkpwd
When sshd is launched from inetd it inherits the open file handle for the TCP socket. It does not use fcntl(fd, F_SETFD..) to make it close on exec for child processes, so when pam_unix.so runs unix_chkpwd (*) the file handle is inherited.
We can do one of three things:
1) dontaudit system_chkpwd_t inetd_t:fd use; 2) Change sshd to use fcntl() before doing any PAM stuff. 3) Put code in pam_unix.so to close all file handles after the fork().
Which do you think is best? 2 seems most correct to me, but may be most difficult to get accepted upstream. 3 means ~1000 close() calls, which doesn't take too long on modern machines. 1 is a hack.
(*) This only happens with my modified PAM and SE Linux policy to prevent all login processes from being able to read /etc/shadow directly.
Signature · 10 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Hi,
Quoted 6 lines · Russell Coker
We can do one of three things:
1) dontaudit system_chkpwd_t inetd_t:fd use; 2) Change sshd to use fcntl() before doing any PAM stuff. 3) Put code in pam_unix.so to close all file handles after the fork().Which do you think is best? 2 seems most correct to me
2 would require fcntl()ing it back again afterwards, of course. Having your shell inherit FD_CLOEXEC on stdin could be confusing, at best. :-)
2 seems clearly the cleanest solution, but is also a rather PAM+SELinux-specific hack. I guess that we're going to be maintaining SELinux-specific patches against a lot of core utils for some time, until it becomes so widespread that all maintainers are desperate to merge full SELinux support :-), and this specific change seems a relatively minimal and painless one to maintain in that manner.
--Stephen
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 7 lines · Russell Coker
We can do one of three things:
1) dontaudit system_chkpwd_t inetd_t:fd use; 2) Change sshd to use fcntl() before doing any PAM stuff. 3) Put code in pam_unix.so to close all file handles after the fork().Which do you think is best? 2 seems most correct to me, but may be most difficult to get accepted upstream.
Yes, 2 seems correct to me as well, what objections would they have upstream?
- James
Signature · 9 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines · James Morris
Quoted 5 lines · Russell Coker
We can do one of three things:
1) dontaudit system_chkpwd_t inetd_t:fd use; 2) Change sshd to use fcntl() before doing any PAM stuff. 3) Put code in pam_unix.so to close all file handles after the fork().
Quoted 10 lines
Quoted 3 lines
Which do you think is best? 2 seems most correct to me, but may be most difficult to get accepted upstream.
Yes, 2 seems correct to me as well, what objections would they have upstream?
- James
I still think the safest thing is to manual close all sockets, since this prevents the case where someone has opened a socket accidently since you don't know where pam is going to be used. The time it takes to run 0-max open file descriptors is tiny.
Dan
Quoted 9 lines · Stephen C. Tweedie
Quoted 6 lines
We can do one of three things:
1) dontaudit system_chkpwd_t inetd_t:fd use; 2) Change sshd to use fcntl() before doing any PAM stuff. 3) Put code in pam_unix.so to close all file handles after the fork().Which do you think is best? 2 seems most correct to me
2 would require fcntl()ing it back again afterwards, of course. Having your shell inherit
FD_CLOEXECon stdin could be confusing, at best. :-)
That handle isn't used by the application and I need to have the policy deal with unix_chkpwd inheriting file handles for the pty/tty device anyway for the case of screen blankers etc. So setting it back shouldn't be necessary.
Quoted 2 lines
2 seems clearly the cleanest solution, but is also a rather PAM+SELinux-specific hack.
It's not really SE Linux specific. There is no need for a program that sshd executes to receive a copy of that file handle. So the best practise (IMHO) is to ensure that such programs don't get it.
Quoted 2 lines
I guess that we're going to be maintaining SELinux-specific patches against a lot of core utils for some time,
I certainly hope not. Maintaining such patches is extremely painful and time consuming. We want to get upstream support for SE Linux things as soon as possible.
Quoted 3 lines
until it becomes so widespread that all maintainers are desperate to merge full SELinux support :-), and this specific change seems a relatively minimal and painless one to maintain in that manner.
I don't think that maintainers will be desperate for SE Linux support for a while. However during our SE Linux work we often find and fix other bugs that may have security implications. It would be rather embarassing for an upstream maintainer if the SE Linux version of a program was the only version that did not have a security hole and people who don't use SE Linux were forced to use the SE Linux version to close the hole!
Signature · 10 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Hi,
Quoted 6 lines · Russell Coker
Quoted 2 lines
2 would require fcntl()ing it back again afterwards, of course. Having your shell inherit
FD_CLOEXECon stdin could be confusing, at best. :-)That handle isn't used by the application and I need to have the policy deal with
unix_chkpwdinheriting file handles for the pty/tty device anyway for the case of screen blankers etc. So setting it back shouldn't be necessary.
Hmm, I think I just forgot that we were dealing with privilege separation here. Do we have a guarantee that the pam call is only done by the unprivileged temporary fork? If so, we needn't worry about the final shell inheriting the CLOEXEC flag.
Quoted 4 lines
It would be rather embarassing for an
upstream maintainer if the SE Linux version of a program was the only version that did not have a security hole and people who don't use SE Linux were forced to use the SE Linux version to close the hole!
Quite!
--Stephen
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.