aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--security/selinux/hooks.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index dc15f16a357c..c3ee902306d8 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2792,8 +2792,25 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2792 2792
2793 rc = security_context_to_sid(value, size, &newsid); 2793 rc = security_context_to_sid(value, size, &newsid);
2794 if (rc == -EINVAL) { 2794 if (rc == -EINVAL) {
2795 if (!capable(CAP_MAC_ADMIN)) 2795 if (!capable(CAP_MAC_ADMIN)) {
2796 struct audit_buffer *ab;
2797 size_t audit_size;
2798 const char *str;
2799
2800 /* We strip a nul only if it is at the end, otherwise the
2801 * context contains a nul and we should audit that */
2802 str = value;
2803 if (str[size - 1] == '\0')
2804 audit_size = size - 1;
2805 else
2806 audit_size = size;
2807 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
2808 audit_log_format(ab, "op=setxattr invalid_context=");
2809 audit_log_n_untrustedstring(ab, value, audit_size);
2810 audit_log_end(ab);
2811
2796 return rc; 2812 return rc;
2813 }
2797 rc = security_context_to_sid_force(value, size, &newsid); 2814 rc = security_context_to_sid_force(value, size, &newsid);
2798 } 2815 }
2799 if (rc) 2816 if (rc)
@@ -5335,8 +5352,23 @@ static int selinux_setprocattr(struct task_struct *p,
5335 } 5352 }
5336 error = security_context_to_sid(value, size, &sid); 5353 error = security_context_to_sid(value, size, &sid);
5337 if (error == -EINVAL && !strcmp(name, "fscreate")) { 5354 if (error == -EINVAL && !strcmp(name, "fscreate")) {
5338 if (!capable(CAP_MAC_ADMIN)) 5355 if (!capable(CAP_MAC_ADMIN)) {
5356 struct audit_buffer *ab;
5357 size_t audit_size;
5358
5359 /* We strip a nul only if it is at the end, otherwise the
5360 * context contains a nul and we should audit that */
5361 if (str[size - 1] == '\0')
5362 audit_size = size - 1;
5363 else
5364 audit_size = size;
5365 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
5366 audit_log_format(ab, "op=fscreate invalid_context=");
5367 audit_log_n_untrustedstring(ab, value, audit_size);
5368 audit_log_end(ab);
5369
5339 return error; 5370 return error;
5371 }
5340 error = security_context_to_sid_force(value, size, 5372 error = security_context_to_sid_force(value, size,
5341 &sid); 5373 &sid);
5342 } 5374 }