Bug 1980241 - systemd-run --shell denied by selinux
Summary: systemd-run --shell denied by selinux
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 36
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Zdenek Pytela
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-07-08 07:50 UTC by Roshan Shariff
Modified: 2022-05-28 01:14 UTC (History)
7 users (show)

Fixed In Version: selinux-policy-36.9-1.fc36
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-05-28 01:14:46 UTC
Type: Bug


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github fedora-selinux selinux-policy pull 1190 0 None open Allow systemd watch and watch_reads user ptys 2022-05-13 17:05:30 UTC

Description Roshan Shariff 2021-07-08 07:50:33 UTC
Description of problem:

"systemd-run --shell" fails because of an selinux denial.

Version-Release number of selected component (if applicable):

systemd-248.3-1.fc34.x86_64
selinux-policy-34.12-1.fc34.noarch

How reproducible:

Consistent failure.

Steps to Reproduce:
1. Run "systemd-run --shell"

Actual results:

Command fails with exit code 208 and the following audit message:

type=AVC msg=audit(1625730032.182:1683): avc:  denied  { watch watch_reads } for  pid=346163 comm="(bash)" path="/dev/pts/2" dev="devpts" ino=5 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:user_devpts_t:s0 tclass=chr_file permissive=0

Expected results:

systemd-run --shell
Running as unit: run-u713.service
Press ^] three times within 1s to disconnect TTY.
[root@localhost root]# 

Additional info:

This bug seems to be similar to bug #1647162 but for "watch" and "watch_reads" permissions.  The expected behaviour is achieved by loading the following selinux module:

module my-systemd-run-pty 1.0;

require {
	type user_devpts_t;
	type init_t;
	class chr_file { watch watch_reads };
}

#============= init_t ==============
allow init_t user_devpts_t:chr_file { watch watch_reads };

Comment 1 Ben Cotton 2022-05-12 16:50:27 UTC
This message is a reminder that Fedora Linux 34 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 34 on 2022-06-07.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '34'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 34 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 2 Milos Malik 2022-05-13 14:58:56 UTC
Following SELinux denial appears in enforcing mode:
----
type=PROCTITLE msg=audit(05/13/2022 10:57:19.765:435) : proctitle=(bash) 
type=PATH msg=audit(05/13/2022 10:57:19.765:435) : item=0 name=/dev/pts/1 inode=4 dev=00:19 mode=character,620 ouid=root ogid=tty rdev=88:01 obj=unconfined_u:object_r:user_devpts_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(05/13/2022 10:57:19.765:435) : cwd=/ 
type=SYSCALL msg=audit(05/13/2022 10:57:19.765:435) : arch=x86_64 syscall=inotify_add_watch success=no exit=EACCES(Permission denied) a0=0x3 a1=0x55e39a4fe560 a2=0x18 a3=0x0 items=1 ppid=1 pid=1109 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=(bash) exe=/usr/lib/systemd/systemd subj=system_u:system_r:init_t:s0 key=(null) 
type=AVC msg=audit(05/13/2022 10:57:19.765:435) : avc:  denied  { watch watch_reads } for  pid=1109 comm=(bash) path=/dev/pts/1 dev="devpts" ino=4 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:user_devpts_t:s0 tclass=chr_file permissive=0 
----

# rpm -qa selinux\* systemd\* | sort
selinux-policy-34.27-1.fc34.noarch
selinux-policy-targeted-34.27-1.fc34.noarch
systemd-248.10-1.fc34.x86_64
systemd-libs-248.10-1.fc34.x86_64
systemd-networkd-248.10-1.fc34.x86_64
systemd-oomd-defaults-248.10-1.fc34.x86_64
systemd-pam-248.10-1.fc34.x86_64
systemd-rpm-macros-248.10-1.fc34.noarch
systemd-udev-248.10-1.fc34.x86_64
#

Comment 3 Milos Malik 2022-05-13 15:01:54 UTC
The following SELinux denial appears in permissive mode:
----
type=PROCTITLE msg=audit(05/13/2022 11:00:28.626:439) : proctitle=(bash) 
type=PATH msg=audit(05/13/2022 11:00:28.626:439) : item=0 name=/dev/pts/1 inode=4 dev=00:19 mode=character,620 ouid=root ogid=tty rdev=88:01 obj=unconfined_u:object_r:user_devpts_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(05/13/2022 11:00:28.626:439) : cwd=/ 
type=SYSCALL msg=audit(05/13/2022 11:00:28.626:439) : arch=x86_64 syscall=inotify_add_watch success=yes exit=1 a0=0x3 a1=0x55e39a65b100 a2=0x18 a3=0x0 items=1 ppid=1 pid=1123 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=(bash) exe=/usr/lib/systemd/systemd subj=system_u:system_r:init_t:s0 key=(null) 
type=AVC msg=audit(05/13/2022 11:00:28.626:439) : avc:  denied  { watch watch_reads } for  pid=1123 comm=(bash) path=/dev/pts/1 dev="devpts" ino=4 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:user_devpts_t:s0 tclass=chr_file permissive=1 
----

Comment 4 Milos Malik 2022-05-13 15:04:34 UTC
Seen in enforcing mode:

# systemd-run --shell
Running as unit: run-u21.service
Press ^] three times within 1s to disconnect TTY.
Finished with result: exit-code
Main processes terminated with: code=exited/status=208
Service runtime: 11ms
CPU time consumed: 944us
#

Seen in permissive mode:

# systemd-run --shell
Running as unit: run-u23.service
Press ^] three times within 1s to disconnect TTY.
[root@fedora root]# Error on PTY forwarding logic: Operation canceled

Finished with result: success
CPU time consumed: 7ms
#

Comment 7 Milos Malik 2022-05-13 17:19:23 UTC
Test coverage for this bug exists in a form of PR:
 * https://src.fedoraproject.org/tests/selinux/pull-request/301

The PR waits for review.

Comment 8 Fedora Update System 2022-05-19 16:24:26 UTC
FEDORA-2022-148223ef3b has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-148223ef3b

Comment 9 Fedora Update System 2022-05-20 02:54:39 UTC
FEDORA-2022-148223ef3b has been pushed to the Fedora 36 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2022-148223ef3b`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2022-148223ef3b

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 10 Fedora Update System 2022-05-28 01:14:46 UTC
FEDORA-2022-148223ef3b has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.