]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selinux: Implement dentry_create_files_as() hook
authorVivek Goyal <vgoyal@redhat.com>
Wed, 13 Jul 2016 14:44:53 +0000 (10:44 -0400)
committerAnand Jain <anand.jain@oracle.com>
Thu, 26 Oct 2017 08:15:29 +0000 (16:15 +0800)
Calculate what would be the label of newly created file and set that
secid in the passed creds.

Context of the task which is actually creating file is retrieved from
set of creds passed in. (old->security).

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>
Orabug: 25684456

(backport upstream commit a518b0a5b0d7f3397e065acb956bca9635aa892d)

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Acked-by: James Morris <james.l.morris@oracle.com>
Reviewed-by: James Morris <james.l.morris@oracle.com>
Conflict fix:
     security/selinux/hooks.c

security/selinux/hooks.c

index 6a9513fcabc5a7aa625e0a1799980156c89118f2..a3d06b3f4dbed61c1c8ae12dac6187f1568c82c2 100644 (file)
@@ -2777,6 +2777,27 @@ static int selinux_dentry_init_security(struct dentry *dentry, int mode,
        return security_sid_to_context(newsid, (char **)ctx, ctxlen);
 }
 
+static int selinux_dentry_create_files_as(struct dentry *dentry, int mode,
+                                         struct qstr *name,
+                                         const struct cred *old,
+                                         struct cred *new)
+{
+       u32 newsid;
+       int rc;
+       struct task_security_struct *tsec;
+
+       rc = selinux_determine_inode_label(old->security,
+                                          d_inode(dentry->d_parent), name,
+                                          inode_mode_to_security_class(mode),
+                                          &newsid);
+       if (rc)
+               return rc;
+
+       tsec = new->security;
+       tsec->create_sid = newsid;
+       return 0;
+}
+
 static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
                                       const struct qstr *qstr,
                                       const char **name,
@@ -5932,6 +5953,7 @@ static struct security_operations selinux_ops = {
        .sb_parse_opts_str =            selinux_parse_opts_str,
 
        .dentry_init_security =         selinux_dentry_init_security,
+       .dentry_create_files_as =       selinux_dentry_create_files_as,
 
        .inode_alloc_security =         selinux_inode_alloc_security,
        .inode_free_security =          selinux_inode_free_security,