Bug 1965001 - Fix possible AVC denial when copystat-ing some /proc/sys/vm/ files
Summary: Fix possible AVC denial when copystat-ing some /proc/sys/vm/ files
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: sos
Version: ---
Hardware: All
OS: Linux
Target Milestone: beta
: ---
Assignee: Pavel Moravec
QA Contact: Miroslav Hradílek
Depends On:
TreeView+ depends on / blocked
Reported: 2021-05-26 14:07 UTC by Pavel Moravec
Modified: 2021-11-10 07:44 UTC (History)
6 users (show)

Fixed In Version: sos-4.1-3.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2021-11-09 19:36:31 UTC
Type: Bug
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Github sosreport sos pull 2560 0 None open [archive] skip copying SELinux context for /proc and /sys everytime 2021-05-26 14:07:19 UTC
Red Hat Product Errata RHEA-2021:4388 0 None None None 2021-11-09 19:36:56 UTC

Description Pavel Moravec 2021-05-26 14:07:19 UTC
Description of problem:
TL;DR: backport https://github.com/sosreport/sos/pull/2560 to RHEL8.5.

Longer version: sosreport still attempts to copystat also SELinux context of some files from /proc or /sys (when adding the files as strings, or for special device files like pipe/shmem/..). This affects newer versions of SELinux policy than what probably appears in 8.5 GA, but it will harm us once the policy is updated a bit.

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

How reproducible:

Steps to Reproduce:
1. Have a SELinux policy preventing to relabel files under /tmp to system_u:object_r:sysctl_vm_t:s0 context (like /proc/sys/vm/drop_caches has).
2. Run sos report in temp dir under /tmp:
TmpDir=$(mktemp -d)
sos report -o system --batch -vvv --tmp-dir=$TmpDir
3. Check AVC denials
4. Check if all files under _collected_ /proc/sys/vm/ dir (esp drop_caches and compact_memory) has unconfined_u:object_r:user_tmp_t:s0 context and not system_u:object_r:sysctl_vm_t:s0 one, and proper mode&permissions.

Actual results:
sos reports an error:
[archive:TarFileArchive] Unable to add '/tmp/tmp.tlrpbtJP3y/sos.n4i00rxe/sosreport-pmoravec-rhel9-2021-05-26-taiozlo/proc/sys/vm/drop_caches' to archive: [Errno 13] Permission denied: '/tmp/tmp.tlrpbtJP3y/sos.n4i00rxe/sosreport-pmoravec-rhel9-2021-05-26-taiozlo/proc/sys/vm/drop_caches'

and the same for compact_memory.

AVC denials:

type=AVC msg=audit(1622032383.981:332): avc:  denied  { associate } for  pid=1456 comm="sosreport" name="compact_memory" dev="tmpfs" ino=5873 scontext=system_u:object_r:sysctl_vm_t:s0 tcontext=system_u:object_r:tmpfs_t:s0 tclass=filesystem permissive=0
type=AVC msg=audit(1622032384.292:333): avc:  denied  { associate } for  pid=1456 comm="sosreport" name="drop_caches" dev="tmpfs" ino=6374 scontext=system_u:object_r:sysctl_vm_t:s0 tcontext=system_u:object_r:tmpfs_t:s0 tclass=filesystem permissive=0

Expected results:
No sos errors, and no AVCs.

Additional info:

Comment 1 Pavel Moravec 2021-05-27 12:14:47 UTC
Yet better test is to verify, if sos_logs/sos.log does contain something like:

2021-05-27 14:11:14,526 ERROR: [archive:TarFileArchive] Unable to add '/tmp/sos.2u13ssqj/sosreport-pmoravec-rhel9-2021-05-27-oppitki/proc/sys/vm/compact_memory' to archive: [Errno 13] Permission denied: '/tmp/sos.2u13ssqj/sosreport-pmoravec-rhel9-2021-05-27-oppitki/proc/sys/vm/compact_memory'
2021-05-27 14:11:14,863 ERROR: [archive:TarFileArchive] Unable to add '/tmp/sos.2u13ssqj/sosreport-pmoravec-rhel9-2021-05-27-oppitki/proc/sys/vm/drop_caches' to archive: [Errno 13] Permission denied: '/tmp/sos.2u13ssqj/sosreport-pmoravec-rhel9-2021-05-27-oppitki/proc/sys/vm/drop_caches'

or not.

Comment 6 errata-xmlrpc 2021-11-09 19:36:31 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (sos bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


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