From ea9681e4cdf30340b583dc27cb6c6474926ddaee Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Mon, 1 Feb 2021 07:57:02 +0000 Subject: [PATCH] Revert "Revert "Set a default ACL on /data/media/userId."" This reverts commit b276e80aec54c139587bbc510f503ced9414cf0f. Reason for revert: b/177926359 is now fixed Change-Id: I8ec5d80a44fc9e491ab3430592e17d10a82f40ea --- FsCrypt.cpp | 11 ++++++++++- Utils.cpp | 4 ++-- Utils.h | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/FsCrypt.cpp b/FsCrypt.cpp index 8f6ba9c..be51963 100644 --- a/FsCrypt.cpp +++ b/FsCrypt.cpp @@ -74,6 +74,7 @@ using android::vold::KeyBuffer; using android::vold::KeyGeneration; using android::vold::retrieveKey; using android::vold::retrieveOrGenerateKey; +using android::vold::SetDefaultAcl; using android::vold::SetQuotaInherit; using android::vold::SetQuotaProjectId; using android::vold::writeStringToFile; @@ -867,7 +868,15 @@ bool fscrypt_prepare_user_storage(const std::string& volume_uuid, userid_t user_ if (!prepare_dir(misc_ce_path, 01771, AID_SYSTEM, AID_MISC)) return false; if (!prepare_dir(vendor_ce_path, 0771, AID_ROOT, AID_ROOT)) return false; } - if (!prepare_dir(media_ce_path, 0770, AID_MEDIA_RW, AID_MEDIA_RW)) return false; + if (!prepare_dir(media_ce_path, 02770, AID_MEDIA_RW, AID_MEDIA_RW)) return false; + // On devices without sdcardfs (kernel 5.4+), the path permissions aren't fixed + // up automatically; therefore, use a default ACL, to ensure apps with MEDIA_RW + // can keep reading external storage; in particular, this allows app cloning + // scenarios to work correctly on such devices. + int ret = SetDefaultAcl(media_ce_path, 02770, AID_MEDIA_RW, AID_MEDIA_RW, {AID_MEDIA_RW}); + if (ret != android::OK) { + return false; + } if (!prepare_dir(user_ce_path, 0771, AID_SYSTEM, AID_SYSTEM)) return false; diff --git a/Utils.cpp b/Utils.cpp index d5648f7..98797b2 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -136,8 +136,8 @@ status_t DestroyDeviceNode(const std::string& path) { } // Sets a default ACL on the directory. -int SetDefaultAcl(const std::string& path, mode_t mode, uid_t uid, gid_t gid, - std::vector additionalGids) { +status_t SetDefaultAcl(const std::string& path, mode_t mode, uid_t uid, gid_t gid, + std::vector additionalGids) { if (IsSdcardfsUsed()) { // sdcardfs magically takes care of this return OK; diff --git a/Utils.h b/Utils.h index cf3fd9b..8975adc 100644 --- a/Utils.h +++ b/Utils.h @@ -52,6 +52,9 @@ std::string GetFuseMountPathForUser(userid_t user_id, const std::string& relativ status_t CreateDeviceNode(const std::string& path, dev_t dev); status_t DestroyDeviceNode(const std::string& path); +status_t SetDefaultAcl(const std::string& path, mode_t mode, uid_t uid, gid_t gid, + std::vector additionalGids); + status_t AbortFuseConnections(); int SetQuotaInherit(const std::string& path);