linux_dsm_epyc7002/security/selinux/ss
Ondrej Mosnacek fede148324 selinux: log invalid contexts in AVCs
In case a file has an invalid context set, in an AVC record generated
upon access to such file, the target context is always reported as
unlabeled. This patch adds new optional fields to the AVC record
(srawcon and trawcon) that report the actual context string if it
differs from the one reported in scontext/tcontext. This is useful for
diagnosing SELinux denials involving invalid contexts.

To trigger an AVC that illustrates this situation:

    # setenforce 0
    # touch /tmp/testfile
    # setfattr -n security.selinux -v system_u:object_r:banana_t:s0 /tmp/testfile
    # runcon system_u:system_r:sshd_t:s0 cat /tmp/testfile

AVC before:

type=AVC msg=audit(1547801083.248:11): avc:  denied  { open } for  pid=1149 comm="cat" path="/tmp/testfile" dev="tmpfs" ino=6608 scontext=system_u:system_r:sshd_t:s0 tcontext=system_u:object_r:unlabeled_t:s15:c0.c1023 tclass=file permissive=1

AVC after:

type=AVC msg=audit(1547801083.248:11): avc:  denied  { open } for  pid=1149 comm="cat" path="/tmp/testfile" dev="tmpfs" ino=6608 scontext=system_u:system_r:sshd_t:s0 tcontext=system_u:object_r:unlabeled_t:s15:c0.c1023 tclass=file permissive=1 trawcon=system_u:object_r:banana_t:s0

Note that it is also possible to encounter this situation with the
'scontext' field - e.g. when a new policy is loaded while a process is
running, whose context is not valid in the new policy.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=1135683

Cc: Daniel Walsh <dwalsh@redhat.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <paul@paul-moore.com>
2019-01-25 17:31:14 -05:00
..
avtab.c selinux: Cleanup printk logging in avtab 2018-06-19 13:00:48 -04:00
avtab.h selinux: wrap global selinux state 2018-03-01 18:48:02 -05:00
conditional.c selinux: Cleanup printk logging in conditional 2018-06-19 11:39:12 -04:00
conditional.h selinux: extended permissions for ioctls 2015-07-13 13:31:58 -04:00
constraint.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
context.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ebitmap.c selinux: Cleanup printk logging in ebitmap 2018-06-19 11:47:46 -04:00
ebitmap.h selinux: wrap global selinux state 2018-03-01 18:48:02 -05:00
hashtab.c selinux: wrap global selinux state 2018-03-01 18:48:02 -05:00
hashtab.h selinux: wrap global selinux state 2018-03-01 18:48:02 -05:00
mls_types.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mls.c selinux/stable-4.21 PR 20181224 2018-12-27 12:01:58 -08:00
mls.h selinux: overhaul sidtab to fix bug and improve performance 2018-12-05 16:12:32 -05:00
policydb.c selinux: use separate table for initial SID lookup 2018-12-05 15:36:12 -05:00
policydb.h selinux: update my email address 2017-08-17 15:32:55 -04:00
services.c selinux: log invalid contexts in AVCs 2019-01-25 17:31:14 -05:00
services.h selinux: use separate table for initial SID lookup 2018-12-05 15:36:12 -05:00
sidtab.c selinux: overhaul sidtab to fix bug and improve performance 2018-12-05 16:12:32 -05:00
sidtab.h selinux: overhaul sidtab to fix bug and improve performance 2018-12-05 16:12:32 -05:00
status.c selinux: rename the {is,set}_enforcing() functions 2018-03-02 14:18:55 -05:00
symtab.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
symtab.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00