Loading sdcard/sdcard.cpp +30 −26 Original line number Original line Diff line number Diff line Loading @@ -321,30 +321,26 @@ static void run(const char* source_path, const char* label, uid_t uid, static bool sdcardfs_setup(const std::string& source_path, const std::string& dest_path, 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, uid_t fsuid, gid_t fsgid, bool multi_user, userid_t userid, gid_t gid, mode_t mask, bool derive_gid) { mode_t mask, bool derive_gid, bool default_normal) { std::string opts = android::base::StringPrintf( // Try several attempts, each time with one less option, to gracefully "fsuid=%d,fsgid=%d,%s%smask=%d,userid=%d,gid=%d", fsuid, fsgid, // handle older kernels that aren't updated yet. multi_user ? "multiuser," : "", derive_gid ? "derive_gid," : "", mask, userid, gid); for (int i = 0; i < 4; i++) { std::string new_opts; if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs", if (multi_user && i < 3) new_opts += "multiuser,"; MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { if (derive_gid && i < 2) new_opts += "derive_gid,"; if (derive_gid) { if (default_normal && i < 1) new_opts += "default_normal,"; PLOG(ERROR) << "trying to mount sdcardfs filesystem without derive_gid"; /* Maybe this isn't supported on this kernel. Try without. */ auto opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d", opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d", fsuid, fsgid, new_opts.c_str(), mask, userid, gid); fsuid, fsgid, multi_user ? "multiuser," : "", mask, userid, gid); if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs", if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { PLOG(ERROR) << "failed to mount sdcardfs filesystem"; PLOG(WARNING) << "Failed to mount sdcardfs with options " << opts; return false; } } else { } else { PLOG(ERROR) << "failed to mount sdcardfs filesystem"; return true; return false; } } } } return true; return false; } } static bool sdcardfs_setup_bind_remount(const std::string& source_path, const std::string& dest_path, static bool sdcardfs_setup_bind_remount(const std::string& source_path, const std::string& dest_path, Loading @@ -370,7 +366,7 @@ 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, 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) { bool derive_gid, bool default_normal) { std::string dest_path_default = "/mnt/runtime/default/" + label; std::string dest_path_default = "/mnt/runtime/default/" + label; std::string dest_path_read = "/mnt/runtime/read/" + label; std::string dest_path_read = "/mnt/runtime/read/" + label; std::string dest_path_write = "/mnt/runtime/write/" + label; std::string dest_path_write = "/mnt/runtime/write/" + label; Loading @@ -380,7 +376,7 @@ static void run_sdcardfs(const std::string& source_path, const std::string& labe // Multi-user storage is fully isolated per user, so "other" // Multi-user storage is fully isolated per user, so "other" // permissions are completely masked off. // permissions are completely masked off. if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, AID_SDCARD_RW, 0006, derive_gid) || AID_SDCARD_RW, 0006, derive_gid, default_normal) || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, 0027) || !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, !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY, full_write ? 0007 : 0027)) { full_write ? 0007 : 0027)) { Loading @@ -391,7 +387,7 @@ static void run_sdcardfs(const std::string& source_path, const std::string& labe // the Android directories are masked off to a single user // the Android directories are masked off to a single user // deep inside attr_from_stat(). // deep inside attr_from_stat(). if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, AID_SDCARD_RW, 0006, derive_gid) || AID_SDCARD_RW, 0006, derive_gid, default_normal) || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, full_write ? 0027 : 0022) || full_write ? 0027 : 0022) || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY, !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY, Loading Loading @@ -466,12 +462,16 @@ int main(int argc, char **argv) { bool multi_user = false; bool multi_user = false; bool full_write = false; bool full_write = false; bool derive_gid = false; bool derive_gid = false; bool default_normal = false; int i; int i; struct rlimit rlim; struct rlimit rlim; int fs_version; int fs_version; setenv("ANDROID_LOG_TAGS", "*:v", 1); android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); int opt; int opt; while ((opt = getopt(argc, argv, "u:g:U:mwG")) != -1) { while ((opt = getopt(argc, argv, "u:g:U:mwGi")) != -1) { switch (opt) { switch (opt) { case 'u': case 'u': uid = strtoul(optarg, NULL, 10); uid = strtoul(optarg, NULL, 10); Loading @@ -491,6 +491,9 @@ int main(int argc, char **argv) { case 'G': case 'G': derive_gid = true; derive_gid = true; break; break; case 'i': default_normal = true; break; case '?': case '?': default: default: return usage(); return usage(); Loading Loading @@ -534,7 +537,8 @@ int main(int argc, char **argv) { } } if (should_use_sdcardfs()) { if (should_use_sdcardfs()) { run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write, derive_gid); run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write, derive_gid, default_normal); } else { } else { run(source_path, label, uid, gid, userid, multi_user, full_write); run(source_path, label, uid, gid, userid, multi_user, full_write); } } Loading Loading
sdcard/sdcard.cpp +30 −26 Original line number Original line Diff line number Diff line Loading @@ -321,30 +321,26 @@ static void run(const char* source_path, const char* label, uid_t uid, static bool sdcardfs_setup(const std::string& source_path, const std::string& dest_path, 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, uid_t fsuid, gid_t fsgid, bool multi_user, userid_t userid, gid_t gid, mode_t mask, bool derive_gid) { mode_t mask, bool derive_gid, bool default_normal) { std::string opts = android::base::StringPrintf( // Try several attempts, each time with one less option, to gracefully "fsuid=%d,fsgid=%d,%s%smask=%d,userid=%d,gid=%d", fsuid, fsgid, // handle older kernels that aren't updated yet. multi_user ? "multiuser," : "", derive_gid ? "derive_gid," : "", mask, userid, gid); for (int i = 0; i < 4; i++) { std::string new_opts; if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs", if (multi_user && i < 3) new_opts += "multiuser,"; MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { if (derive_gid && i < 2) new_opts += "derive_gid,"; if (derive_gid) { if (default_normal && i < 1) new_opts += "default_normal,"; PLOG(ERROR) << "trying to mount sdcardfs filesystem without derive_gid"; /* Maybe this isn't supported on this kernel. Try without. */ auto opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d", opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d", fsuid, fsgid, new_opts.c_str(), mask, userid, gid); fsuid, fsgid, multi_user ? "multiuser," : "", mask, userid, gid); if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs", if (mount(source_path.c_str(), dest_path.c_str(), "sdcardfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { PLOG(ERROR) << "failed to mount sdcardfs filesystem"; PLOG(WARNING) << "Failed to mount sdcardfs with options " << opts; return false; } } else { } else { PLOG(ERROR) << "failed to mount sdcardfs filesystem"; return true; return false; } } } } return true; return false; } } static bool sdcardfs_setup_bind_remount(const std::string& source_path, const std::string& dest_path, static bool sdcardfs_setup_bind_remount(const std::string& source_path, const std::string& dest_path, Loading @@ -370,7 +366,7 @@ 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, 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) { bool derive_gid, bool default_normal) { std::string dest_path_default = "/mnt/runtime/default/" + label; std::string dest_path_default = "/mnt/runtime/default/" + label; std::string dest_path_read = "/mnt/runtime/read/" + label; std::string dest_path_read = "/mnt/runtime/read/" + label; std::string dest_path_write = "/mnt/runtime/write/" + label; std::string dest_path_write = "/mnt/runtime/write/" + label; Loading @@ -380,7 +376,7 @@ static void run_sdcardfs(const std::string& source_path, const std::string& labe // Multi-user storage is fully isolated per user, so "other" // Multi-user storage is fully isolated per user, so "other" // permissions are completely masked off. // permissions are completely masked off. if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, AID_SDCARD_RW, 0006, derive_gid) || AID_SDCARD_RW, 0006, derive_gid, default_normal) || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, 0027) || !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, !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY, full_write ? 0007 : 0027)) { full_write ? 0007 : 0027)) { Loading @@ -391,7 +387,7 @@ static void run_sdcardfs(const std::string& source_path, const std::string& labe // the Android directories are masked off to a single user // the Android directories are masked off to a single user // deep inside attr_from_stat(). // deep inside attr_from_stat(). if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, AID_SDCARD_RW, 0006, derive_gid) || AID_SDCARD_RW, 0006, derive_gid, default_normal) || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, !sdcardfs_setup_bind_remount(dest_path_default, dest_path_read, AID_EVERYBODY, full_write ? 0027 : 0022) || full_write ? 0027 : 0022) || !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY, !sdcardfs_setup_bind_remount(dest_path_default, dest_path_write, AID_EVERYBODY, Loading Loading @@ -466,12 +462,16 @@ int main(int argc, char **argv) { bool multi_user = false; bool multi_user = false; bool full_write = false; bool full_write = false; bool derive_gid = false; bool derive_gid = false; bool default_normal = false; int i; int i; struct rlimit rlim; struct rlimit rlim; int fs_version; int fs_version; setenv("ANDROID_LOG_TAGS", "*:v", 1); android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); int opt; int opt; while ((opt = getopt(argc, argv, "u:g:U:mwG")) != -1) { while ((opt = getopt(argc, argv, "u:g:U:mwGi")) != -1) { switch (opt) { switch (opt) { case 'u': case 'u': uid = strtoul(optarg, NULL, 10); uid = strtoul(optarg, NULL, 10); Loading @@ -491,6 +491,9 @@ int main(int argc, char **argv) { case 'G': case 'G': derive_gid = true; derive_gid = true; break; break; case 'i': default_normal = true; break; case '?': case '?': default: default: return usage(); return usage(); Loading Loading @@ -534,7 +537,8 @@ int main(int argc, char **argv) { } } if (should_use_sdcardfs()) { if (should_use_sdcardfs()) { run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write, derive_gid); run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write, derive_gid, default_normal); } else { } else { run(source_path, label, uid, gid, userid, multi_user, full_write); run(source_path, label, uid, gid, userid, multi_user, full_write); } } Loading