ANDROID: Sdcardfs: Move gid derivation under flag
authorDaniel Rosenberg <drosen@google.com>
Thu, 20 Jul 2017 00:25:07 +0000 (17:25 -0700)
committerStricted <info@stricted.net>
Thu, 11 Oct 2018 16:03:44 +0000 (18:03 +0200)
This moves the code to adjust the gid/uid of lower filesystem
files under the mount flag derive_gid.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: I44eaad4ef67c7fcfda3b6ea3502afab94442610c
Bug: 63245673

fs/sdcardfs/derived_perm.c
fs/sdcardfs/inode.c
fs/sdcardfs/main.c
fs/sdcardfs/sdcardfs.h
fs/sdcardfs/super.c

index 64f188f84887b861d47b8aa3398e01150758c1d6..75beeff149f0b784b67ddc1f40bbb14e944302f9 100644 (file)
@@ -175,6 +175,9 @@ void fixup_lower_ownership(struct dentry *dentry, const char *name)
        gid_t gid = sbi->options.fs_low_gid;
        struct iattr newattrs;
 
+       if (!sbi->options.gid_derivation)
+               return;
+
        info = SDCARDFS_I(dentry->d_inode);
        info_d = info->data;
        perm = info_d->perm;
index 030210ac8e10d77dbeee32c8926f560f392de86e..c7fe86f89caf2893b30d85bcffe71cde8642ae8b 100644 (file)
@@ -34,10 +34,14 @@ const struct cred *override_fsids(struct sdcardfs_sb_info *sbi,
        if (!cred)
                return NULL;
 
-       if (data->under_obb)
-               uid = AID_MEDIA_OBB;
-       else
-               uid = multiuser_get_uid(data->userid, sbi->options.fs_low_uid);
+       if (sbi->options.gid_derivation) {
+               if (data->under_obb)
+                       uid = AID_MEDIA_OBB;
+               else
+                       uid = multiuser_get_uid(data->userid, sbi->options.fs_low_uid);
+       } else {
+               uid = sbi->options.fs_low_uid;
+       }
        cred->fsuid = uid;
        cred->fsgid = sbi->options.fs_low_gid;
 
index 6c6904e8618816adf8702fecf76cc344a3517300..c2761cdaf28ca0ed0c88a57faf0f0590cc9da996 100644 (file)
@@ -32,6 +32,7 @@ enum {
        Opt_multiuser,
        Opt_userid,
        Opt_reserved_mb,
+       Opt_gid_derivation,
        Opt_err,
 };
 
@@ -43,6 +44,7 @@ static const match_table_t sdcardfs_tokens = {
        {Opt_mask, "mask=%u"},
        {Opt_userid, "userid=%d"},
        {Opt_multiuser, "multiuser"},
+       {Opt_gid_derivation, "derive_gid"},
        {Opt_reserved_mb, "reserved_mb=%u"},
        {Opt_err, NULL}
 };
@@ -64,6 +66,8 @@ static int parse_options(struct super_block *sb, char *options, int silent,
        vfsopts->gid = 0;
        /* by default, 0MB is reserved */
        opts->reserved_mb = 0;
+       /* by default, gid derivation is off */
+       opts->gid_derivation = false;
 
        *debug = 0;
 
@@ -115,6 +119,8 @@ static int parse_options(struct super_block *sb, char *options, int silent,
                                return 0;
                        opts->reserved_mb = option;
                        break;
+               case Opt_gid_derivation:
+                       opts->gid_derivation = true;
                /* unknown option */
                default:
                        if (!silent)
index 63c3bd329105b65da2e5072b9652057f6916b9c2..f3c283759cb3077048f1469aded1d56b2fae974a 100644 (file)
@@ -218,6 +218,7 @@ struct sdcardfs_mount_options {
        gid_t fs_low_gid;
        userid_t fs_user_id;
        bool multiuser;
+       bool gid_derivation;
        unsigned int reserved_mb;
 };
 
index eb3ebb454a3ede6fb2464487f743fb17611d0e04..fa9aa52e6e06d8ef9b4a9041abd9cb0d88b4b8f0 100644 (file)
@@ -302,6 +302,8 @@ static int sdcardfs_show_options(struct vfsmount *mnt, struct seq_file *m,
                seq_printf(m, ",mask=%u", vfsopts->mask);
        if (opts->fs_user_id)
                seq_printf(m, ",userid=%u", opts->fs_user_id);
+       if (opts->gid_derivation)
+               seq_puts(m, ",derive_gid");
        if (opts->reserved_mb != 0)
                seq_printf(m, ",reserved=%uMB", opts->reserved_mb);