summaryrefslogtreecommitdiffstats
path: root/sdcard
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2017-09-06 15:22:54 -0700
committerDaniel Rosenberg <drosen@google.com>2017-09-20 16:04:50 -0700
commitb7c118522f300cea3bc4044ff42e825ca5ed3ee2 (patch)
treeeefa1486775c2bc8f72f3fd9f865cad68113c4f1 /sdcard
parent2dd3b6e349a73d2d8871b2827cd99a60c4f913f5 (diff)
downloadsystem_core-b7c118522f300cea3bc4044ff42e825ca5ed3ee2.tar.gz
system_core-b7c118522f300cea3bc4044ff42e825ca5ed3ee2.tar.bz2
system_core-b7c118522f300cea3bc4044ff42e825ca5ed3ee2.zip
Add derive_gid flag for mounting sdcardfs
Turns on the derive_gid feature for sdcardfs. This was moved under a mount flag in the kernel. Test: If the derive_gid flag is supported, the first mount should succeed. If the flag is not, the second should succeed. Bug: 63245673 Change-Id: If1c1bce13d14120732e420252cb5605d33ce7c40
Diffstat (limited to 'sdcard')
-rw-r--r--sdcard/sdcard.cpp60
1 files changed, 40 insertions, 20 deletions
diff --git a/sdcard/sdcard.cpp b/sdcard/sdcard.cpp
index 343a90356..77d5a91f1 100644
--- a/sdcard/sdcard.cpp
+++ b/sdcard/sdcard.cpp
@@ -319,17 +319,31 @@ static void run(const char* source_path, const char* label, uid_t uid,
LOG(FATAL) << "terminated prematurely";
}
-static bool sdcardfs_setup(const std::string& source_path, const std::string& dest_path, uid_t fsuid,
- gid_t fsgid, bool multi_user, userid_t userid, gid_t gid, mode_t mask) {
- std::string opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d",
- fsuid, fsgid, multi_user?"multiuser,":"", mask, userid, gid);
+static bool sdcardfs_setup(const std::string& source_path, const std::string& dest_path,
+ uid_t fsuid, gid_t fsgid, bool multi_user, userid_t userid, gid_t gid,
+ mode_t mask, bool derive_gid) {
+ std::string opts = android::base::StringPrintf(
+ "fsuid=%d,fsgid=%d,%s%smask=%d,userid=%d,gid=%d", fsuid, fsgid,
+ multi_user ? "multiuser," : "", derive_gid ? "derive_gid," : "", mask, userid, gid);
if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs",
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) {
- PLOG(ERROR) << "failed to mount sdcardfs filesystem";
- return false;
+ if (derive_gid) {
+ PLOG(ERROR) << "trying to mount sdcardfs filesystem without derive_gid";
+ /* Maybe this isn't supported on this kernel. Try without. */
+ opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d",
+ fsuid, fsgid, multi_user ? "multiuser," : "", mask,
+ userid, gid);
+ if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs",
+ MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) {
+ PLOG(ERROR) << "failed to mount sdcardfs filesystem";
+ return false;
+ }
+ } else {
+ PLOG(ERROR) << "failed to mount sdcardfs filesystem";
+ return false;
+ }
}
-
return true;
}
@@ -355,7 +369,8 @@ static bool sdcardfs_setup_bind_remount(const std::string& source_path, const st
}
static void run_sdcardfs(const std::string& source_path, const std::string& label, uid_t uid,
- gid_t gid, userid_t userid, bool multi_user, bool full_write) {
+ gid_t gid, userid_t userid, bool multi_user, bool full_write,
+ bool derive_gid) {
std::string dest_path_default = "/mnt/runtime/default/" + label;
std::string dest_path_read = "/mnt/runtime/read/" + label;
std::string dest_path_write = "/mnt/runtime/write/" + label;
@@ -365,10 +380,10 @@ static void run_sdcardfs(const std::string& source_path, const std::string& labe
// Multi-user storage is fully isolated per user, so "other"
// permissions are completely masked off.
if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid,
- AID_SDCARD_RW, 0006)
- || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, 0027)
- || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write,
- AID_EVERYBODY, full_write ? 0007 : 0027)) {
+ AID_SDCARD_RW, 0006, derive_gid) ||
+ !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, 0027) ||
+ !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY,
+ full_write ? 0007 : 0027)) {
LOG(FATAL) << "failed to sdcardfs_setup";
}
} else {
@@ -376,11 +391,11 @@ static void run_sdcardfs(const std::string& source_path, const std::string& labe
// the Android directories are masked off to a single user
// deep inside attr_from_stat().
if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid,
- AID_SDCARD_RW, 0006)
- || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read,
- AID_EVERYBODY, full_write ? 0027 : 0022)
- || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write,
- AID_EVERYBODY, full_write ? 0007 : 0022)) {
+ AID_SDCARD_RW, 0006, derive_gid) ||
+ !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY,
+ full_write ? 0027 : 0022) ||
+ !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY,
+ full_write ? 0007 : 0022)) {
LOG(FATAL) << "failed to sdcardfs_setup";
}
}
@@ -437,7 +452,8 @@ static int usage() {
<< " -g: specify GID to run as"
<< " -U: specify user ID that owns device"
<< " -m: source_path is multi-user"
- << " -w: runtime write mount has full write access";
+ << " -w: runtime write mount has full write access"
+ << " -P preserve owners on the lower file system";
return 1;
}
@@ -449,12 +465,13 @@ int main(int argc, char **argv) {
userid_t userid = 0;
bool multi_user = false;
bool full_write = false;
+ bool derive_gid = false;
int i;
struct rlimit rlim;
int fs_version;
int opt;
- while ((opt = getopt(argc, argv, "u:g:U:mw")) != -1) {
+ while ((opt = getopt(argc, argv, "u:g:U:mwG")) != -1) {
switch (opt) {
case 'u':
uid = strtoul(optarg, NULL, 10);
@@ -471,6 +488,9 @@ int main(int argc, char **argv) {
case 'w':
full_write = true;
break;
+ case 'G':
+ derive_gid = true;
+ break;
case '?':
default:
return usage();
@@ -514,7 +534,7 @@ int main(int argc, char **argv) {
}
if (should_use_sdcardfs()) {
- run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write);
+ run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write, derive_gid);
} else {
run(source_path, label, uid, gid, userid, multi_user, full_write);
}