Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selinux loading fix and warning cleanups #2781

Merged
merged 5 commits into from
Mar 3, 2016

Conversation

keszybz
Copy link
Member

@keszybz keszybz commented Mar 2, 2016

No description provided.

@evverx
Copy link
Member

evverx commented Mar 2, 2016

@keszybz , thanks for the test-selinux.
I've found a problem:

$ sudo ./test-selinux
...
mac_selinux_create_label_from_exe → 0 (No such file or directory), "unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023"
...

$ sudo strace ./test-selinux
...
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
open("/sys/fs/selinux/create", O_RDWR)  = 3
write(3, "unconfined_u:unconfined_r:unconf"..., 88) = 88
read(3, "unconfined_u:unconfined_r:unconf"..., 4095) = 54
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
writev(2, [{"mac_selinux_create_label_from_ex"..., 124}, {"\n", 1}], 2mac_selinux_create_label_from_exe → 0 (No such file or directory), "unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023"
...

$ sudo systemctl start mcstransd.service
$ sudo ./test-selinux
...
mac_selinux_create_label_from_exe → 0 (Success), "unconfined_u:unconfined_r:unconfined_t:SystemLow-SystemHigh"
...

So, we use non-raw functions sometimes. It's not good: #1107

This helps to understand misleading gcc warnings about type mismatches.
It seems that it is signed both on i386 and arm.

Avoids a stupid gcc warning on arm:

src/udev/udevadm-monitor.c: In function ‘print_device’:
src/udev/udevadm-monitor.c:44:16: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__time_t {aka long int}’ [-Wformat=]
         printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
                ^
@@ -225,7 +217,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
return -errno;

sclass = string_to_security_class("process");
r = security_compute_create(mycon, fcon, sclass, (security_context_t *) label);
r = security_compute_create_raw(mycon, fcon, sclass, (security_context_t *) label);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keszybz , thanks!
I'm running exec strace -D -ff -o strace-of-systemd /usr/lib/systemd/systemd as init:

bash-4.3# grep -F '.setrans-unix' /strace-of-systemd.1
connect(19, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(22, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(22, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(23, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(23, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(25, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(26, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(28, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(29, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(39, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(39, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(34, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(34, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(35, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(35, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(15, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)
connect(15, {sa_family=AF_LOCAL, sun_path="/var/run/setrans/.setrans-unix"}, 110) = -1 ENOENT (No such file or directory)

So, it's not so easy:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing that here (running with 6f81773de7fe5ad4).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it's strange.
For example: systemd calls mac_selinux_setup. mac_selinux_setup calls setcon. setcon calls selinux_raw_to_trans_context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've prepared a PR: #2797

poettering added a commit that referenced this pull request Mar 3, 2016
Selinux loading fix and warning cleanups
@poettering poettering merged commit 04c760d into systemd:master Mar 3, 2016
@keszybz keszybz deleted the selinux-and-warnings branch March 3, 2016 17:55
evverx added a commit to evverx/systemd that referenced this pull request Mar 4, 2016
Very handy for early-boot debugging
See systemd#2781 (comment)
fbuihuu pushed a commit to fbuihuu/systemd-opensuse-next that referenced this pull request Apr 11, 2019
As suggested by Evgeny Vereshchagin as a follow up for
systemd/systemd#2781 (comment).

(cherry picked from commit 5c5433a)
fbuihuu pushed a commit to fbuihuu/systemd-opensuse-next that referenced this pull request Apr 11, 2019
As suggested by Evgeny Vereshchagin as a follow up for
systemd/systemd#2781 (comment).

(cherry picked from commit 5c5433a)
fbuihuu pushed a commit to openSUSE/systemd that referenced this pull request Apr 29, 2019
As suggested by Evgeny Vereshchagin as a follow up for
systemd/systemd#2781 (comment).

(cherry picked from commit 5c5433a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants