smack: introduce a special case for tmpfs in smack_d_instantiate()
authorŁukasz Stelmach <l.stelmach@samsung.com>
Wed, 10 Dec 2014 06:29:46 +0000 (07:29 +0100)
committerChanho Park <parkch98@gmail.com>
Fri, 23 Jan 2015 14:27:20 +0000 (23:27 +0900)
Files created with __shmem_file_stup() appear to have somewhat fake
dentries which make them look like root directories and not get
the label the current process or ("*") star meant for tmpfs files.

Change-Id: If0e2e3ceddeff55d5121e76e85dbea60414b786a
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
security/smack/smack_lsm.c

index cdbf92b34e7e5e4a71da850b39b0e18f63d00a94..96b9884258578c81bf49f63e1fe9e724d0ee85b6 100644 (file)
@@ -2724,7 +2724,8 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
         * of the superblock.
         */
        if (opt_dentry->d_parent == opt_dentry) {
-               if (sbp->s_magic == CGROUP_SUPER_MAGIC) {
+               switch (sbp->s_magic) {
+               case CGROUP_SUPER_MAGIC:
                        /*
                         * The cgroup filesystem is never mounted,
                         * so there's no opportunity to set the mount
@@ -2732,8 +2733,19 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
                         */
                        sbsp->smk_root = smack_known_star.smk_known;
                        sbsp->smk_default = smack_known_star.smk_known;
+                       isp->smk_inode = sbsp->smk_root;
+                       break;
+               case TMPFS_MAGIC:
+                       /*
+                        * What about shmem/tmpfs anonymous files with dentry
+                        * obtained from d_alloc_pseudo()?
+                        */
+                       isp->smk_inode = smk_of_current();
+                       break;
+               default:
+                       isp->smk_inode = sbsp->smk_root;
+                       break;
                }
-               isp->smk_inode = sbsp->smk_root;
                isp->smk_flags |= SMK_INODE_INSTANT;
                goto unlockandout;
        }