ANDROID: Sdcardfs: Move gid derivation under flag

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
This commit is contained in:
Daniel Rosenberg 2017-07-19 17:25:07 -07:00 committed by Amit Pundir
parent 980ab18fbd
commit 95c3511a98
5 changed files with 21 additions and 4 deletions

View file

@ -176,6 +176,9 @@ void fixup_lower_ownership(struct dentry *dentry, const char *name)
gid_t gid = sbi->options.fs_low_gid; gid_t gid = sbi->options.fs_low_gid;
struct iattr newattrs; struct iattr newattrs;
if (!sbi->options.gid_derivation)
return;
info = SDCARDFS_I(d_inode(dentry)); info = SDCARDFS_I(d_inode(dentry));
info_d = info->data; info_d = info->data;
perm = info_d->perm; perm = info_d->perm;

View file

@ -34,10 +34,14 @@ const struct cred *override_fsids(struct sdcardfs_sb_info *sbi,
if (!cred) if (!cred)
return NULL; return NULL;
if (data->under_obb) if (sbi->options.gid_derivation) {
uid = AID_MEDIA_OBB; if (data->under_obb)
else uid = AID_MEDIA_OBB;
uid = multiuser_get_uid(data->userid, sbi->options.fs_low_uid); else
uid = multiuser_get_uid(data->userid, sbi->options.fs_low_uid);
} else {
uid = sbi->options.fs_low_uid;
}
cred->fsuid = make_kuid(&init_user_ns, uid); cred->fsuid = make_kuid(&init_user_ns, uid);
cred->fsgid = make_kgid(&init_user_ns, sbi->options.fs_low_gid); cred->fsgid = make_kgid(&init_user_ns, sbi->options.fs_low_gid);

View file

@ -32,6 +32,7 @@ enum {
Opt_multiuser, Opt_multiuser,
Opt_userid, Opt_userid,
Opt_reserved_mb, Opt_reserved_mb,
Opt_gid_derivation,
Opt_err, Opt_err,
}; };
@ -43,6 +44,7 @@ static const match_table_t sdcardfs_tokens = {
{Opt_mask, "mask=%u"}, {Opt_mask, "mask=%u"},
{Opt_userid, "userid=%d"}, {Opt_userid, "userid=%d"},
{Opt_multiuser, "multiuser"}, {Opt_multiuser, "multiuser"},
{Opt_gid_derivation, "derive_gid"},
{Opt_reserved_mb, "reserved_mb=%u"}, {Opt_reserved_mb, "reserved_mb=%u"},
{Opt_err, NULL} {Opt_err, NULL}
}; };
@ -64,6 +66,8 @@ static int parse_options(struct super_block *sb, char *options, int silent,
vfsopts->gid = 0; vfsopts->gid = 0;
/* by default, 0MB is reserved */ /* by default, 0MB is reserved */
opts->reserved_mb = 0; opts->reserved_mb = 0;
/* by default, gid derivation is off */
opts->gid_derivation = false;
*debug = 0; *debug = 0;
@ -115,6 +119,9 @@ static int parse_options(struct super_block *sb, char *options, int silent,
return 0; return 0;
opts->reserved_mb = option; opts->reserved_mb = option;
break; break;
case Opt_gid_derivation:
opts->gid_derivation = true;
break;
/* unknown option */ /* unknown option */
default: default:
if (!silent) if (!silent)

View file

@ -219,6 +219,7 @@ struct sdcardfs_mount_options {
gid_t fs_low_gid; gid_t fs_low_gid;
userid_t fs_user_id; userid_t fs_user_id;
bool multiuser; bool multiuser;
bool gid_derivation;
unsigned int reserved_mb; unsigned int reserved_mb;
}; };

View file

@ -302,6 +302,8 @@ static int sdcardfs_show_options(struct vfsmount *mnt, struct seq_file *m,
seq_printf(m, ",mask=%u", vfsopts->mask); seq_printf(m, ",mask=%u", vfsopts->mask);
if (opts->fs_user_id) if (opts->fs_user_id)
seq_printf(m, ",userid=%u", 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) if (opts->reserved_mb != 0)
seq_printf(m, ",reserved=%uMB", opts->reserved_mb); seq_printf(m, ",reserved=%uMB", opts->reserved_mb);