aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Quigley <dpquigl@davequigley.com>2013-05-22 12:50:34 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2013-06-08 16:19:41 -0400
commitd47be3dfecaf20255af89a57460285c82d5271ad (patch)
tree6427561f82a9bf90f17d748a865e3e0084919540
parent4488cc96c581f130f3e86283d514123dce0dd46b (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>
-rw-r--r--include/linux/security.h27
-rw-r--r--security/capability.c8
-rw-r--r--security/security.c10
-rw-r--r--security/selinux/hooks.c35
4 files changed, 80 insertions, 0 deletions
diff --git a/include/linux/security.h b/include/linux/security.h
index 4686491852a7..c2af46264ae0 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -26,6 +26,7 @@
26#include <linux/capability.h> 26#include <linux/capability.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/string.h>
29 30
30struct linux_binprm; 31struct linux_binprm;
31struct cred; 32struct cred;
@@ -306,6 +307,15 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
306 * Parse a string of security data filling in the opts structure 307 * Parse a string of security data filling in the opts structure
307 * @options string containing all mount options known by the LSM 308 * @options string containing all mount options known by the LSM
308 * @opts binary data structure usable by the LSM 309 * @opts binary data structure usable by the LSM
310 * @dentry_init_security:
311 * Compute a context for a dentry as the inode is not yet available
312 * since NFSv4 has no label backed by an EA anyway.
313 * @dentry dentry to use in calculating the context.
314 * @mode mode used to determine resource type.
315 * @name name of the last path component used to create file
316 * @ctx pointer to place the pointer to the resulting context in.
317 * @ctxlen point to place the length of the resulting context.
318 *
309 * 319 *
310 * Security hooks for inode operations. 320 * Security hooks for inode operations.
311 * 321 *
@@ -1443,6 +1453,10 @@ struct security_operations {
1443 int (*sb_clone_mnt_opts) (const struct super_block *oldsb, 1453 int (*sb_clone_mnt_opts) (const struct super_block *oldsb,
1444 struct super_block *newsb); 1454 struct super_block *newsb);
1445 int (*sb_parse_opts_str) (char *options, struct security_mnt_opts *opts); 1455 int (*sb_parse_opts_str) (char *options, struct security_mnt_opts *opts);
1456 int (*dentry_init_security) (struct dentry *dentry, int mode,
1457 struct qstr *name, void **ctx,
1458 u32 *ctxlen);
1459
1446 1460
1447#ifdef CONFIG_SECURITY_PATH 1461#ifdef CONFIG_SECURITY_PATH
1448 int (*path_unlink) (struct path *dir, struct dentry *dentry); 1462 int (*path_unlink) (struct path *dir, struct dentry *dentry);
@@ -1729,6 +1743,9 @@ int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *o
1729int security_sb_clone_mnt_opts(const struct super_block *oldsb, 1743int security_sb_clone_mnt_opts(const struct super_block *oldsb,
1730 struct super_block *newsb); 1744 struct super_block *newsb);
1731int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts); 1745int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
1746int security_dentry_init_security(struct dentry *dentry, int mode,
1747 struct qstr *name, void **ctx,
1748 u32 *ctxlen);
1732 1749
1733int security_inode_alloc(struct inode *inode); 1750int security_inode_alloc(struct inode *inode);
1734void security_inode_free(struct inode *inode); 1751void security_inode_free(struct inode *inode);
@@ -2035,6 +2052,16 @@ static inline int security_inode_alloc(struct inode *inode)
2035static inline void security_inode_free(struct inode *inode) 2052static inline void security_inode_free(struct inode *inode)
2036{ } 2053{ }
2037 2054
2055static inline int security_dentry_init_security(struct dentry *dentry,
2056 int mode,
2057 struct qstr *name,
2058 void **ctx,
2059 u32 *ctxlen)
2060{
2061 return -EOPNOTSUPP;
2062}
2063
2064
2038static inline int security_inode_init_security(struct inode *inode, 2065static inline int security_inode_init_security(struct inode *inode,
2039 struct inode *dir, 2066 struct inode *dir,
2040 const struct qstr *qstr, 2067 const struct qstr *qstr,
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
112static 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
112static int cap_inode_alloc_security(struct inode *inode) 119static 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
328int 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}
335EXPORT_SYMBOL(security_dentry_init_security);
336
327int security_inode_init_security(struct inode *inode, struct inode *dir, 337int 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
2518static 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
2518static int selinux_inode_init_security(struct inode *inode, struct inode *dir, 2552static 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,