Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f29a3bc7 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Skip hard quotas when reserved has our back.

If the filesystem has reserved blocks set aside for system critical
services, then we don't need to enable or set hard quotas.

Test: builds, boots
Bug: 62024591
Change-Id: I2b4d2fb644ad5d2e2a789c7f42f968bc717cfead
parent 7a0f1e75
Loading
Loading
Loading
Loading
+17 −8
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <unistd.h>


#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <android-base/unique_fd.h>
@@ -71,6 +72,7 @@ namespace installd {


static constexpr const char* kCpPath = "/system/bin/cp";
static constexpr const char* kCpPath = "/system/bin/cp";
static constexpr const char* kXattrDefault = "user.default";
static constexpr const char* kXattrDefault = "user.default";
static constexpr const char* kPropHasReserved = "vold.has_reserved";


static constexpr const int MIN_RESTRICTED_HOME_SDK_VERSION = 24; // > M
static constexpr const int MIN_RESTRICTED_HOME_SDK_VERSION = 24; // > M


@@ -302,6 +304,9 @@ static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t ui
 */
 */
static int prepare_app_quota(const std::unique_ptr<std::string>& uuid, const std::string& device,
static int prepare_app_quota(const std::unique_ptr<std::string>& uuid, const std::string& device,
        uid_t uid) {
        uid_t uid) {
    // Skip when reserved blocks are protecting us against abusive apps
    if (android::base::GetBoolProperty(kPropHasReserved, false)) return 0;
    // Skip when device no quotas present
    if (device.empty()) return 0;
    if (device.empty()) return 0;


    struct dqblk dq;
    struct dqblk dq;
@@ -2417,17 +2422,21 @@ binder::Status InstalldNativeService::invalidateMounts() {
                mQuotaReverseMounts[target] = source;
                mQuotaReverseMounts[target] = source;


                // ext4 only enables DQUOT_USAGE_ENABLED by default, so we
                // ext4 only enables DQUOT_USAGE_ENABLED by default, so we
                // need to kick it again to enable DQUOT_LIMITS_ENABLED.
                // need to kick it again to enable DQUOT_LIMITS_ENABLED. We
                if (quotactl(QCMD(Q_QUOTAON, USRQUOTA), source.c_str(), QFMT_VFS_V1, nullptr) != 0
                // only need hard limits enabled when we're not being protected
                        && errno != EBUSY) {
                // by reserved blocks.
                if (!android::base::GetBoolProperty(kPropHasReserved, false)) {
                    if (quotactl(QCMD(Q_QUOTAON, USRQUOTA), source.c_str(), QFMT_VFS_V1,
                            nullptr) != 0 && errno != EBUSY) {
                        PLOG(ERROR) << "Failed to enable USRQUOTA on " << source;
                        PLOG(ERROR) << "Failed to enable USRQUOTA on " << source;
                    }
                    }
                if (quotactl(QCMD(Q_QUOTAON, GRPQUOTA), source.c_str(), QFMT_VFS_V1, nullptr) != 0
                    if (quotactl(QCMD(Q_QUOTAON, GRPQUOTA), source.c_str(), QFMT_VFS_V1,
                        && errno != EBUSY) {
                            nullptr) != 0 && errno != EBUSY) {
                        PLOG(ERROR) << "Failed to enable GRPQUOTA on " << source;
                        PLOG(ERROR) << "Failed to enable GRPQUOTA on " << source;
                    }
                    }
                }
                }
            }
            }
        }
#endif
#endif
    }
    }
    return ok();
    return ok();