BACKPORT: smack: parse mnt opts after privileges check
authorHimanshu Shukla <himanshu.sh@samsung.com>
Thu, 10 Nov 2016 10:49:52 +0000 (16:19 +0530)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 21 Nov 2016 16:04:23 +0000 (17:04 +0100)
In smack_set_mnt_opts()first the SMACK mount options are being
parsed and later it is being checked whether the user calling
mount has CAP_MAC_ADMIN capability.
This sequence of operationis will allow unauthorized user to add
SMACK labels in label list and may cause denial of security attack
by adding many labels by allocating kernel memory by unauthorized user.
Superblock smack flag is also being set as initialized though function
may return with EPERM error.
First check the capability of calling user then set the SMACK attributes
and smk_flags.

Signed-off-by: Himanshu Shukla <himanshu.sh@samsung.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
(cherry-picked from upstream 2097f59920ea81516d7783396683cad22c26d140)

security/smack/smack_lsm.c

index 2c3d060c98a2e0cf847fae9f97c6e20767a84695..21ff5fa772fbe3ed4d6d69af94de15a690c44ca1 100644 (file)
@@ -765,6 +765,20 @@ static int smack_set_mnt_opts(struct super_block *sb,
        if (sp->smk_initialized)
                return 0;
 
+       if (!smack_privileged(CAP_MAC_ADMIN)) {
+               /*
+                * Unprivileged mounts don't get to specify Smack values.
+                */
+               if (num_opts)
+                       return -EPERM;
+               /*
+                * Unprivileged mounts get root and default from the caller.
+                */
+               skp = smk_of_current();
+               sp->smk_root = skp;
+               sp->smk_default = skp;
+       }
+
        sp->smk_initialized = 1;
 
        for (i = 0; i < num_opts; i++) {
@@ -805,20 +819,6 @@ static int smack_set_mnt_opts(struct super_block *sb,
                }
        }
 
-       if (!smack_privileged(CAP_MAC_ADMIN)) {
-               /*
-                * Unprivileged mounts don't get to specify Smack values.
-                */
-               if (num_opts)
-                       return -EPERM;
-               /*
-                * Unprivileged mounts get root and default from the caller.
-                */
-               skp = smk_of_current();
-               sp->smk_root = skp;
-               sp->smk_default = skp;
-       }
-
        /*
         * Initialize the root inode.
         */