aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/selinuxfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux/selinuxfs.c')
-rw-r--r--security/selinux/selinuxfs.c47
1 files changed, 11 insertions, 36 deletions
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index d7018bfa1f00..3ad290251288 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -496,6 +496,7 @@ static const struct file_operations sel_policy_ops = {
496 .read = sel_read_policy, 496 .read = sel_read_policy,
497 .mmap = sel_mmap_policy, 497 .mmap = sel_mmap_policy,
498 .release = sel_release_policy, 498 .release = sel_release_policy,
499 .llseek = generic_file_llseek,
499}; 500};
500 501
501static ssize_t sel_write_load(struct file *file, const char __user *buf, 502static ssize_t sel_write_load(struct file *file, const char __user *buf,
@@ -1232,6 +1233,7 @@ static int sel_make_bools(void)
1232 kfree(bool_pending_names[i]); 1233 kfree(bool_pending_names[i]);
1233 kfree(bool_pending_names); 1234 kfree(bool_pending_names);
1234 kfree(bool_pending_values); 1235 kfree(bool_pending_values);
1236 bool_num = 0;
1235 bool_pending_names = NULL; 1237 bool_pending_names = NULL;
1236 bool_pending_values = NULL; 1238 bool_pending_values = NULL;
1237 1239
@@ -1257,12 +1259,8 @@ static int sel_make_bools(void)
1257 if (!inode) 1259 if (!inode)
1258 goto out; 1260 goto out;
1259 1261
1260 ret = -EINVAL;
1261 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
1262 if (len < 0)
1263 goto out;
1264
1265 ret = -ENAMETOOLONG; 1262 ret = -ENAMETOOLONG;
1263 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
1266 if (len >= PAGE_SIZE) 1264 if (len >= PAGE_SIZE)
1267 goto out; 1265 goto out;
1268 1266
@@ -1532,11 +1530,6 @@ static int sel_make_initcon_files(struct dentry *dir)
1532 return 0; 1530 return 0;
1533} 1531}
1534 1532
1535static inline unsigned int sel_div(unsigned long a, unsigned long b)
1536{
1537 return a / b - (a % b < 0);
1538}
1539
1540static inline unsigned long sel_class_to_ino(u16 class) 1533static inline unsigned long sel_class_to_ino(u16 class)
1541{ 1534{
1542 return (class * (SEL_VEC_MAX + 1)) | SEL_CLASS_INO_OFFSET; 1535 return (class * (SEL_VEC_MAX + 1)) | SEL_CLASS_INO_OFFSET;
@@ -1544,7 +1537,7 @@ static inline unsigned long sel_class_to_ino(u16 class)
1544 1537
1545static inline u16 sel_ino_to_class(unsigned long ino) 1538static inline u16 sel_ino_to_class(unsigned long ino)
1546{ 1539{
1547 return sel_div(ino & SEL_INO_MASK, SEL_VEC_MAX + 1); 1540 return (ino & SEL_INO_MASK) / (SEL_VEC_MAX + 1);
1548} 1541}
1549 1542
1550static inline unsigned long sel_perm_to_ino(u16 class, u32 perm) 1543static inline unsigned long sel_perm_to_ino(u16 class, u32 perm)
@@ -1560,19 +1553,10 @@ static inline u32 sel_ino_to_perm(unsigned long ino)
1560static ssize_t sel_read_class(struct file *file, char __user *buf, 1553static ssize_t sel_read_class(struct file *file, char __user *buf,
1561 size_t count, loff_t *ppos) 1554 size_t count, loff_t *ppos)
1562{ 1555{
1563 ssize_t rc, len;
1564 char *page;
1565 unsigned long ino = file->f_path.dentry->d_inode->i_ino; 1556 unsigned long ino = file->f_path.dentry->d_inode->i_ino;
1566 1557 char res[TMPBUFLEN];
1567 page = (char *)__get_free_page(GFP_KERNEL); 1558 ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
1568 if (!page) 1559 return simple_read_from_buffer(buf, count, ppos, res, len);
1569 return -ENOMEM;
1570
1571 len = snprintf(page, PAGE_SIZE, "%d", sel_ino_to_class(ino));
1572 rc = simple_read_from_buffer(buf, count, ppos, page, len);
1573 free_page((unsigned long)page);
1574
1575 return rc;
1576} 1560}
1577 1561
1578static const struct file_operations sel_class_ops = { 1562static const struct file_operations sel_class_ops = {
@@ -1583,19 +1567,10 @@ static const struct file_operations sel_class_ops = {
1583static ssize_t sel_read_perm(struct file *file, char __user *buf, 1567static ssize_t sel_read_perm(struct file *file, char __user *buf,
1584 size_t count, loff_t *ppos) 1568 size_t count, loff_t *ppos)
1585{ 1569{
1586 ssize_t rc, len;
1587 char *page;
1588 unsigned long ino = file->f_path.dentry->d_inode->i_ino; 1570 unsigned long ino = file->f_path.dentry->d_inode->i_ino;
1589 1571 char res[TMPBUFLEN];
1590 page = (char *)__get_free_page(GFP_KERNEL); 1572 ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));
1591 if (!page) 1573 return simple_read_from_buffer(buf, count, ppos, res, len);
1592 return -ENOMEM;
1593
1594 len = snprintf(page, PAGE_SIZE, "%d", sel_ino_to_perm(ino));
1595 rc = simple_read_from_buffer(buf, count, ppos, page, len);
1596 free_page((unsigned long)page);
1597
1598 return rc;
1599} 1574}
1600 1575
1601static const struct file_operations sel_perm_ops = { 1576static const struct file_operations sel_perm_ops = {
@@ -1831,7 +1806,7 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent)
1831 [SEL_REJECT_UNKNOWN] = {"reject_unknown", &sel_handle_unknown_ops, S_IRUGO}, 1806 [SEL_REJECT_UNKNOWN] = {"reject_unknown", &sel_handle_unknown_ops, S_IRUGO},
1832 [SEL_DENY_UNKNOWN] = {"deny_unknown", &sel_handle_unknown_ops, S_IRUGO}, 1807 [SEL_DENY_UNKNOWN] = {"deny_unknown", &sel_handle_unknown_ops, S_IRUGO},
1833 [SEL_STATUS] = {"status", &sel_handle_status_ops, S_IRUGO}, 1808 [SEL_STATUS] = {"status", &sel_handle_status_ops, S_IRUGO},
1834 [SEL_POLICY] = {"policy", &sel_policy_ops, S_IRUSR}, 1809 [SEL_POLICY] = {"policy", &sel_policy_ops, S_IRUGO},
1835 /* last one */ {""} 1810 /* last one */ {""}
1836 }; 1811 };
1837 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files); 1812 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);