From 11d7bc52df55e487b78dce0fd70a88e5096987d9 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 15 Jul 2022 13:44:14 +0900 Subject: [PATCH] init: don't touch mmap_rnd_compat_bits on 64-bit only builds mmap_rnd_compat_bits is for address space randomization of 32-bit applications on 64-bit system. Configuring it is not only unnecessary for 64-bit "only" builds, but also can cause a boot failure if the kernel is built without CONFIG_COMPAT which is the case for Microdroid. Use ro.product.abilist32 to determine whether 32-bit applications are supported and if not, don't configure it, but mmap_rnd_bits. Bug: 237950549 Test: run Microdroid with the kernel built with aosp/2153639 Change-Id: Ifca6fa02f14ad4c7d8f9b2ab8852494c12945c3a --- init/security.cpp | 5 +++-- init/util.cpp | 5 +++++ init/util.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/init/security.cpp b/init/security.cpp index 970696e64..8bf4d5299 100644 --- a/init/security.cpp +++ b/init/security.cpp @@ -15,6 +15,7 @@ */ #include "security.h" +#include "util.h" #include #include @@ -106,12 +107,12 @@ Result SetMmapRndBitsAction(const BuiltinArguments&) { return {}; #elif defined(__aarch64__) // arm64 supports 18 - 33 bits depending on pagesize and VA_SIZE - if (SetMmapRndBitsMin(33, 24, false) && SetMmapRndBitsMin(16, 16, true)) { + if (SetMmapRndBitsMin(33, 24, false) && (!Has32BitAbi() || SetMmapRndBitsMin(16, 16, true))) { return {}; } #elif defined(__x86_64__) // x86_64 supports 28 - 32 bits - if (SetMmapRndBitsMin(32, 32, false) && SetMmapRndBitsMin(16, 16, true)) { + if (SetMmapRndBitsMin(32, 32, false) && (!Has32BitAbi() || SetMmapRndBitsMin(16, 16, true))) { return {}; } #elif defined(__arm__) || defined(__i386__) diff --git a/init/util.cpp b/init/util.cpp index 1801d1792..523cce451 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -733,5 +733,10 @@ bool IsMicrodroid() { return is_microdroid; } +bool Has32BitAbi() { + static bool has = !android::base::GetProperty("ro.product.cpu.abilist32", "").empty(); + return has; +} + } // namespace init } // namespace android diff --git a/init/util.h b/init/util.h index 47d4ff518..099b9eeae 100644 --- a/init/util.h +++ b/init/util.h @@ -106,5 +106,6 @@ bool IsDefaultMountNamespaceReady(); void SetDefaultMountNamespaceReady(); bool IsMicrodroid(); +bool Has32BitAbi(); } // namespace init } // namespace android