summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2015-10-21 17:44:25 -0400
committerPaul Moore <pmoore@redhat.com>2015-10-21 17:44:25 -0400
commit44be2f65d979291ffb2a47112449507ffe1f9726 (patch)
tree9f3732d534de8425f6bf5d7519812263d0c292c9 /security
parent44d37ad3602b3823764eeb0f6c1ee3ef6c4fb936 (diff)
selinux: introduce security_context_str_to_sid
There seems to be a little confusion as to whether the scontext_len parameter of security_context_to_sid() includes the nul-byte or not. Reading security_context_to_sid_core(), it seems that the expectation is that it does not (both the string copying and the test for scontext_len being zero hint at that). Introduce the helper security_context_str_to_sid() to do the strlen() call and fix all callers. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <pmoore@redhat.com>
Diffstat (limited to 'security')
-rw-r--r--security/selinux/hooks.c12
-rw-r--r--security/selinux/include/security.h2
-rw-r--r--security/selinux/selinuxfs.c26
-rw-r--r--security/selinux/ss/services.c5
4 files changed, 20 insertions, 25 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 7cd71cea0503..9ed1b5dbcb39 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -674,10 +674,9 @@ static int selinux_set_mnt_opts(struct super_block *sb,
674 674
675 if (flags[i] == SBLABEL_MNT) 675 if (flags[i] == SBLABEL_MNT)
676 continue; 676 continue;
677 rc = security_context_to_sid(mount_options[i], 677 rc = security_context_str_to_sid(mount_options[i], &sid, GFP_KERNEL);
678 strlen(mount_options[i]), &sid, GFP_KERNEL);
679 if (rc) { 678 if (rc) {
680 printk(KERN_WARNING "SELinux: security_context_to_sid" 679 printk(KERN_WARNING "SELinux: security_context_str_to_sid"
681 "(%s) failed for (dev %s, type %s) errno=%d\n", 680 "(%s) failed for (dev %s, type %s) errno=%d\n",
682 mount_options[i], sb->s_id, name, rc); 681 mount_options[i], sb->s_id, name, rc);
683 goto out; 682 goto out;
@@ -2617,15 +2616,12 @@ static int selinux_sb_remount(struct super_block *sb, void *data)
2617 2616
2618 for (i = 0; i < opts.num_mnt_opts; i++) { 2617 for (i = 0; i < opts.num_mnt_opts; i++) {
2619 u32 sid; 2618 u32 sid;
2620 size_t len;
2621 2619
2622 if (flags[i] == SBLABEL_MNT) 2620 if (flags[i] == SBLABEL_MNT)
2623 continue; 2621 continue;
2624 len = strlen(mount_options[i]); 2622 rc = security_context_str_to_sid(mount_options[i], &sid, GFP_KERNEL);
2625 rc = security_context_to_sid(mount_options[i], len, &sid,
2626 GFP_KERNEL);
2627 if (rc) { 2623 if (rc) {
2628 printk(KERN_WARNING "SELinux: security_context_to_sid" 2624 printk(KERN_WARNING "SELinux: security_context_str_to_sid"
2629 "(%s) failed for (dev %s, type %s) errno=%d\n", 2625 "(%s) failed for (dev %s, type %s) errno=%d\n",
2630 mount_options[i], sb->s_id, sb->s_type->name, rc); 2626 mount_options[i], sb->s_id, sb->s_type->name, rc);
2631 goto out_free_opts; 2627 goto out_free_opts;
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index 6a681d26bf20..223e9fd15d66 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -166,6 +166,8 @@ int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
166int security_context_to_sid(const char *scontext, u32 scontext_len, 166int security_context_to_sid(const char *scontext, u32 scontext_len,
167 u32 *out_sid, gfp_t gfp); 167 u32 *out_sid, gfp_t gfp);
168 168
169int security_context_str_to_sid(const char *scontext, u32 *out_sid, gfp_t gfp);
170
169int security_context_to_sid_default(const char *scontext, u32 scontext_len, 171int security_context_to_sid_default(const char *scontext, u32 scontext_len,
170 u32 *out_sid, u32 def_sid, gfp_t gfp_flags); 172 u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
171 173
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 5bed7716f8ab..c02da25d7b63 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -731,13 +731,11 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
731 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) 731 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
732 goto out; 732 goto out;
733 733
734 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid, 734 length = security_context_str_to_sid(scon, &ssid, GFP_KERNEL);
735 GFP_KERNEL);
736 if (length) 735 if (length)
737 goto out; 736 goto out;
738 737
739 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid, 738 length = security_context_str_to_sid(tcon, &tsid, GFP_KERNEL);
740 GFP_KERNEL);
741 if (length) 739 if (length)
742 goto out; 740 goto out;
743 741
@@ -819,13 +817,11 @@ static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
819 objname = namebuf; 817 objname = namebuf;
820 } 818 }
821 819
822 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid, 820 length = security_context_str_to_sid(scon, &ssid, GFP_KERNEL);
823 GFP_KERNEL);
824 if (length) 821 if (length)
825 goto out; 822 goto out;
826 823
827 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid, 824 length = security_context_str_to_sid(tcon, &tsid, GFP_KERNEL);
828 GFP_KERNEL);
829 if (length) 825 if (length)
830 goto out; 826 goto out;
831 827
@@ -882,13 +878,11 @@ static ssize_t sel_write_relabel(struct file *file, char *buf, size_t size)
882 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) 878 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
883 goto out; 879 goto out;
884 880
885 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid, 881 length = security_context_str_to_sid(scon, &ssid, GFP_KERNEL);
886 GFP_KERNEL);
887 if (length) 882 if (length)
888 goto out; 883 goto out;
889 884
890 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid, 885 length = security_context_str_to_sid(tcon, &tsid, GFP_KERNEL);
891 GFP_KERNEL);
892 if (length) 886 if (length)
893 goto out; 887 goto out;
894 888
@@ -940,7 +934,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size)
940 if (sscanf(buf, "%s %s", con, user) != 2) 934 if (sscanf(buf, "%s %s", con, user) != 2)
941 goto out; 935 goto out;
942 936
943 length = security_context_to_sid(con, strlen(con) + 1, &sid, GFP_KERNEL); 937 length = security_context_str_to_sid(con, &sid, GFP_KERNEL);
944 if (length) 938 if (length)
945 goto out; 939 goto out;
946 940
@@ -1000,13 +994,11 @@ static ssize_t sel_write_member(struct file *file, char *buf, size_t size)
1000 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) 994 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
1001 goto out; 995 goto out;
1002 996
1003 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid, 997 length = security_context_str_to_sid(scon, &ssid, GFP_KERNEL);
1004 GFP_KERNEL);
1005 if (length) 998 if (length)
1006 goto out; 999 goto out;
1007 1000
1008 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid, 1001 length = security_context_str_to_sid(tcon, &tsid, GFP_KERNEL);
1009 GFP_KERNEL);
1010 if (length) 1002 if (length)
1011 goto out; 1003 goto out;
1012 1004
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index b7df12ba61d8..c550df0e0ff1 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1476,6 +1476,11 @@ int security_context_to_sid(const char *scontext, u32 scontext_len, u32 *sid,
1476 sid, SECSID_NULL, gfp, 0); 1476 sid, SECSID_NULL, gfp, 0);
1477} 1477}
1478 1478
1479int security_context_str_to_sid(const char *scontext, u32 *sid, gfp_t gfp)
1480{
1481 return security_context_to_sid(scontext, strlen(scontext), sid, gfp);
1482}
1483
1479/** 1484/**
1480 * security_context_to_sid_default - Obtain a SID for a given security context, 1485 * security_context_to_sid_default - Obtain a SID for a given security context,
1481 * falling back to specified default if needed. 1486 * falling back to specified default if needed.