From 194739bfe3d9f4c0b5e9d919b75ce541f7abe701 Mon Sep 17 00:00:00 2001 From: arvinzzz Date: Thu, 13 Oct 2022 10:56:17 +0800 Subject: [PATCH] binfmt_elf: Add a new type of segment PT_OHOS_RANDOMDATA Appears only in ELF compiled with specific compile options. It is used to identify this attribute and fill random numbers into corresponding segments when loading and linking, and is used for some system security hardening features. Signed-off-by: arvinzzz Change-Id: I18a537fd32dde27c153d2f99248fc67c8f1dbf87 --- fs/binfmt_elf.c | 5 +++++ include/uapi/linux/elf.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 04c4aa7a1df2..1651afc8656a 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1034,6 +1034,11 @@ static int load_elf_binary(struct linux_binprm *bprm) unsigned long total_size = 0; unsigned long alignment; + if (elf_ppnt->p_type == PT_OHOS_RANDOMDATA) { + get_random_bytes((void *)(elf_ppnt->p_vaddr + load_bias), (int)elf_ppnt->p_memsz); + continue; + } + if (elf_ppnt->p_type != PT_LOAD) continue; diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index 30f68b42eeb5..2f06a1195fee 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -38,6 +38,8 @@ typedef __s64 Elf64_Sxword; #define PT_GNU_EH_FRAME 0x6474e550 #define PT_GNU_PROPERTY 0x6474e553 +#define PT_OHOS_RANDOMDATA 0x6788fc60 /* ohos-specific segment */ + #define PT_GNU_STACK (PT_LOOS + 0x474e551) /* -- Gitee