Bug 2084077 - SELinux prevents portablectl detach
Summary: SELinux prevents portablectl detach
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 38
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Zdenek Pytela
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2022-05-11 10:32 UTC by Sam Thursfield
Modified: 2023-02-07 15:09 UTC (History)
19 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2022-12-13 17:58:10 UTC
Type: Bug

Attachments (Terms of Use)

Description Sam Thursfield 2022-05-11 10:32:07 UTC
Description of problem:

Detaching a filesystem-based Portable Service does not work:

[I] sam@ausecuma ~/s/portable-walkthrough (main)> sudo portablectl attach /opt/serialosc
(Matching unit files with prefix 'serialosc'.)
Created directory /etc/systemd/system.attached/serialosc.service.d.
Written /etc/systemd/system.attached/serialosc.service.d/20-portable.conf.
Created symlink /etc/systemd/system.attached/serialosc.service.d/10-profile.conf → /usr/lib/systemd/portable/profile/default/service.conf.
Copied /opt/serialosc/usr/local/lib/systemd/system/serialosc.service → /etc/systemd/system.attached/serialosc.service.
Created symlink /etc/portables/serialosc → /opt/serialosc.
[I] sam@ausecuma ~/s/portable-walkthrough (main)> sudo portablectl detach /opt/serialosc
DetachImage failed: Access denied

Disabling SELinux with `setenforce 0` works around the issue.

Relevant audit.log entry appears to be this:

type=USER_AVC msg=audit(1652264980.399:749): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc:  denied  { status } for auid=n/a uid=0 gid=0 path="/etc/systemd/system.attached/serialosc.service" cmdline="/usr/lib/systemd/systemd-portabled" scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:etc_runtime_t:s0 tclass=service permissive=0  exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'^]UID="root" AUID="unset" AUID="root" UID="root" GID="root" SAUID="root"

Related issue: https://bugzilla.redhat.com/show_bug.cgi?id=1922580 - I have confirmed that this bug is also still present in Fedora 35.

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

> portablectl --version
systemd 249 (v249.11-2.fc35)

How reproducible: always.

Steps to Reproduce:
1. Attach a portable service from filesystem (if you try to attach an image, you will hit https://bugzilla.redhat.com/show_bug.cgi?id=1922580)
2. Try to detach it.

Actual results:

Access denied error.

Expected results:

Service is detached.

Comment 1 Milos Malik 2022-05-13 09:32:35 UTC
I would like you to test a workaround.

My assumptions are:
1) SELinux label on the systemd-portabled file was not changed:

# ls -Z /usr/lib/systemd/systemd-portabled
system_u:object_r:init_exec_t:s0 /usr/lib/systemd/systemd-portabled

2) After starting the systemd-portabled service, the systemd-portabled process runs as init_t:

system_u:system_r:init_t:s0     root        1448       1  0 05:22 ?        00:00:00 /usr/lib/systemd/systemd-portabled

The workaround consists of the following commands:

# chcon -t usr_t /usr/lib/systemd/systemd-portabled
# systemctl restart systemd-portabled

Purpose of the workaround is to run the systemd-portabled service as unconfined_service_t (instead of init_t) and see if that helps.

Does the portablectl command mentioned above work now?

Thank you.

Comment 2 Milos Malik 2022-05-13 09:34:58 UTC
Why a workaround? Because SELinux policy currently does not provide any special policy for the systemd-portabled program.

Comment 3 Sam Thursfield 2022-05-23 10:47:03 UTC
Hi Milos,
Thanks for the workaround, I just tested this and the commands work without error now.

Comment 4 Zdenek Pytela 2022-05-23 11:07:27 UTC
There are plans to confined the service, but probably only for F37.

Comment 5 Ben Cotton 2022-11-29 18:54:01 UTC
This message is a reminder that Fedora Linux 35 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 35 on 2022-12-13.
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 '35'.

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 35 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 6 Ben Cotton 2022-12-13 17:58:10 UTC
Fedora Linux 35 entered end-of-life (EOL) status on 2022-12-13.

Fedora Linux 35 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora Linux
please feel free to reopen this bug against that version. Note that the version
field may be hidden. Click the "Show advanced fields" button if you do not see
the version field.

If you are unable to reopen this bug, please file a new report against an
active release.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 7 Ben Cotton 2023-02-07 15:09:23 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 38 development cycle.
Changing version to 38.

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