From c09eee098bd347608cdccac0fc9f17000d255bb5 Mon Sep 17 00:00:00 2001 From: Mao Han Date: Wed, 12 Oct 2022 22:25:06 +0800 Subject: [PATCH] Add mmap_rnd_bits routine for riscv64 Signed-off-by: Mao Han Change-Id: Ide793f4365fee67f30e35302365c4a7a5ba1f021 --- init/security.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init/security.cpp b/init/security.cpp index 0e9f6c2b4..2ecf6872d 100644 --- a/init/security.cpp +++ b/init/security.cpp @@ -116,6 +116,13 @@ Result SetMmapRndBitsAction(const BuiltinArguments&) { if (SetMmapRndBitsMin(33, 24, false) && (!Has32BitAbi() || SetMmapRndBitsMin(16, 16, true))) { return {}; } +#elif defined(__riscv) + // TODO: sv48 and sv57 were both added to the kernel this year, so we + // probably just need some kernel fixes to enable higher ASLR randomization, + // but for now 24 is the maximum that the kernel supports. + if (SetMmapRndBitsMin(24, 18, false)) { + return {}; + } #elif defined(__x86_64__) // x86_64 supports 28 - 32 rnd bits, but Android wants to ensure that the // theoretical maximum of 32 bits is always supported and used.