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)
committerSooyoung Ha <yoosah.ha@samsung.com>
Tue, 23 Feb 2016 09:27:26 +0000 (18: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: Id97004f2a5090cee9c16778109d849d433bd39c9
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
(cherry picked from commit 7141e6be730e637255b1c75789ca67d309cbce95)
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
security/smack/smack_lsm.c

index 716ab8e9a272140834df93e3006de2dc93165cd8..c3db9d3edff10acc71793599024a4e6ce766ee38 100644 (file)
@@ -3070,7 +3070,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
@@ -3078,8 +3079,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()->smk_known;
+                       break;
+               default:
+                       isp->smk_inode = sbsp->smk_root;
+                       break;
                }
-               isp->smk_inode = sbsp->smk_root;
                isp->smk_flags |= SMK_INODE_INSTANT;
                goto unlockandout;
        }