pam_selinux patch
The attached patch against Dan's latest package will prevent any device name starting with "NODEV" from being relabeled (scp uses the device name of "NODEVssh"). It will also refrain from trying to relabel a /dev/pts node back to it's original context. We know that a /dev/pts node will be unlinked when both master and slave are closed so there is no need to relabel it at logout time. This means that we can prevent sshd from arbitary relabel operations without getting anything logged.
Signature · 4 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
Linux-PAM/modules/pam_selinux/pam_selinux.c +17 -4
@@ -191,18 +191,31 @@return NULL ; } -static void security_restorelabel_tty (char *tty,security_context_t context) { +static void security_restorelabel_tty (const char *tty,security_context_t context) {char ttybuf[PATH_MAX ]; +const char *ptr; +if (context==NULL )return ; -snprintf (ttybuf,sizeof (ttybuf),"/dev/%s" ,tty); -if (setfilecon (ttybuf,context)) +if (strncmp ("/dev/" , tty,5 )) + { +snprintf (ttybuf,sizeof (ttybuf),"/dev/%s" ,tty); + ptr = ttybuf; + } +else + ptr = tty; + +if (!strncmp (tty,"/dev/pts" ,8 )) +return ; + +if (setfilecon (ptr, context)) {syslog (LOG_NOTICE ,_ ("Warning! Could not relabel %s with %s, not relabeling.\n" ), ttybuf,context); }return ; } +static security_context_t security_label_tty (char *tty,security_context_t usercon) {char ttybuf[PATH_MAX ];int status=0 ;
@@ -348,7 +361,7 @@ } } } -if (ttys && tty) { +if (ttys && tty &&strncmp (tty,"NODEV" ,5 ) ) { ttyn=strdup (tty); ttyn_context=security_label_tty (ttyn,user_context); }