Bug 1801846

Summary: useradd: use set_selinux_file_context() and reset_selinux_file_context() for create_mail() just as is done for create_home()
Product: [Fedora] Fedora Reporter: Petr Lautrbach <plautrba>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: 31CC: dac.override, dwalsh, extras-qa, grepl.miroslav, ipedrosa, lvrabec, mmalik, plautrba, pvrabec, tmraz, vmojzis, zpytela
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1690527 Environment:
Last Closed: 2020-11-24 19:49:06 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1690527    
Bug Blocks:    

Description Petr Lautrbach 2020-02-11 17:59:49 UTC
+++ This bug was initially created as a clone of Bug #1690527 +++

Description of problem:

useradd does not "create_mail()" (create /var/spool/mail/$USER) with a proper context currently

create_home() calls set_selinux_file_context() and reset_selinux_file_context()
when user home is created to ensure that user home is labeled properly.

https://github.com/shadow-maint/shadow/blob/master/src/useradd.c#L2042

create_mail() however does not, and so user mail spool files end up mislabeled.

https://github.com/shadow-maint/shadow/blob/master/src/useradd.c#L2131

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

shadow-utils-4.6-9.fc31.x86_64

How reproducible:
useradd -Z user_u joe

Steps to Reproduce:
1. useradd -Z user_u joe
2. ls -alZ /var/spool/mail/joe
3. note now the selinux user identity in the context of /var/spool/mail/joe is not user_u 

Actual results:
the selinux user identity of /var/spool/mail/joe is not "user_u"

Expected results:
the selinux user identity of /var/spool/mail/joe is "user_u"

Additional info:
Access control can be enforced based on selinux user identities, roles and security levels (just as on types). It is important that the labels are acurate

--- Additional comment from  on 2019-03-19 17:25:51 CET ---

Err, well the reproducer is not acurate ...

You would need to leverage it properly first, like so:

echo '(filecon "/var/spool/mail/%{USERNAME}" file (system_u object_r mail_spool_t ((s0)(s0))))' > mytest.cil && sudo semodule -i mytest.cil
useradd -Z user_u joe
matchpathcon /var/spool/mail/joe
ls -alZ /var/spool/mail/joe

--- Additional comment from Ben Cotton on 2019-08-13 19:06:31 CEST ---

This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

--- Additional comment from Ben Cotton on 2019-08-13 21:31:00 CEST ---

This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

--- Additional comment from  on 2020-02-06 15:37:35 CET ---

I have a fix for this issue. Would you be willing to test a scratch build?

--- Additional comment from  on 2020-02-06 17:59:40 CET ---

heck yes! Can I have URL to scratch built?

--- Additional comment from  on 2020-02-10 13:11:20 CET ---

I am patiently awaiting the URL of the scratch built so that i can test to see whether the patch address the requested functionality

--- Additional comment from  on 2020-02-10 13:26:02 CET ---

Sorry, when I was on the point of generating the scratch build I got some comments on the pull-request that I created to fix this bug. I'm still trying to figure out how to make the improvements from the comment and keep the fix working as it should. I will come back to you as soon as everything is ready.

--- Additional comment from Petr Lautrbach on 2020-02-11 14:53:19 CET ---

The patch from PR looks good, however it would also need to update selinux-policy in order to provide a template file context for /var/spool/mail/USER

--- Additional comment from Petr Lautrbach on 2020-02-11 18:36:25 CET ---

I'd expect something like:

--- a/mta.fc
+++ b/mta.fc
@@ -41,4 +41,5 @@ ifdef(`distro_redhat',`
 /var/spool/(client)?mqueue(/.*)?       gen_context(system_u:object_r:mqueue_spool_t,s0)
 /var/spool/mqueue\.in(/.*)?    gen_context(system_u:object_r:mqueue_spool_t,s0)
 /var/spool/mail(/.*)?          gen_context(system_u:object_r:mail_spool_t,s0)
+/var/spool/mail/USER           --      gen_context(system_u:object_r:mail_spool_t,s0)
 /var/spool/smtpd(/.*)?         gen_context(system_u:object_r:mail_spool_t,s0)

--- Additional comment from Petr Lautrbach on 2020-02-11 18:58:57 CET ---

https://koji.fedoraproject.org/koji/taskinfo?taskID=41459946

before

$ matchpathcon /var/spool/mail/user
/var/spool/mail/user    system_u:object_r:mail_spool_t:s0

after

$ matchpathcon /var/spool/mail/user
/var/spool/mail/user    user_u:object_r:mail_spool_t:s0

Comment 1 Ben Cotton 2020-11-03 17:25:42 UTC
This message is a reminder that Fedora 31 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 31 on 2020-11-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 '31'.

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 31 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 2 Ben Cotton 2020-11-24 19:49:06 UTC
Fedora 31 changed to end-of-life (EOL) status on 2020-11-24. Fedora 31 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.