Bug 1275153 - libselinux: get_default_context() does not work correctly if there is a big list of possible contexts
libselinux: get_default_context() does not work correctly if there is a big l...
Status: CLOSED EOL
Product: Fedora
Classification: Fedora
Component: selinux-policy (Show other bugs)
24
Unspecified Unspecified
unspecified Severity medium
: ---
: ---
Assigned To: Lukas Vrabec
Fedora Extras Quality Assurance
:
Depends On: 1274345
Blocks:
  Show dependency treegraph
 
Reported: 2015-10-26 03:01 EDT by Miroslav Grepl
Modified: 2017-08-08 08:19 EDT (History)
13 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1274345
Environment:
Last Closed: 2017-08-08 08:19:34 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Miroslav Grepl 2015-10-26 03:01:44 EDT
+++ This bug was initially created as a clone of Bug #1274345 +++

Description of problem:

Trying to make "systemd --user" + pam_selinux working correctly for confined users. If I have all policy changes then I am not able to get a correct context for "systemd --user" 

staff_u:unconfined_r:unconfined_t:s0 mgrepl 1541   1  0 09:00 ?        00:00:00 /usr/lib/systemd/systemd --user

instead of staff_t. I see

audit[1024]: USER_ROLE_CHANGE pid=1024 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='pam: default-context=unconfined_u:unconfined_r:unconfined_t:s0 selected-context=unconfined_u:unconfined_r:unconfined_t:s0 exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'

The problem is with enabled uncofined.pp module.


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

$ rpm -q libselinux
libselinux-2.4-4.fc24.x86_64

How reproducible:

1. With enabled unconfined.pp module

selinux.security_compute_user("system_u:system_r:init_t:s0","staff_u")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 34] Numerical result out of range

which causes you continue with a context defined in "/etc/selinux/targeted/contexts/failsafe_context".


2. With disabled unconfined.pp module

selinux.security_compute_user("system_u:system_r:init_t:s0","staff_u")

returns a correct list and 

selinux.get_default_context("staff_u","system_u:system_r:init_t:s0")
[0, 'staff_u:staff_r:staff_t:s0']

--- Additional comment from Petr Lautrbach on 2015-10-22 11:11:30 EDT ---

It could be a problem in kernel which hit some kind of limit?

# echo -n system_u:system_r:init_t:s0 staff_u > /sys/fs/selinux/user
echo: write error: numerical result out of range

--- Additional comment from Petr Lautrbach on 2015-10-22 11:21:38 EDT ---

So it seems to the code in kernel security/selinux/selinuxfs.c which hits the SIMPLE_TRANSACTION_LIMIT:

security/selinux/selinuxfs.c:
 916 static ssize_t sel_write_user(struct file *file, char *buf, size_t size)
 ...
 953         for (i = 0; i < nsids; i++) {
 954                 rc = security_sid_to_context(sids[i], &newcon, &len);
 955                 if (rc) {
 956                         length = rc;
 957                         goto out;
 958                 }
 959                 if ((length + len) >= SIMPLE_TRANSACTION_LIMIT) {
 960                         kfree(newcon);
 961                         length = -ERANGE;
 962                         goto out;
 963                 }
 964                 memcpy(ptr, newcon, len);
 965                 kfree(newcon);
 966                 ptr += len;
 967                 length += len;
 968         }

I'm not sure if it's expected, or the limit could be raised or policy changed?

--- Additional comment from Paul Moore on 2015-10-22 15:41:37 EDT ---

The SIMPLE_TRANSACTION_LIMIT is due to our use of the simple_transaction_* set of APIs in the kernel, removing the current limit would require a good deal of work in the kernel.  Without knowing too much about the problem you're trying to solve, is there some workaround in userspace?  After all, the limit should be almost a full page size ...

--- Additional comment from Miroslav Grepl on 2015-10-23 02:56:24 EDT ---

The problem is we are not able to get confined users working with enabled unconfined.pp module. We have pam_selinux.so in /etc/pam.d/systemd-user to have it running in a user domain instead of init_t.

But security_compute_user() is not able to get all possible contexts with enabled unconfined.pp module because we have a lot of transition rules to staff_t. 

It is caused by

optional_policy(`
 unconfined_domain(init_t)
')

So we would need to run with confined init_t by default to avoid it. But I can not imagine it now. But we could probably review these transitions rules for unconfined domains.

--- Additional comment from Miroslav Grepl on 2015-10-23 07:33:04 EDT ---

I am playing with policy changes to make it working which I will need to discuss with upstream.

--- Additional comment from Paul Moore on 2015-10-23 11:53:38 EDT ---

Okay.  If there is a workaround in policy it will be much quicker than trying to solve this in the kernel, although we could still keep this BZ open to address the kernel limit at a later date.
Comment 1 Miroslav Grepl 2015-10-26 05:35:05 EDT
Ok I apologize but I totally overlooked

allow initrc_domain daemon:process transition;

rule which is really needed to have a correct transitions if services are started. So not sure what we can do in the policy with this.
Comment 2 Jan Kurik 2016-02-24 10:36:58 EST
This bug appears to have been reported against 'rawhide' during the Fedora 24 development cycle.
Changing version to '24'.

More information and reason for this action is here:
https://fedoraproject.org/wiki/Fedora_Program_Management/HouseKeeping/Fedora24#Rawhide_Rebase
Comment 3 Fedora Admin XMLRPC Client 2016-09-27 11:07:31 EDT
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 4 Fedora End Of Life 2017-07-25 15:23:38 EDT
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. 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 Fedora  'version'
of '24'.

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

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 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, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.
Comment 5 Fedora End Of Life 2017-08-08 08:19:34 EDT
Fedora 24 changed to end-of-life (EOL) status on 2017-08-08. Fedora 24 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 please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

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

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