Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 636862 - Selinux prevents normal system boot if initrams used
Summary: Selinux prevents normal system boot if initrams used
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: SE Linux Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-08 11:54 UTC by Alexander Miroshnichenko
Modified: 2018-03-03 10:03 UTC (History)
1 user (show)

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


Attachments
Screenshot (Screenshot_20171108_143823.png,32.54 KB, image/png)
2017-11-08 11:54 UTC, Alexander Miroshnichenko
Details
Genkernel-next unmount /run if selinux enabled patch (selinux_run_fs.patch,696 bytes, patch)
2017-11-17 16:36 UTC, Alexander Miroshnichenko
Details | Diff
Boot process with /dev/console wrong permissions (selinux-console-wrong-perms.png,39.73 KB, image/png)
2018-01-20 08:53 UTC, Alexander Miroshnichenko
Details
Boot process with /dev/console correct permissions (context) (selinux-console-right-perms.png,30.31 KB, image/png)
2018-01-20 08:54 UTC, Alexander Miroshnichenko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Miroshnichenko 2017-11-08 11:54:24 UTC
Created attachment 503096 [details]
Screenshot

I have installed and configured Gentoo Linux with Selinux enforcing mode.

All the context correctly relabled.
But it is impossible to boot with enforcing mode because initramfs selinux not aware. It creates /dev , /run. When new root mounted and run "switch_root" selinux policy loaded and prevents openrc/init to work with /run and /dev, because the fyleystems have wrong contexts.

From screeshot you can see denials for files /dev/console, /dev/ptmx, /run/utmp
After that system impossible to boot.
Comment 1 Jason Zaman gentoo-dev 2017-11-11 06:04:22 UTC
which initramfs do you use?
genkernel works fine for me.
it looks like you have a wrong label on /run or /dev. does your initramfs mount /run for you? do you have /run in your fstab with the rootcontext= option?
Comment 2 Alexander Miroshnichenko 2017-11-11 13:43:19 UTC
>which initramfs do you use?
genkernel-next

>does your initramfs mount /run for you? 
YES. I tried to run OS with "debug" kernel parameter which right before switch_root give me shell. I can see mounted /newroot/dev and /newroot/run.

>do you have /run in your fstab with the rootcontext= option?
No, because I get error if such mountpoint exists in fstab: remount /run or /dev   with change security context is not allowed on mounted FS.
Comment 3 Jason Zaman gentoo-dev 2017-11-13 10:21:44 UTC
(In reply to Alexander Miroshnichenko from comment #2)
> >which initramfs do you use?
> genkernel-next

ah right, yeah genkernel-next doesnt work right with selinux. can you switch to regular genkernel? iirc genkernel-next is aiming to go away eventually so should be no harm in switching anyway.
Comment 4 Alexander Miroshnichenko 2017-11-17 16:35:41 UTC
Hi,

I can not migrate to genkernel, because it does not support LVM THIN and uses old LVM version source package.

I have wrote the patch which unmount /run before switch_root if SELinux enabled.
Put the patch to /etc/portage/patches/sys-kernel/genkernel-next/ and re-emerge the genkernel-next. It works for me.
Comment 5 Alexander Miroshnichenko 2017-11-17 16:36:21 UTC
Created attachment 504570 [details, diff]
Genkernel-next unmount /run if selinux enabled patch
Comment 6 Jason Zaman gentoo-dev 2018-01-17 03:30:00 UTC
I just tried out dracut again and added a fix to openrc itself, can  you try this instead:
in /lib/rc/sh/init.sh around line 86, the checkpath's already exist, add the restorecon line:

[ -x /sbin/restorecon ] && /sbin/restorecon -rFv /run
checkpath -d $RC_SVCDIR
checkpath -d -m 0775 -o root:uucp /run/lock

If it works for you i'll add it to openrc for the next version
Comment 7 Alexander Miroshnichenko 2018-01-18 16:42:08 UTC
>If it works for you i'll add it to openrc for the next version

It helps me with genkernel-next and dracut. But I add /dev/console too for restorecon target to see boot process.

So, resulted string is:
[ -x /sbin/restorecon ] && /sbin/restorecon -rFv /dev/console /run

Thak you!
Comment 8 Jason Zaman gentoo-dev 2018-01-19 05:16:46 UTC
(In reply to Alexander Miroshnichenko from comment #7)
> >If it works for you i'll add it to openrc for the next version
> 
> It helps me with genkernel-next and dracut. But I add /dev/console too for
> restorecon target to see boot process.

huh. dracut appears to work for me without restorecon'ing /dev/console. any chance you can post the avcs? what exactly happens without it?
init_t and initrc_t both have rw perms on the plain device_t, so should work even if its not restorecon'd that early.

and the later devfs openrc init script does relabel all of /dev. it happens pretty early (obviously not as early as init.sh tho).
Comment 9 Alexander Miroshnichenko 2018-01-20 08:53:56 UTC
Created attachment 515342 [details]
Boot process with /dev/console wrong permissions
Comment 10 Alexander Miroshnichenko 2018-01-20 08:54:34 UTC
Created attachment 515344 [details]
Boot process with /dev/console correct permissions (context)
Comment 11 Alexander Miroshnichenko 2018-01-20 08:55:29 UTC
I have added two screenshots:
1. [ -x /sbin/restorecon ] && /sbin/restorecon -rFv /run
2. [ -x /sbin/restorecon ] && /sbin/restorecon -rFv /dev/console /run
Comment 12 Alexander Miroshnichenko 2018-01-20 08:59:36 UTC
As you can see there nothing displayed until entering runlevel 3 if /dev/console have wrong permissions.

 # eselect rc show sysinit
Status of init scripts in runlevel "sysinit"
  devfs                     [started]
  dmesg                     [started]
  kmod-static-nodes         [started]
  opentmpfiles-dev          [stopped]
  sysfs                     [started]
  udev                      [started]
  udev-trigger              [started]
Comment 13 Jason Zaman gentoo-dev 2018-01-21 04:12:53 UTC
(In reply to Alexander Miroshnichenko from comment #12)
> As you can see there nothing displayed until entering runlevel 3 if
> /dev/console have wrong permissions.

haha i may have actually just never noticed that. but those screenshots make it pretty clear. I'll add /dev/console too :)
Comment 14 Jason Zaman gentoo-dev 2018-01-21 04:15:47 UTC
Actually i think restorecon console should be better off in /lib/rc/sh/init-early.sh

since that script runs first and has parts that echo to console to set font and stuff, the restorecon -F /dev/console should probably go before anything there