Re: [PATCH] sys_personality: Add a optional arch hook arch_check_personality()

From: Wangshaobo (bobo)
Date: Sat Dec 28 2019 - 04:03:03 EST


I am sorry for sending a wrong version, the correct version is v2.

在 2019/12/28 16:43, Wang ShaoBo 写道:
currently arm64 use __arm64_sys_arm64_personality() as its default
syscall. Now using a normal hook arch_check_personality() can reject
personality settings for special case of different archs.

Signed-off-by: Wang ShaoBo <bobo.shaobowang@xxxxxxxxxx>
---
arch/arm64/kernel/sys.c | 6 +++---
kernel/exec_domain.c | 11 +++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c
index d5ffaaab31a7..751fbd57eb1e 100644
--- a/arch/arm64/kernel/sys.c
+++ b/arch/arm64/kernel/sys.c
@@ -28,12 +28,13 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
}
-SYSCALL_DEFINE1(arm64_personality, unsigned int, personality)
+int arch_check_personality(unsigned int personality)
{
if (personality(personality) == PER_LINUX32 &&
!system_supports_32bit_el0())
return -EINVAL;
- return ksys_personality(personality);
+
+ return 0;
}
asmlinkage long sys_ni_syscall(void);
@@ -46,7 +47,6 @@ asmlinkage long __arm64_sys_ni_syscall(const struct pt_regs *__unused)
/*
* Wrappers to pass the pt_regs argument.
*/
-#define __arm64_sys_personality __arm64_sys_arm64_personality
#undef __SYSCALL
#define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *);
diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c
index f7a0512ddc23..ec6b16e30ed1 100644
--- a/kernel/exec_domain.c
+++ b/kernel/exec_domain.c
@@ -35,7 +35,18 @@ static int __init proc_execdomains_init(void)
module_init(proc_execdomains_init);
#endif
+static int __weak arch_check_personality(unsigned int personality)
+{
+ return 0;
+}
+
SYSCALL_DEFINE1(personality, unsigned int, personality)
{
+ int check;
+
+ check = arch_check_personality(personality);
+ if (check)
+ return check;
+
return ksys_personality(personality);
}