diff options
author | Vivek Goyal <vgoyal@redhat.com> | 2016-07-13 10:44:48 -0400 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2016-08-08 20:41:52 -0400 |
commit | 56909eb3f559103196ecbf2c08c923e0804980fb (patch) | |
tree | 5a0df1c21ea1acec5730298ef08df8b8d930cfe4 | |
parent | d8ad8b49618410ddeafd78465b63a6cedd6c9484 (diff) |
selinux: Implementation for inode_copy_up() hook
A file is being copied up for overlay file system. Prepare a new set of
creds and set create_sid appropriately so that new file is created with
appropriate label.
Overlay inode has right label for both context and non-context mount
cases. In case of non-context mount, overlay inode will have the label
of lower file and in case of context mount, overlay inode will have
the label from context= mount option.
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <paul@paul-moore.com>
-rw-r--r-- | security/selinux/hooks.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 880f9533863f..40597ed00ba9 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -3293,6 +3293,26 @@ static void selinux_inode_getsecid(struct inode *inode, u32 *secid) | |||
3293 | *secid = isec->sid; | 3293 | *secid = isec->sid; |
3294 | } | 3294 | } |
3295 | 3295 | ||
3296 | static int selinux_inode_copy_up(struct dentry *src, struct cred **new) | ||
3297 | { | ||
3298 | u32 sid; | ||
3299 | struct task_security_struct *tsec; | ||
3300 | struct cred *new_creds = *new; | ||
3301 | |||
3302 | if (new_creds == NULL) { | ||
3303 | new_creds = prepare_creds(); | ||
3304 | if (!new_creds) | ||
3305 | return -ENOMEM; | ||
3306 | } | ||
3307 | |||
3308 | tsec = new_creds->security; | ||
3309 | /* Get label from overlay inode and set it in create_sid */ | ||
3310 | selinux_inode_getsecid(d_inode(src), &sid); | ||
3311 | tsec->create_sid = sid; | ||
3312 | *new = new_creds; | ||
3313 | return 0; | ||
3314 | } | ||
3315 | |||
3296 | /* file security operations */ | 3316 | /* file security operations */ |
3297 | 3317 | ||
3298 | static int selinux_revalidate_file_permission(struct file *file, int mask) | 3318 | static int selinux_revalidate_file_permission(struct file *file, int mask) |
@@ -6088,6 +6108,7 @@ static struct security_hook_list selinux_hooks[] = { | |||
6088 | LSM_HOOK_INIT(inode_setsecurity, selinux_inode_setsecurity), | 6108 | LSM_HOOK_INIT(inode_setsecurity, selinux_inode_setsecurity), |
6089 | LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity), | 6109 | LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity), |
6090 | LSM_HOOK_INIT(inode_getsecid, selinux_inode_getsecid), | 6110 | LSM_HOOK_INIT(inode_getsecid, selinux_inode_getsecid), |
6111 | LSM_HOOK_INIT(inode_copy_up, selinux_inode_copy_up), | ||
6091 | 6112 | ||
6092 | LSM_HOOK_INIT(file_permission, selinux_file_permission), | 6113 | LSM_HOOK_INIT(file_permission, selinux_file_permission), |
6093 | LSM_HOOK_INIT(file_alloc_security, selinux_file_alloc_security), | 6114 | LSM_HOOK_INIT(file_alloc_security, selinux_file_alloc_security), |