Skip to content

Commit ea74a68

Browse files
rgbriggspcmoore
authored andcommitted
selinux: format all invalid context as untrusted
The userspace tools expect all fields of the same name to be logged consistently with the same encoding. Since the invalid_context fields contain untrusted strings in selinux_inode_setxattr() and selinux_setprocattr(), encode all instances of this field the same way as though they were untrusted even though compute_sid_handle_invalid_context() and security_sid_mls_copy() are trusted. Please see github issue linux-audit/audit-kernel#57 Signed-off-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 464c258 commit ea74a68

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

security/selinux/ss/services.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,19 +1584,22 @@ static int compute_sid_handle_invalid_context(
15841584
struct policydb *policydb = &state->ss->policydb;
15851585
char *s = NULL, *t = NULL, *n = NULL;
15861586
u32 slen, tlen, nlen;
1587+
struct audit_buffer *ab;
15871588

15881589
if (context_struct_to_string(policydb, scontext, &s, &slen))
15891590
goto out;
15901591
if (context_struct_to_string(policydb, tcontext, &t, &tlen))
15911592
goto out;
15921593
if (context_struct_to_string(policydb, newcontext, &n, &nlen))
15931594
goto out;
1594-
audit_log(audit_context(), GFP_ATOMIC, AUDIT_SELINUX_ERR,
1595-
"op=security_compute_sid invalid_context=%s"
1596-
" scontext=%s"
1597-
" tcontext=%s"
1598-
" tclass=%s",
1599-
n, s, t, sym_name(policydb, SYM_CLASSES, tclass-1));
1595+
ab = audit_log_start(audit_context(), GFP_ATOMIC, AUDIT_SELINUX_ERR);
1596+
audit_log_format(ab,
1597+
"op=security_compute_sid invalid_context=");
1598+
/* no need to record the NUL with untrusted strings */
1599+
audit_log_n_untrustedstring(ab, n, nlen - 1);
1600+
audit_log_format(ab, " scontext=%s tcontext=%s tclass=%s",
1601+
s, t, sym_name(policydb, SYM_CLASSES, tclass-1));
1602+
audit_log_end(ab);
16001603
out:
16011604
kfree(s);
16021605
kfree(t);
@@ -3003,10 +3006,16 @@ int security_sid_mls_copy(struct selinux_state *state,
30033006
if (rc) {
30043007
if (!context_struct_to_string(policydb, &newcon, &s,
30053008
&len)) {
3006-
audit_log(audit_context(),
3007-
GFP_ATOMIC, AUDIT_SELINUX_ERR,
3008-
"op=security_sid_mls_copy "
3009-
"invalid_context=%s", s);
3009+
struct audit_buffer *ab;
3010+
3011+
ab = audit_log_start(audit_context(),
3012+
GFP_ATOMIC,
3013+
AUDIT_SELINUX_ERR);
3014+
audit_log_format(ab,
3015+
"op=security_sid_mls_copy invalid_context=");
3016+
/* don't record NUL with untrusted strings */
3017+
audit_log_n_untrustedstring(ab, s, len - 1);
3018+
audit_log_end(ab);
30103019
kfree(s);
30113020
}
30123021
goto out_unlock;

0 commit comments

Comments
 (0)