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/selinux/hooks.c | |
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/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 35 |
1 files changed, 35 insertions, 0 deletions
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, |