summaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
authorCasey Schaufler <casey@schaufler-ca.com>2018-11-12 15:02:49 -0500
committerKees Cook <keescook@chromium.org>2019-01-08 16:18:44 -0500
commit33bf60cabcc7687b194a689b068b65e9ecd556be (patch)
treef8bbf4c27ce73e33ab5f1efa7e99448ab9755373 /security/selinux
parentf28952ac900822a189fc383a5b73631e72c69356 (diff)
LSM: Infrastructure management of the file security
Move management of the file->f_security blob out of the individual security modules and into the infrastructure. The modules no longer allocate or free the data, instead they tell the infrastructure how much space they require. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Kees Cook <keescook@chromium.org> [kees: adjusted for ordered init series] Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/hooks.c25
-rw-r--r--security/selinux/include/objsec.h2
2 files changed, 3 insertions, 24 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 620be0367c0b..632813821da6 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -146,7 +146,6 @@ static int __init checkreqprot_setup(char *str)
146__setup("checkreqprot=", checkreqprot_setup); 146__setup("checkreqprot=", checkreqprot_setup);
147 147
148static struct kmem_cache *sel_inode_cache; 148static struct kmem_cache *sel_inode_cache;
149static struct kmem_cache *file_security_cache;
150 149
151/** 150/**
152 * selinux_secmark_enabled - Check to see if SECMARK is currently enabled 151 * selinux_secmark_enabled - Check to see if SECMARK is currently enabled
@@ -378,27 +377,15 @@ static void inode_free_security(struct inode *inode)
378 377
379static int file_alloc_security(struct file *file) 378static int file_alloc_security(struct file *file)
380{ 379{
381 struct file_security_struct *fsec; 380 struct file_security_struct *fsec = selinux_file(file);
382 u32 sid = current_sid(); 381 u32 sid = current_sid();
383 382
384 fsec = kmem_cache_zalloc(file_security_cache, GFP_KERNEL);
385 if (!fsec)
386 return -ENOMEM;
387
388 fsec->sid = sid; 383 fsec->sid = sid;
389 fsec->fown_sid = sid; 384 fsec->fown_sid = sid;
390 file->f_security = fsec;
391 385
392 return 0; 386 return 0;
393} 387}
394 388
395static void file_free_security(struct file *file)
396{
397 struct file_security_struct *fsec = selinux_file(file);
398 file->f_security = NULL;
399 kmem_cache_free(file_security_cache, fsec);
400}
401
402static int superblock_alloc_security(struct super_block *sb) 389static int superblock_alloc_security(struct super_block *sb)
403{ 390{
404 struct superblock_security_struct *sbsec; 391 struct superblock_security_struct *sbsec;
@@ -3345,11 +3332,6 @@ static int selinux_file_alloc_security(struct file *file)
3345 return file_alloc_security(file); 3332 return file_alloc_security(file);
3346} 3333}
3347 3334
3348static void selinux_file_free_security(struct file *file)
3349{
3350 file_free_security(file);
3351}
3352
3353/* 3335/*
3354 * Check whether a task has the ioctl permission and cmd 3336 * Check whether a task has the ioctl permission and cmd
3355 * operation to an inode. 3337 * operation to an inode.
@@ -6646,6 +6628,7 @@ static void selinux_bpf_prog_free(struct bpf_prog_aux *aux)
6646 6628
6647struct lsm_blob_sizes selinux_blob_sizes __lsm_ro_after_init = { 6629struct lsm_blob_sizes selinux_blob_sizes __lsm_ro_after_init = {
6648 .lbs_cred = sizeof(struct task_security_struct), 6630 .lbs_cred = sizeof(struct task_security_struct),
6631 .lbs_file = sizeof(struct file_security_struct),
6649}; 6632};
6650 6633
6651static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { 6634static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
@@ -6717,7 +6700,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
6717 6700
6718 LSM_HOOK_INIT(file_permission, selinux_file_permission), 6701 LSM_HOOK_INIT(file_permission, selinux_file_permission),
6719 LSM_HOOK_INIT(file_alloc_security, selinux_file_alloc_security), 6702 LSM_HOOK_INIT(file_alloc_security, selinux_file_alloc_security),
6720 LSM_HOOK_INIT(file_free_security, selinux_file_free_security),
6721 LSM_HOOK_INIT(file_ioctl, selinux_file_ioctl), 6703 LSM_HOOK_INIT(file_ioctl, selinux_file_ioctl),
6722 LSM_HOOK_INIT(mmap_file, selinux_mmap_file), 6704 LSM_HOOK_INIT(mmap_file, selinux_mmap_file),
6723 LSM_HOOK_INIT(mmap_addr, selinux_mmap_addr), 6705 LSM_HOOK_INIT(mmap_addr, selinux_mmap_addr),
@@ -6902,9 +6884,6 @@ static __init int selinux_init(void)
6902 sel_inode_cache = kmem_cache_create("selinux_inode_security", 6884 sel_inode_cache = kmem_cache_create("selinux_inode_security",
6903 sizeof(struct inode_security_struct), 6885 sizeof(struct inode_security_struct),
6904 0, SLAB_PANIC, NULL); 6886 0, SLAB_PANIC, NULL);
6905 file_security_cache = kmem_cache_create("selinux_file_security",
6906 sizeof(struct file_security_struct),
6907 0, SLAB_PANIC, NULL);
6908 avc_init(); 6887 avc_init();
6909 6888
6910 avtab_cache_init(); 6889 avtab_cache_init();
diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h
index e0ac2992e059..96374dbf4ace 100644
--- a/security/selinux/include/objsec.h
+++ b/security/selinux/include/objsec.h
@@ -167,7 +167,7 @@ static inline struct task_security_struct *selinux_cred(const struct cred *cred)
167 167
168static inline struct file_security_struct *selinux_file(const struct file *file) 168static inline struct file_security_struct *selinux_file(const struct file *file)
169{ 169{
170 return file->f_security; 170 return file->f_security + selinux_blob_sizes.lbs_file;
171} 171}
172 172
173#endif /* _SELINUX_OBJSEC_H_ */ 173#endif /* _SELINUX_OBJSEC_H_ */