Merge "Set memlock rlimit to 64KB"

This commit is contained in:
Carlos Galo 2023-01-09 19:05:59 +00:00 committed by Gerrit Code Review
commit 177f5b1822
2 changed files with 19 additions and 0 deletions

View file

@ -21,8 +21,10 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android/api-level.h>
#include <gtest/gtest.h>
#include <selinux/selinux.h>
#include <sys/resource.h>
#include "action.h"
#include "action_manager.h"
@ -626,6 +628,20 @@ service A something
ASSERT_EQ(1u, parser.parse_error_count());
}
TEST(init, MemLockLimit) {
// Test is enforced only for U+ devices
if (android::base::GetIntProperty("ro.vendor.api_level", 0) < __ANDROID_API_U__) {
GTEST_SKIP();
}
// Verify we are running memlock at, or under, 64KB
const unsigned long max_limit = 65536;
struct rlimit curr_limit;
ASSERT_EQ(getrlimit(RLIMIT_MEMLOCK, &curr_limit), 0);
ASSERT_LE(curr_limit.rlim_cur, max_limit);
ASSERT_LE(curr_limit.rlim_max, max_limit);
}
class TestCaseLogger : public ::testing::EmptyTestEventListener {
void OnTestStart(const ::testing::TestInfo& test_info) override {
#ifdef __ANDROID__

View file

@ -47,6 +47,9 @@ on early-init
# Allow up to 32K FDs per process
setrlimit nofile 32768 32768
# set RLIMIT_MEMLOCK to 64KB
setrlimit memlock 65536 65536
# Set up linker config subdirectories based on mount namespaces
mkdir /linkerconfig/bootstrap 0755
mkdir /linkerconfig/default 0755