diff options
author | David Quigley <dpquigl@davequigley.com> | 2013-05-22 12:50:34 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2013-06-08 16:19:41 -0400 |
commit | d47be3dfecaf20255af89a57460285c82d5271ad (patch) | |
tree | 6427561f82a9bf90f17d748a865e3e0084919540 /security | |
parent | 4488cc96c581f130f3e86283d514123dce0dd46b (diff) |
Security: Add hook to calculate context based on a negative dentry.
There is a time where we need to calculate a context without the
inode having been created yet. To do this we take the negative dentry and
calculate a context based on the process and the parent directory contexts.
Acked-by: Eric Paris <eparis@redhat.com>
Acked-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Matthew N. Dodd <Matthew.Dodd@sparta.com>
Signed-off-by: Miguel Rodel Felipe <Rodel_FM@dsi.a-star.edu.sg>
Signed-off-by: Phua Eu Gene <PHUA_Eu_Gene@dsi.a-star.edu.sg>
Signed-off-by: Khin Mi Mi Aung <Mi_Mi_AUNG@dsi.a-star.edu.sg>
Signed-off-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/capability.c | 8 | ||||
-rw-r--r-- | security/security.c | 10 | ||||
-rw-r--r-- | security/selinux/hooks.c | 35 |
3 files changed, 53 insertions, 0 deletions
diff --git a/security/capability.c b/security/capability.c index 1728d4e375db..58578b4bdad4 100644 --- a/security/capability.c +++ b/security/capability.c | |||
@@ -109,6 +109,13 @@ static int cap_sb_parse_opts_str(char *options, struct security_mnt_opts *opts) | |||
109 | return 0; | 109 | return 0; |
110 | } | 110 | } |
111 | 111 | ||
112 | static int cap_dentry_init_security(struct dentry *dentry, int mode, | ||
113 | struct qstr *name, void **ctx, | ||
114 | u32 *ctxlen) | ||
115 | { | ||
116 | return 0; | ||
117 | } | ||
118 | |||
112 | static int cap_inode_alloc_security(struct inode *inode) | 119 | static int cap_inode_alloc_security(struct inode *inode) |
113 | { | 120 | { |
114 | return 0; | 121 | return 0; |
@@ -931,6 +938,7 @@ void __init security_fixup_ops(struct security_operations *ops) | |||
931 | set_to_cap_if_null(ops, sb_set_mnt_opts); | 938 | set_to_cap_if_null(ops, sb_set_mnt_opts); |
932 | set_to_cap_if_null(ops, sb_clone_mnt_opts); | 939 | set_to_cap_if_null(ops, sb_clone_mnt_opts); |
933 | set_to_cap_if_null(ops, sb_parse_opts_str); | 940 | set_to_cap_if_null(ops, sb_parse_opts_str); |
941 | set_to_cap_if_null(ops, dentry_init_security); | ||
934 | set_to_cap_if_null(ops, inode_alloc_security); | 942 | set_to_cap_if_null(ops, inode_alloc_security); |
935 | set_to_cap_if_null(ops, inode_free_security); | 943 | set_to_cap_if_null(ops, inode_free_security); |
936 | set_to_cap_if_null(ops, inode_init_security); | 944 | set_to_cap_if_null(ops, inode_init_security); |
diff --git a/security/security.c b/security/security.c index a3dce87d1aef..0fe2b2ee9545 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -12,6 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/capability.h> | 14 | #include <linux/capability.h> |
15 | #include <linux/dcache.h> | ||
15 | #include <linux/module.h> | 16 | #include <linux/module.h> |
16 | #include <linux/init.h> | 17 | #include <linux/init.h> |
17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
@@ -324,6 +325,15 @@ void security_inode_free(struct inode *inode) | |||
324 | security_ops->inode_free_security(inode); | 325 | security_ops->inode_free_security(inode); |
325 | } | 326 | } |
326 | 327 | ||
328 | int security_dentry_init_security(struct dentry *dentry, int mode, | ||
329 | struct qstr *name, void **ctx, | ||
330 | u32 *ctxlen) | ||
331 | { | ||
332 | return security_ops->dentry_init_security(dentry, mode, name, | ||
333 | ctx, ctxlen); | ||
334 | } | ||
335 | EXPORT_SYMBOL(security_dentry_init_security); | ||
336 | |||
327 | int security_inode_init_security(struct inode *inode, struct inode *dir, | 337 | int security_inode_init_security(struct inode *inode, struct inode *dir, |
328 | const struct qstr *qstr, | 338 | const struct qstr *qstr, |
329 | const initxattrs initxattrs, void *fs_data) | 339 | const initxattrs initxattrs, void *fs_data) |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 5c6f2cd2d095..b1f7bd727bd9 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -2515,6 +2515,40 @@ static void selinux_inode_free_security(struct inode *inode) | |||
2515 | inode_free_security(inode); | 2515 | inode_free_security(inode); |
2516 | } | 2516 | } |
2517 | 2517 | ||
2518 | static int selinux_dentry_init_security(struct dentry *dentry, int mode, | ||
2519 | struct qstr *name, void **ctx, | ||
2520 | u32 *ctxlen) | ||
2521 | { | ||
2522 | const struct cred *cred = current_cred(); | ||
2523 | struct task_security_struct *tsec; | ||
2524 | struct inode_security_struct *dsec; | ||
2525 | struct superblock_security_struct *sbsec; | ||
2526 | struct inode *dir = dentry->d_parent->d_inode; | ||
2527 | u32 newsid; | ||
2528 | int rc; | ||
2529 | |||
2530 | tsec = cred->security; | ||
2531 | dsec = dir->i_security; | ||
2532 | sbsec = dir->i_sb->s_security; | ||
2533 | |||
2534 | if (tsec->create_sid && sbsec->behavior != SECURITY_FS_USE_MNTPOINT) { | ||
2535 | newsid = tsec->create_sid; | ||
2536 | } else { | ||
2537 | rc = security_transition_sid(tsec->sid, dsec->sid, | ||
2538 | inode_mode_to_security_class(mode), | ||
2539 | name, | ||
2540 | &newsid); | ||
2541 | if (rc) { | ||
2542 | printk(KERN_WARNING | ||
2543 | "%s: security_transition_sid failed, rc=%d\n", | ||
2544 | __func__, -rc); | ||
2545 | return rc; | ||
2546 | } | ||
2547 | } | ||
2548 | |||
2549 | return security_sid_to_context(newsid, (char **)ctx, ctxlen); | ||
2550 | } | ||
2551 | |||
2518 | static int selinux_inode_init_security(struct inode *inode, struct inode *dir, | 2552 | static int selinux_inode_init_security(struct inode *inode, struct inode *dir, |
2519 | const struct qstr *qstr, char **name, | 2553 | const struct qstr *qstr, char **name, |
2520 | void **value, size_t *len) | 2554 | void **value, size_t *len) |
@@ -5562,6 +5596,7 @@ static struct security_operations selinux_ops = { | |||
5562 | .sb_clone_mnt_opts = selinux_sb_clone_mnt_opts, | 5596 | .sb_clone_mnt_opts = selinux_sb_clone_mnt_opts, |
5563 | .sb_parse_opts_str = selinux_parse_opts_str, | 5597 | .sb_parse_opts_str = selinux_parse_opts_str, |
5564 | 5598 | ||
5599 | .dentry_init_security = selinux_dentry_init_security, | ||
5565 | 5600 | ||
5566 | .inode_alloc_security = selinux_inode_alloc_security, | 5601 | .inode_alloc_security = selinux_inode_alloc_security, |
5567 | .inode_free_security = selinux_inode_free_security, | 5602 | .inode_free_security = selinux_inode_free_security, |