Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 905371 - sec-policy/selinux-base: Wrong fcontext of "/root"
Summary: sec-policy/selinux-base: Wrong fcontext of "/root"
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: SE Linux Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-30 10:22 UTC by David Sardari
Modified: 2024-08-25 01:35 UTC (History)
3 users (show)

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


Attachments
sec-policy/selinux-base patch (sec-policy_selinux-base.patch,858 bytes, patch)
2024-08-25 01:35 UTC, David Sardari
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Sardari 2023-04-30 10:22:51 UTC
"/root" folder and content have wrong fcontext with "unconfined" useflag and SELINUXTYPE=mcs being used.


Reproducible: Always

Steps to Reproduce:
My installation steps, but don't set "-unconfined" as shown in the 2nd codeblog:
https://github.com/duxsco/gentoo-installation/blob/69f457dd1309bf70f08f8afb139821902ff0243f/docs/selinux.md

Actual Results:  
❯ ls -ldZ /root
drwx------. 1 root root system_u:object_r:default_t:s0 350 30. Apr 09:28 /root/



Expected Results:  
❯ ls -ldZ /root
drwx------. 1 root root root:object_r:user_home_dir_t:s0 304 30. Apr 09:34 /root/



With "unconfined" useflag and SELINUXTYPE=mcs, you get the following fcontext:

❯ ls -ldZ /root
drwx------. 1 root root system_u:object_r:default_t:s0 350 30. Apr 09:28 /root/


This leads to following SELinux denials:

----
[   42.593374] audit: type=1400 audit(1682803607.506:3): avc:  denied  { getattr } for  pid=4582 comm="loadkeys" path="/root" dev="dm-5" ino=76274 scontext=system_u:system_r:udev_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=dir permissive=1
[   42.621347] audit: type=1400 audit(1682803607.506:4): avc:  denied  { getattr } for  pid=4583 comm="loadkeys" path="/root" dev="dm-5" ino=76274 scontext=system_u:system_r:udev_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=dir permissive=1


Object(s) mentioned in SELinux denials with inode number(s):

❯ find / -inum "76274" -context "system_u:object_r:default_t:s0"
/root


Without "unconfined" useflag, you don't get a denial:

❯ ls -ldZ /root
drwx------. 1 root root root:object_r:user_home_dir_t:s0 304 30. Apr 09:34 /root/

❯ sesearch --allow --source udev_t --target user_home_dir_t --class dir --perms getattr
allow nsswitch_domain user_home_dir_t:dir { getattr open search };


Removing these lines solved the denial:
https://github.com/gentoo-mirror/gentoo/blob/stable/sec-policy/selinux-base/selinux-base-2.20221101-r4.ebuild#L102-L106
Comment 1 Kenton Groombridge gentoo-dev 2023-05-18 13:36:43 UTC
Unless I'm missing something, I'm not able to reproduce this.

---
# grep SELINUXTYPE= /etc/selinux/config 
SELINUXTYPE=mcs

# emerge --info selinux-base
[...]
sec-policy/selinux-base-2.20221101-r4::gentoo was built with the following:
USE="systemd ubac unconfined unknown-perms userland_GNU -doc"

# matchpathcon /root
/root	root:object_r:user_home_dir_t:s0

# matchpathcon /home/concord
/home/concord	unconfined_u:object_r:user_home_dir_t:s0

# semanage login -l

Login Name           SELinux User         MLS/MCS Range        Service

__default__          user_u               s0-s0                *
concord              unconfined_u         s0-s0                *
root                 root                 s0-s0                *
---
Comment 2 David Sardari 2023-08-19 21:30:53 UTC
I don't know what I do differently. In another test installation, I face the same problem.

Removing "-e '/root/d' -e " fixes the issue:

https://github.com/gentoo-mirror/gentoo/blob/009c813d340e60a982d7cb0dd286c51b67756a01/sec-policy/selinux-base/selinux-base-2.20221101-r4.ebuild#L103

Then, the "seusers" files have the following content where the linux starting with "root" isn't missing:

❯ find / -xdev -name seusers | xargs head -n 99
==> /etc/selinux/mcs/seusers <==
root:root:s0-s0:c0.c1023
__default__:unconfined_u:s0-s0

==> /var/lib/selinux/mcs/active/seusers <==
root:root:s0-s0:c0.c1023
__default__:unconfined_u:s0-s0
Comment 3 David Sardari 2023-08-19 21:32:17 UTC
I meant "... where the lines* starting...".
Comment 4 David Sardari 2023-08-19 21:39:45 UTC
@concord Apparently, the "sed" line doesn't get applied in your case. I have:

❯ semanage login -l

Login Name           SELinux User         MLS/MCS Range        Service

__default__          unconfined_u         s0-s0                *
david                staff_u              s0-s0:c0.c1023       *
root                 root                 s0-s0:c0.c1023       *
Comment 5 David Sardari 2023-08-19 21:42:45 UTC
.... using the fix by removing "-e '/root/d' -e ".
Comment 6 tithom 2024-07-12 19:58:18 UTC
Hi, I have the same issue following the selinux install page using a hardened systemd stage3.

The one thing where I may have deviated was to use POLICY_TYPES="mcs strict targeted" in /etc/portage/make.conf and not just "mcs" for instance.

I think that the patch of David fixes it (eg. id -Z shows unconfined for root and matchpathcon shows the right context for /root) however relabeling got my system unbootable
Comment 7 David Sardari 2024-08-25 01:35:59 UTC
Created attachment 901183 [details, diff]
sec-policy/selinux-base patch

I attach my patch for completeness sake.