libselinux: Do not fall back to /selinux on a sysfs mount failure
Stephen Smalley
maintainerPATCH 1/1 libselinux: Do not fall back to /selinux on a sysfs mount failure
Even if we cannot mount sysfs ourselves (e.g. in a user namespace), we can still try to mount on /sys/fs/selinux first prior to falling back to /selinux.
Signed-off-by Stephen Smalley <[email protected]>
--- libselinux/src/load_policy.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
libselinux/src/load_policy.c +5 -10
@@ -290,16 +290,11 @@ int selinux_init_load_policy(int *enforce)*/ const char *mntpoint =NULL ;/* First make sure /sys is mounted */ -if (mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,0 ) ==0 || errno ==EBUSY ) { -/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */ -if (mount (SELINUXFS ,SELINUXMNT ,SELINUXFS ,MS_NOEXEC |MS_NOSUID ,0 ) ==0 || errno ==EBUSY ) { - mntpoint =SELINUXMNT ; - }else { -/* check old mountpoint */ -if (mount (SELINUXFS ,OLDSELINUXMNT ,SELINUXFS ,0 ,0 ) ==0 || errno ==EBUSY ) { - mntpoint =OLDSELINUXMNT ; - } - } + (void )mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,0 ); + +/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */ +if (mount (SELINUXFS ,SELINUXMNT ,SELINUXFS ,MS_NOEXEC |MS_NOSUID ,0 ) ==0 || errno ==EBUSY ) { + mntpoint =SELINUXMNT ; }else {/* check old mountpoint */ if (mount (SELINUXFS ,OLDSELINUXMNT ,SELINUXFS ,0 ,0 ) ==0 || errno ==EBUSY ) {
Signature · 1 line
2.52.0
Quoted 5 lines · Stephen Smalley
Even if we cannot mount sysfs ourselves (e.g. in a user namespace), we can still try to mount on
/sys/fs/selinuxfirst prior to falling back to /selinux.Signed-off-by Stephen Smalley <[email protected]>
Acked-by Petr Lautrbach <[email protected]>
Quoted 32 lines
--- libselinux/src/load_policy.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)libselinux/src/load_policy.c +5
-10@@ -290,16 +290,11 @@ int selinux_init_load_policy(int *enforce)*/ const char *mntpoint =NULL ;/* First make sure /sys is mounted */ -if (mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,0 ) ==0 || errno ==EBUSY ) { -/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */ -if (mount (SELINUXFS ,SELINUXMNT ,SELINUXFS ,MS_NOEXEC |MS_NOSUID ,0 ) ==0 || errno ==EBUSY ) { - mntpoint =SELINUXMNT ; - }else { -/* check old mountpoint */ -if (mount (SELINUXFS ,OLDSELINUXMNT ,SELINUXFS ,0 ,0 ) ==0 || errno ==EBUSY ) { - mntpoint =OLDSELINUXMNT ; - } - } + (void )mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,0 ); + +/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */ +if (mount (SELINUXFS ,SELINUXMNT ,SELINUXFS ,MS_NOEXEC |MS_NOSUID ,0 ) ==0 || errno ==EBUSY ) { + mntpoint =SELINUXMNT ; }else {/* check old mountpoint */ if (mount (SELINUXFS ,OLDSELINUXMNT ,SELINUXFS ,0 ,0 ) ==0 || errno ==EBUSY ) {Signature · 1 line
2.52.0
Stephen Smalley
maintainerQuoted 10 lines · Petr Lautrbach
Quoted 5 lines · Stephen Smalley
Even if we cannot mount sysfs ourselves (e.g. in a user namespace), we can still try to mount on
/sys/fs/selinuxfirst prior to falling back to /selinux.Signed-off-by Stephen Smalley <[email protected]>Acked-by Petr Lautrbach <[email protected]>
I went ahead and merged this.