pam_namespace : allow use of X while polyinstantiating /tmp - v3
PATCH 1/1 pam_namespace : allow use of X while polyinstantiating /tmp - v3
This patch updates pam_namespace to allow the use of graphical display manager while polyinstantiating /tmp. It applies on top of the 06/18/06 version of pam_namespace (pam-0.99.4.0-5.src.rpm) in rawhide.
Changes since the last version posted on 6/18/06:
- Made the namespace.init script more robust as suggested by Klaus.
Other changes to the version in rawhide:
- Fixed Makefile.am to ensure that namespace.init gets installed as an executable
- Fixed typos, spelling errors and some white-space issues
- Execute instance initialization script at each instance setup
- Properly obtain exit status from a child process that executes the instance initialization script
- Example script for using X while polyinstantiating /tmp
- Update Makefile.am to make sure that the instance initalization script gets installed with execute permission
- Update man pages and README to reflect above changes
---
Makefile.am | 3 ++- README | 2 +- namespace.conf.5.xml | 2 +- namespace.init | 21 +++++++++++++++++++++ pam_namespace.8.xml | 40 ++++++++++++++++++++++++++-------------- pam_namespace.c | 32 ++++++++++++++++++++++++-------- 6 files changed, 75 insertions(+), 25 deletions(-)
modules/pam_namespace/Makefile.am +2 -1
@@ -33,5 +33,6 @@ if HAVE_UNSHARE securelib_LTLIBRARIES = pam_namespace.la pam_namespace_la_SOURCES = pam_namespace.c md5.c md5.h -secureconf_DATA = namespace.conf namespace.init +secureconf_DATA = namespace.conf +secureconf_SCRIPTS = namespace.init endif
modules/pam_namespace/README +1 -1
@@ -11,7 +11,7 @@ and users' home directory. If an executable script /etc/security/namespace.init exists, it is used to initialize the namespace every time a new instance directory -is created. The script receives the polyinstantiated directory path +is setup. The script receives the polyinstantiated directory path and the instance directory path as its arguments. Each line in namespace.conf describes a limit for a user in the form:
modules/pam_namespace/namespace.conf.5.xml +1 -1
@@ -25,7 +25,7 @@ or, in the case of SELinux, user name, security context or both. If an executable script <filename>/etc/security/namespace.init</filename> exists, it is used to initialize the namespace every time a new instance - directory is created. The script receives the polyinstantiated + directory is setup. The script receives the polyinstantiated directory path and the instance directory path as its arguments. </para>
modules/pam_namespace/namespace.init +21 -0
@@ -1,3 +1,24 @@ #!/bin/sh # This is only a boilerplate for the instance initialization script. # It receives polydir path as $1 and the instance path as $2. +# +# If you intend to polyinstantiate /tmp and you also want to use the X windows +# environment, you will have to use this script to bind mount the socket that +# is used by the X server to communicate with its clients. X server places +# this socket in /tmp/.X11-unix directory, which will get obscured by +# polyinstantiation. Uncommenting the following lines will bind mount +# the relevant directory at an alternative location (/.tmp/.X11-unix) such +# that the X server, window manager and X clients, can still find the +# socket X0 at the polyinstanted /tmp/.X11-unix. +# +#if [ $1 = /tmp ]; then +# if [ ! -f /.tmp/.X11-unix ]; then +# mkdir -p /.tmp/.X11-unix +# fi +# mount --bind /tmp/.X11-unix /.tmp/.X11-unix +# cp -fp -- /tmp/.X0-lock "$2/.X0-lock" +# mkdir -- "$2/.X11-unix" +# ln -fs -- /.tmp/.X11-unix/X0 "$2/.X11-unix/X0" +#fi + +exit 0
modules/pam_namespace/pam_namespace.8.xml +26 -14
@@ -56,7 +56,7 @@ using SELinux, user name, security context or both. If an executable script <filename>/etc/security/namespace.init</filename> exists, it is used to initialize the namespace every time a new instance - directory is created. The script receives the polyinstantiated + directory is setup. The script receives the polyinstantiated directory path and the instance directory path as its arguments. </para>
@@ -64,7 +64,7 @@ The pam_namespace module disassociates the session namespace from the parent namespace. Any mounts/unmounts performed in the parent namespace, such as mounting of devices, are not reflected in the - session namespace. To propogate selected mount/unmount events from + session namespace. To propagate selected mount/unmount events from the parent namespace into the disassociated session namespace, an administrator may use the special shared-subtree feature. For additional information on shared-subtree feature, please refer to
@@ -84,7 +84,7 @@ </term> <listitem> <para> - A lot of debug informations is logged using syslog + A lot of debug information is logged using syslog </para> </listitem> </varlistentry>
@@ -255,22 +255,34 @@ <para> This allows gdm to restart after each session and appropriately adjust - namesapces of display manager and the X server. If polyinstantiation of - /tmp is desired along with the graphical environment, then addtional + namespaces of display manager and the X server. If polyinstantiation + of /tmp is desired along with the graphical environment, then additional configuration changes are needed to address the interaction of X server - and font server namespaces with their use of /tmp to create communication - sockets. Perform the following changes to use graphical environment - with polyinstantiation of /tmp: + and font server namespaces with their use of /tmp to create + communication sockets. Please use the initialization script + <filename>/etc/security/namespace.init</filename> to ensure that + the X server and its clients can appropriately access the + communication socket X0. Please refer to the sample instructions + provided in the comment section of the instance initialization script + <filename>/etc/security/namespace.init</filename>. In addition, + perform the following changes to use graphical environment with + polyinstantiation of /tmp: </para> <para> <literallayout> - 1. Setup default init state to 3, by modifying /etc/inittab - 2. Disable the use of font server by commenting out "FontPath" - line in /etc/X11/xorg.conf. - 3. Ensure that the login service is setup to use pam_namespace, - as described above, by modifying /etc/pam.d/login. - 4. Use the "startx" command after a successful terminal login. + 1. Disable the use of font server by commenting out "FontPath" + line in /etc/X11/xorg.conf. If you do want to use the font server + then you will have to augment the instance initialization + script to appropriately provide /tmp/.font-unix from the + polyinstantiated /tmp. + 2. Ensure that the gdm service is setup to use pam_namespace, + as described above, by modifying /etc/pam.d/gdm. + 3. Ensure that the display manager is configured to restart X server + with each new session. This default setup can be verified by + making sure that /usr/share/gdm/defaults.conf contains + "AlwaysRestartServer=true", and it is not overridden by + /etc/gdm/custom.conf. </literallayout> </para>
modules/pam_namespace/pam_namespace.c +24 -8
@@ -632,8 +632,10 @@ static int create_dirs(const struct poly#endif {struct stat statbuf, newstatbuf, instpbuf; -int fd, pid, status; +int fd, status;char *inst_parent, *trailing_slash; +pid_t rc, pid; +sighandler_t osighand =NULL ;/* * stat the directory to polyinstantiate, so its owner-group-mode
@@ -705,7 +707,7 @@ static int create_dirs(const struct poly*/ if (mkdir (ipath,S_IRUSR ) <0 ) {if (errno ==EEXIST ) -return PAM_SUCCESS ; + goto inst_init;else {pam_syslog (idata->pamh,LOG_ERR ,"Error creating %s, %m" , ipath);
@@ -776,12 +778,19 @@ static int create_dirs(const struct poly* directory as arguments. */ +inst_init: + osighand =signal (SIGCHLD ,SIG_DFL ); +if (osighand ==NULL ) { +pam_syslog (idata->pamh,LOG_ERR ,"Cannot set signal value" ); +return PAM_SESSION_ERR ; + } +if (access (NAMESPACE_INIT_SCRIPT ,F_OK ) ==0 ) {if (access (NAMESPACE_INIT_SCRIPT ,X_OK ) <0 ) {if (idata->flags &PAMNS_DEBUG )pam_syslog (idata->pamh,LOG_ERR ,"Namespace init script not executable" ); -rmdir (ipath); + (void )signal (SIGCHLD , osighand);return PAM_SESSION_ERR ; }else { pid =fork ();
@@ -796,22 +805,29 @@ static int create_dirs(const struct poly polyptr->dir, ipath, (char *)NULL) < 0)exit (1 ); }else if (pid >0 ) { -while (waitpid (pid, &status,0 ) != pid); -if (!WIFEXITED (status) ||WEXITSTATUS (status) >0 ) { +while (((rc =waitpid (pid, &status,0 )) == (pid_t)-1 ) && + (errno ==EINTR )); +if (rc == (pid_t)-1 ) { +pam_syslog (idata->pamh,LOG_ERR ,"waitpid failed- %m" ); + (void )signal (SIGCHLD , osighand); +return PAM_SESSION_ERR ; + } +if (!WIFEXITED (status) ||WIFSIGNALED (status) >0 ) {pam_syslog (idata->pamh,LOG_ERR ,"Error initializing instance" ); -rmdir (ipath); + (void )signal (SIGCHLD , osighand);return PAM_SESSION_ERR ; } }else if (pid <0 ) {pam_syslog (idata->pamh,LOG_ERR ,"Cannot fork to run namespace init script, %m" ); -rmdir (ipath); + (void )signal (SIGCHLD , osighand);return PAM_SESSION_ERR ; } } } + (void )signal (SIGCHLD , osighand);return PAM_SUCCESS ; }
@@ -894,7 +910,7 @@ static int ns_setup(const struct polydir#ifdef WITH_SELINUX if ((idata->flags &PAMNS_DEBUG ) && (idata->flags &PAMNS_SELINUX_ENABLED )) -pam_syslog (idata->pamh,LOG_DEBUG ,"Inst context %s Orig context %s" , +pam_syslog (idata->pamh,LOG_DEBUG ,"Inst ctxt %s Orig ctxt %s" , instcontext, origcontext);#endif }
--
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 3 lines · Janak Desai
This patch updates
pam_namespaceto allow the use of graphical display manager while polyinstantiating /tmp. It applies on top of the 06/18/06 version ofpam_namespace(pam-0.99.4.0-5.src.rpm) in rawhide.
I hit another bug...
Quoted 3 lines
diff -Naurp
pam_namespace0620/modules/pam_namespace/pam_namespace.cpam_namespace0620+patch/modules/pam_namespace/pam_namespace.cmodules/pam_namespace/pam_namespace.c +0
-0
....
modules/pam_namespace/pam_namespace.c static int create_dirs(const struct poly · line 787
Quoted 11 lines
modules/pam_namespace/pam_namespace.c +7
-0@@ -776,12 +778,19 @@ static int create_dirs(const struct poly* directory as arguments. */ +inst_init: + osighand =signal (SIGCHLD ,SIG_DFL ); +if (osighand ==NULL ) { +pam_syslog (idata->pamh,LOG_ERR ,"Cannot set signal value" ); +return PAM_SESSION_ERR ; + } +
Of course, SIG_DFL and NULL are both zero - which means this throws an error if we try to set it to SIG_DFL and it already *was*. I suspect the 'if' condition should be:
if (osighand == SIG_ERR) {instead. (Unless somebody can point me at code that guarantees that the signal handler *will* be set to a non-SIG_DFL value when we get here? I don't see anyplace in pam_namespace.c where we would have set it before...)
Quoted 28 lines · On Thu, 2006-06-22 at 03:35 -0400, [email protected] wrote:
Quoted 3 lines · Janak Desai
This patch updates
pam_namespaceto allow the use of graphical display manager while polyinstantiating /tmp. It applies on top of the 06/18/06 version ofpam_namespace(pam-0.99.4.0-5.src.rpm) in rawhide.I hit another bug...
Quoted 3 lines
diff -Naurp
pam_namespace0620/modules/pam_namespace/pam_namespace.cpam_namespace0620+patch/modules/pam_namespace/pam_namespace.cmodules/pam_namespace/pam_namespace.c +0
-0....
modules/pam_namespace/pam_namespace.c static int create_dirs(const struct poly · line 787
Quoted 11 lines
modules/pam_namespace/pam_namespace.c +7
-0@@ -776,12 +778,19 @@ static int create_dirs(const struct poly* directory as arguments. */ +inst_init: + osighand =signal (SIGCHLD ,SIG_DFL ); +if (osighand ==NULL ) { +pam_syslog (idata->pamh,LOG_ERR ,"Cannot set signal value" ); +return PAM_SESSION_ERR ; + } +Of course,
SIG_DFLand NULL are both zero - which means this throws an error if we try to set it toSIG_DFLand it already *was*. I suspect the 'if' condition should be:
Quoted 1 line
if (osighand == SIG_ERR) {Of course it should be compared to SIG_ERR and not NULL. Thanks for finding this.
Signature · 6 lines
Tomas Mraz <[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 3 lines · Tomas Mraz
Quoted 1 line
if (osighand == SIG_ERR) {Of course it should be compared to
SIG_ERRand not NULL. Thanks for finding this.
OK, getting farther now. GDM comes up and I can login with a polyinstantiated copy of /tmp. :)
A few issues I ran into after I fixed that one:
1) The current namespace.init:
if [ $1 = /tmp ]; then
if [ ! -f /.tmp/.X11-unix ]; then
Probably needs to be 'if [ ! -d /.tmp/.X11-unix'?
2) After a few login/logouts, I have in /etc/mtab:
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0/tmp/.X11-unix /.tmp/.X11-unix none rw,bind 0 0/tmp/.X11-unix /.tmp/.X11-unix none rw,bind 0 0/tmp/.X11-unix /.tmp/.X11-unix none rw,bind 0 0
/proc/mounts looks sane. Probaby we need 'mount -n --bind' for this one. Otherwise, the "unmount everything at shutdown" spews messages for each attempted unmount.
3) I'm running in strict/permissive policy, and that whole script tosses zillions of AVC's because we're running in local_login_t which isn't allowed to play with xdm_tmp_t files and similar. Not sure what's supposed to happen here.
Quoted 9 lines · On Thu, 2006-06-22 at 11:39 -0400, [email protected] wrote:
Quoted 3 lines · Tomas Mraz
Quoted 1 line
if (osighand == SIG_ERR) {Of course it should be compared to
SIG_ERRand not NULL. Thanks for finding this.OK, getting farther now. GDM comes up and I can login with a polyinstantiated copy of /tmp. :)
Quoted 9 lines
A few issues I ran into after I fixed that one:
1) The current namespace.init:
if [ $1 = /tmp ]; then
if [ ! -f /.tmp/.X11-unix ]; thenProbably needs to be 'if [ ! -d /.tmp/.X11-unix'?
ok. Will fix it in the next incarnation.
Quoted 11 lines
2) After a few login/logouts, I have in
/etc/mtab:none
/proc/sys/fs/binfmt_miscbinfmt_miscrw 0 0/tmp/.X11-unix/.tmp/.X11-unix none rw,bind 0 0/tmp/.X11-unix/.tmp/.X11-unix none rw,bind 0 0/tmp/.X11-unix/.tmp/.X11-unix none rw,bind 0 0
/proc/mountslooks sane. Probaby we need 'mount -n --bind' for this one. Otherwise, the "unmount everything at shutdown" spews messages for each attempted unmount.
ok. Will fix it in the next incarnation.
Quoted 4 lines
3) I'm running in strict/permissive policy, and that whole script tosses zillions of AVC's because we're running in
local_login_twhich isn't allowed to play withxdm_tmp_tfiles and similar. Not sure what's supposed to happen here.
I have been testing using targeted policy in enforcing mode. I am not sure about what needs to be done with strict policy as well.
-Janak
--
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 29 lines · Tomas Mraz
Quoted 28 lines · On Thu, 2006-06-22 at 03:35 -0400, [email protected] wrote:
Quoted 3 lines · Janak Desai
This patch updates
pam_namespaceto allow the use of graphical display manager while polyinstantiating /tmp. It applies on top of the 06/18/06 version ofpam_namespace(pam-0.99.4.0-5.src.rpm) in rawhide.I hit another bug...
Quoted 3 lines
diff -Naurp
pam_namespace0620/modules/pam_namespace/pam_namespace.cpam_namespace0620+patch/modules/pam_namespace/pam_namespace.cmodules/pam_namespace/pam_namespace.c +0
-0....
modules/pam_namespace/pam_namespace.c static int create_dirs(const struct poly · line 787
Quoted 11 lines
modules/pam_namespace/pam_namespace.c +7
-0@@ -776,12 +778,19 @@ static int create_dirs(const struct poly* directory as arguments. */ +inst_init: + osighand =signal (SIGCHLD ,SIG_DFL ); +if (osighand ==NULL ) { +pam_syslog (idata->pamh,LOG_ERR ,"Cannot set signal value" ); +return PAM_SESSION_ERR ; + } +Of course,
SIG_DFLand NULL are both zero - which means this throws an error if we try to set it toSIG_DFLand it already *was*. I suspect the 'if' condition should be:
Quoted 3 lines
Quoted 1 line
if (osighand == SIG_ERR) {Of course it should be compared to
SIG_ERRand not NULL. Thanks for finding this.
Yes, thanks for find this and other problems. I was using pam_unix sources to see how signal handlers are managed by pam modules. It too takes non-NULL return values as good previous signal handler value. I should have looked at the man page as well.
Tomas, should I send a patch with just this change or the create a v4 version of the patch? I am going to be unavailable in about an hour so I can do this on Monday.
-Janak
--
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 10 lines · Janak Desai
On Thu, 2006-06-22 at 10:37 +0200, Tomas Mraz wrote:
Yes, thanks for find this and other problems. I was using
pam_unixsources to see how signal handlers are managed by pam modules. It too takes non-NULL return values as good previous signal handler value. I should have looked at the man page as well.Tomas, should I send a patch with just this change or the create a v4 version of the patch? I am going to be unavailable in about an hour so I can do this on Monday.
You don't have to send the patch. I've already submitted pam_namespace patch with the above fixed for upstream review to pam-patches mailing list.
Signature · 7 lines
Tomas Mraz <[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.