BACKPORT: smack: introduce a special case for tmpfs in smack_d_instantiate()
authorŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 16 Dec 2014 15:53:08 +0000 (16:53 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 30 Jun 2016 12:57:43 +0000 (14:57 +0200)
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.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
(cherry-picked from upstream 1d8c2326a4a2a4d942f9165b5702fe6f869ccf48)

security/smack/smack_lsm.c

index fbfd3aa6f71a1d9958c949a9fe9906eec5e5d8db..3935c28dfdffd5a785f92db4d53980ba12b76fe9 100644 (file)
@@ -3052,7 +3052,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
@@ -3060,8 +3061,19 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
                         */
                        sbsp->smk_root = &smack_known_star;
                        sbsp->smk_default = &smack_known_star;
+                       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;
        }