2020-01-09 01:44:15

by Wangshaobo (bobo)

[permalink] [raw]
Subject: [PATCH] sys_personality: Add a optional arch hook arch_check_personality() for common sys_personality()

currently arm64 use __arm64_sys_arm64_personality() as its default
syscall. But using a normal hook arch_check_personality() can reject
personality settings for special case of different archs.

Signed-off-by: Wang ShaoBo <[email protected]>
---
arch/arm64/kernel/sys.c | 7 +++----
kernel/exec_domain.c | 14 ++++++++++----
2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c
index d5ffaaab31a7..5c01816d7a77 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,8 +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 *);
#include <asm/unistd.h>
diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c
index 33f07c5f2515..d1d5d14441e2 100644
--- a/kernel/exec_domain.c
+++ b/kernel/exec_domain.c
@@ -35,12 +35,18 @@ static int __init proc_execdomains_init(void)
module_init(proc_execdomains_init);
#endif

+int __weak arch_check_personality(unsigned int personality)
+{
+ return 0;
+}
+
SYSCALL_DEFINE1(personality, unsigned int, personality)
{
- unsigned int old = current->personality;
+ int check;

- if (personality != 0xffffffff)
- set_personality(personality);
+ check = arch_check_personality(personality);
+ if (check)
+ return check;

- return old;
+ return ksys_personality(personality);
}
--
2.20.1


2020-01-09 07:01:27

by Dominik Brodowski

[permalink] [raw]
Subject: Re: [PATCH] sys_personality: Add a optional arch hook arch_check_personality() for common sys_personality()

On Thu, Jan 09, 2020 at 09:38:46AM +0800, Wang ShaoBo wrote:
> currently arm64 use __arm64_sys_arm64_personality() as its default
> syscall. But using a normal hook arch_check_personality() can reject
> personality settings for special case of different archs.

Thanks for your patch!

> SYSCALL_DEFINE1(personality, unsigned int, personality)
> {
> - unsigned int old = current->personality;
> + int check;
>
> - if (personality != 0xffffffff)
> - set_personality(personality);
> + check = arch_check_personality(personality);
> + if (check)
> + return check;
>
> - return old;
> + return ksys_personality(personality);
> }

Please leave the default check and call to set_personality()
in here and remove the now-unneeded ksys_personality() from
include/linux/syscalls.h

Thanks,
Dominik

2020-01-09 10:23:53

by Wangshaobo (bobo)

[permalink] [raw]
Subject: Re: [PATCH] sys_personality: Add a optional arch hook arch_check_personality() for common sys_personality()

Thanks for your reply, I wiil send it in version 2

Thanks,

            wangshaobo

在 2020/1/9 14:54, Dominik Brodowski 写道:
> On Thu, Jan 09, 2020 at 09:38:46AM +0800, Wang ShaoBo wrote:
>> currently arm64 use __arm64_sys_arm64_personality() as its default
>> syscall. But using a normal hook arch_check_personality() can reject
>> personality settings for special case of different archs.
> Thanks for your patch!
>
>> SYSCALL_DEFINE1(personality, unsigned int, personality)
>> {
>> - unsigned int old = current->personality;
>> + int check;
>>
>> - if (personality != 0xffffffff)
>> - set_personality(personality);
>> + check = arch_check_personality(personality);
>> + if (check)
>> + return check;
>>
>> - return old;
>> + return ksys_personality(personality);
>> }
> Please leave the default check and call to set_personality()
> in here and remove the now-unneeded ksys_personality() from
> include/linux/syscalls.h
>
> Thanks,
> Dominik
>
> .