diff options
author | James Morris <james.l.morris@oracle.com> | 2015-10-21 20:17:50 -0400 |
---|---|---|
committer | James Morris <james.l.morris@oracle.com> | 2015-10-21 20:17:50 -0400 |
commit | a47c7a6c8aff0563c0ef4adf299268f3c27af0f6 (patch) | |
tree | 0b9233d8daac506b094307683fe27edba0a1f00d /security/selinux/hooks.c | |
parent | 083c1290ca73666ce1b551cc89d080d060f02ad6 (diff) | |
parent | 63205654c0e05e5ffa1c6eef2fbef21dcabd2185 (diff) |
Merge branch 'upstream' of git://git.infradead.org/users/pcmoore/selinux into next
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index e4369d86e588..305399225010 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -126,6 +126,7 @@ int selinux_enabled = 1; | |||
126 | #endif | 126 | #endif |
127 | 127 | ||
128 | static struct kmem_cache *sel_inode_cache; | 128 | static struct kmem_cache *sel_inode_cache; |
129 | static struct kmem_cache *file_security_cache; | ||
129 | 130 | ||
130 | /** | 131 | /** |
131 | * selinux_secmark_enabled - Check to see if SECMARK is currently enabled | 132 | * selinux_secmark_enabled - Check to see if SECMARK is currently enabled |
@@ -287,7 +288,7 @@ static int file_alloc_security(struct file *file) | |||
287 | struct file_security_struct *fsec; | 288 | struct file_security_struct *fsec; |
288 | u32 sid = current_sid(); | 289 | u32 sid = current_sid(); |
289 | 290 | ||
290 | fsec = kzalloc(sizeof(struct file_security_struct), GFP_KERNEL); | 291 | fsec = kmem_cache_zalloc(file_security_cache, GFP_KERNEL); |
291 | if (!fsec) | 292 | if (!fsec) |
292 | return -ENOMEM; | 293 | return -ENOMEM; |
293 | 294 | ||
@@ -302,7 +303,7 @@ static void file_free_security(struct file *file) | |||
302 | { | 303 | { |
303 | struct file_security_struct *fsec = file->f_security; | 304 | struct file_security_struct *fsec = file->f_security; |
304 | file->f_security = NULL; | 305 | file->f_security = NULL; |
305 | kfree(fsec); | 306 | kmem_cache_free(file_security_cache, fsec); |
306 | } | 307 | } |
307 | 308 | ||
308 | static int superblock_alloc_security(struct super_block *sb) | 309 | static int superblock_alloc_security(struct super_block *sb) |
@@ -674,10 +675,9 @@ static int selinux_set_mnt_opts(struct super_block *sb, | |||
674 | 675 | ||
675 | if (flags[i] == SBLABEL_MNT) | 676 | if (flags[i] == SBLABEL_MNT) |
676 | continue; | 677 | continue; |
677 | rc = security_context_to_sid(mount_options[i], | 678 | rc = security_context_str_to_sid(mount_options[i], &sid, GFP_KERNEL); |
678 | strlen(mount_options[i]), &sid, GFP_KERNEL); | ||
679 | if (rc) { | 679 | if (rc) { |
680 | printk(KERN_WARNING "SELinux: security_context_to_sid" | 680 | printk(KERN_WARNING "SELinux: security_context_str_to_sid" |
681 | "(%s) failed for (dev %s, type %s) errno=%d\n", | 681 | "(%s) failed for (dev %s, type %s) errno=%d\n", |
682 | mount_options[i], sb->s_id, name, rc); | 682 | mount_options[i], sb->s_id, name, rc); |
683 | goto out; | 683 | goto out; |
@@ -2617,15 +2617,12 @@ static int selinux_sb_remount(struct super_block *sb, void *data) | |||
2617 | 2617 | ||
2618 | for (i = 0; i < opts.num_mnt_opts; i++) { | 2618 | for (i = 0; i < opts.num_mnt_opts; i++) { |
2619 | u32 sid; | 2619 | u32 sid; |
2620 | size_t len; | ||
2621 | 2620 | ||
2622 | if (flags[i] == SBLABEL_MNT) | 2621 | if (flags[i] == SBLABEL_MNT) |
2623 | continue; | 2622 | continue; |
2624 | len = strlen(mount_options[i]); | 2623 | 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) { | 2624 | if (rc) { |
2628 | printk(KERN_WARNING "SELinux: security_context_to_sid" | 2625 | printk(KERN_WARNING "SELinux: security_context_str_to_sid" |
2629 | "(%s) failed for (dev %s, type %s) errno=%d\n", | 2626 | "(%s) failed for (dev %s, type %s) errno=%d\n", |
2630 | mount_options[i], sb->s_id, sb->s_type->name, rc); | 2627 | mount_options[i], sb->s_id, sb->s_type->name, rc); |
2631 | goto out_free_opts; | 2628 | goto out_free_opts; |
@@ -2946,7 +2943,8 @@ static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr) | |||
2946 | ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET)) | 2943 | ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET)) |
2947 | return dentry_has_perm(cred, dentry, FILE__SETATTR); | 2944 | return dentry_has_perm(cred, dentry, FILE__SETATTR); |
2948 | 2945 | ||
2949 | if (selinux_policycap_openperm && (ia_valid & ATTR_SIZE)) | 2946 | if (selinux_policycap_openperm && (ia_valid & ATTR_SIZE) |
2947 | && !(ia_valid & ATTR_FILE)) | ||
2950 | av |= FILE__OPEN; | 2948 | av |= FILE__OPEN; |
2951 | 2949 | ||
2952 | return dentry_has_perm(cred, dentry, av); | 2950 | return dentry_has_perm(cred, dentry, av); |
@@ -3166,7 +3164,7 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name, | |||
3166 | if (!value || !size) | 3164 | if (!value || !size) |
3167 | return -EACCES; | 3165 | return -EACCES; |
3168 | 3166 | ||
3169 | rc = security_context_to_sid((void *)value, size, &newsid, GFP_KERNEL); | 3167 | rc = security_context_to_sid(value, size, &newsid, GFP_KERNEL); |
3170 | if (rc) | 3168 | if (rc) |
3171 | return rc; | 3169 | return rc; |
3172 | 3170 | ||
@@ -3238,7 +3236,7 @@ static void selinux_file_free_security(struct file *file) | |||
3238 | * Check whether a task has the ioctl permission and cmd | 3236 | * Check whether a task has the ioctl permission and cmd |
3239 | * operation to an inode. | 3237 | * operation to an inode. |
3240 | */ | 3238 | */ |
3241 | int ioctl_has_perm(const struct cred *cred, struct file *file, | 3239 | static int ioctl_has_perm(const struct cred *cred, struct file *file, |
3242 | u32 requested, u16 cmd) | 3240 | u32 requested, u16 cmd) |
3243 | { | 3241 | { |
3244 | struct common_audit_data ad; | 3242 | struct common_audit_data ad; |
@@ -6089,6 +6087,9 @@ static __init int selinux_init(void) | |||
6089 | sel_inode_cache = kmem_cache_create("selinux_inode_security", | 6087 | sel_inode_cache = kmem_cache_create("selinux_inode_security", |
6090 | sizeof(struct inode_security_struct), | 6088 | sizeof(struct inode_security_struct), |
6091 | 0, SLAB_PANIC, NULL); | 6089 | 0, SLAB_PANIC, NULL); |
6090 | file_security_cache = kmem_cache_create("selinux_file_security", | ||
6091 | sizeof(struct file_security_struct), | ||
6092 | 0, SLAB_PANIC, NULL); | ||
6092 | avc_init(); | 6093 | avc_init(); |
6093 | 6094 | ||
6094 | security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks)); | 6095 | security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks)); |