libsepol, libselinux, audit2allow: teach audit2why about type bounds failures
PATCH 1/1 libsepol, libselinux, audit2allow: teach audit2why about type bounds failures
Teach audit2why to recognize type bounds failures. This required updating libsepol sepol_compute_av_reason() to identify bounds failures, and updating libsepol context_struct_compute_av() to include the type bounds logic from the kernel.
This could potentially be further augmented to provide more detailed reporting via the reason buffer to include information similar to what security_dump_masked_av() reports in the kernel. However, it is unclear if this is needed. It is already possible to get type bounds checking at policy build time by enabling expand-check=1 in /etc/selinux/semanage.conf (or by default when compiling monolithic policy).
Before:
type=AVC msg=audit(1480451925.038:3225): avc: denied { getattr } for pid=7118 comm="chmod" path="/home/sds/selinux-testsuite/tests/bounds/bounds_file_blue" dev="dm-2" ino=23337697 scontext=unconfined_u:unconfined_r:test_bounds_child_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:test_bounds_file_blue_t:s0 tclass=file permissive=0
Was caused by:
Unknown - would be allowed by active policy
Possible mismatch between this policy and the one under which the audit message was generated.
Possible mismatch between current in-memory boolean settings vs. permanent ones.
After:
type=AVC msg=audit(1480451925.038:3225): avc: denied { getattr } for pid=7118 comm="chmod" path="/home/sds/selinux-testsuite/tests/bounds/bounds_file_blue" dev="dm-2" ino=23337697 scontext=unconfined_u:unconfined_r:test_bounds_child_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:test_bounds_file_blue_t:s0 tclass=file permissive=0
Was caused by:
Typebounds violation.
Add an allow rule for the parent type.
--- libselinux/src/audit2why.c | 5 ++ libsepol/include/sepol/policydb/services.h | 7 +-- libsepol/src/services.c | 77 ++++++++++++++++++++++++++++-- python/audit2allow/audit2allow | 5 ++ 4 files changed, 86 insertions(+), 8 deletions(-)
libselinux/src/audit2why.c +5 -0
@@ -28,6 +28,7 @@#define BOOLEAN 3#define CONSTRAINT 4#define RBAC 5 +#define BOUNDS 6struct boolean_t {char *name;
@@ -425,6 +426,9 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *argsif (reason &SEPOL_COMPUTEAV_RBAC ) RETURN(RBAC) +if (reason &SEPOL_COMPUTEAV_BOUNDS ) + RETURN(BOUNDS) + RETURN(BADCOMPUTE) }
@@ -481,6 +485,7 @@ PyMODINIT_FUNC initaudit2why(void)PyModule_AddIntConstant (m,"BOOLEAN" ,BOOLEAN );PyModule_AddIntConstant (m,"CONSTRAINT" ,CONSTRAINT );PyModule_AddIntConstant (m,"RBAC" ,RBAC ); +PyModule_AddIntConstant (m,"BOUNDS" ,BOUNDS );#if PY_MAJOR_VERSION >=3 return m;
libsepol/include/sepol/policydb/services.h +4 -3
@@ -52,9 +52,10 @@ extern int sepol_compute_av(sepol_security_id_t ssid, /* IN *//* Same as above, but also return the reason(s) for any denials of the requested permissions. */ -#define SEPOL_COMPUTEAV_TE 1 -#define SEPOL_COMPUTEAV_CONS 2 -#define SEPOL_COMPUTEAV_RBAC 4 +#define SEPOL_COMPUTEAV_TE 0x1U +#define SEPOL_COMPUTEAV_CONS 0x2U +#define SEPOL_COMPUTEAV_RBAC 0x4U +#define SEPOL_COMPUTEAV_BOUNDS 0x8U extern int sepol_compute_av_reason(sepol_security_id_t ssid, sepol_security_id_t tsid, sepol_security_class_t tclass,
libsepol/src/services.c +72 -5
116 lines not on this page · raw message
python/audit2allow/audit2allow +5 -0
@@ -285,6 +285,11 @@ class AuditToPolicy: print("\t\tAdd an allow rule for the role pair.\n") continue + if rc == audit2why.BOUNDS: + print("\t\tTypebounds violation.\n") + print("\t\tAdd an allow rule for the parent type.\n") + continue + audit2why.finish() return
Signature · 1 line
2.7.4