Skip to content

Commit aff7ed4

Browse files
WOnder93pcmoore
authored andcommitted
selinux: log raw contexts as untrusted strings
These strings may come from untrusted sources (e.g. file xattrs) so they need to be properly escaped. Reproducer: # setenforce 0 # touch /tmp/test # setfattr -n security.selinux -v 'kuřecí řízek' /tmp/test # runcon system_u:system_r:sshd_t:s0 cat /tmp/test (look at the generated AVCs) Actual result: type=AVC [...] trawcon=kuřecí řízek Expected result: type=AVC [...] trawcon=6B75C5996563C3AD20C599C3AD7A656B Fixes: fede148 ("selinux: log invalid contexts in AVCs") Cc: [email protected] # v5.1+ Signed-off-by: Ondrej Mosnacek <[email protected]> Acked-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 05174c9 commit aff7ed4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

security/selinux/avc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,20 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
739739
rc = security_sid_to_context_inval(sad->state, sad->ssid, &scontext,
740740
&scontext_len);
741741
if (!rc && scontext) {
742-
audit_log_format(ab, " srawcon=%s", scontext);
742+
if (scontext_len && scontext[scontext_len - 1] == '\0')
743+
scontext_len--;
744+
audit_log_format(ab, " srawcon=");
745+
audit_log_n_untrustedstring(ab, scontext, scontext_len);
743746
kfree(scontext);
744747
}
745748

746749
rc = security_sid_to_context_inval(sad->state, sad->tsid, &scontext,
747750
&scontext_len);
748751
if (!rc && scontext) {
749-
audit_log_format(ab, " trawcon=%s", scontext);
752+
if (scontext_len && scontext[scontext_len - 1] == '\0')
753+
scontext_len--;
754+
audit_log_format(ab, " trawcon=");
755+
audit_log_n_untrustedstring(ab, scontext, scontext_len);
750756
kfree(scontext);
751757
}
752758
}

0 commit comments

Comments
 (0)