mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang ShaoBo <bobo.shaobowang@huawei.com>
To: <mark.rutland@arm.com>, <hch@infradead.org>,
	<linux@dominikbrodowski.net>
Cc: <cj.chengjian@huawei.com>, <huawei.libin@huawei.com>,
	<xiexiuqi@huawei.com>, <yangyingliang@huawei.com>,
	<bobo.shaobowang@huawei.com>, <guohanjun@huawei.com>,
	<wcohen@redhat.com>, <linux-kernel@vger.kernel.org>,
	<mtk.manpages@gmail.com>, <wezhang@redhat.com>
Subject: [PATCH v2] sys_personality: Add a optional arch hook arch_check_personality() for common sys_personality()
Date: Thu, 9 Jan 2020 21:36:34 +0800	[thread overview]
Message-ID: <20200109133634.176483-1-bobo.shaobowang@huawei.com> (raw)

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 <bobo.shaobowang@huawei.com>
---
 Changes in v2:
  - Delete inline ksys_personality() definition.
  - Update sys_personality() definition.
 Changes in v1:
  - Delete macro __arm64_sys_personality.
  - Add hook arch_check_personality() and update sys_personality().
---
 arch/arm64/kernel/sys.c  |  7 +++----
 include/linux/syscalls.h | 10 ----------
 kernel/exec_domain.c     | 14 +++++++++++++-
 3 files changed, 16 insertions(+), 15 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/include/linux/syscalls.h b/include/linux/syscalls.h
index 2960dedcfde8..b7ead4c933d5 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1389,16 +1389,6 @@ static inline long ksys_truncate(const char __user *pathname, loff_t length)
 	return do_sys_truncate(pathname, length);
 }
 
-static inline unsigned int ksys_personality(unsigned int personality)
-{
-	unsigned int old = current->personality;
-
-	if (personality != 0xffffffff)
-		set_personality(personality);
-
-	return old;
-}
-
 /* for __ARCH_WANT_SYS_IPC */
 long ksys_semtimedop(int semid, struct sembuf __user *tsops,
 		     unsigned int nsops,
diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c
index 33f07c5f2515..1e70b41bf348 100644
--- a/kernel/exec_domain.c
+++ b/kernel/exec_domain.c
@@ -35,9 +35,21 @@ 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;
+	unsigned int old;
+
+	check = arch_check_personality(personality);
+	if (check)
+		return check;
+
+	old = current->personality;
 
 	if (personality != 0xffffffff)
 		set_personality(personality);
-- 
2.20.1


             reply	other threads:[~2020-01-09 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 13:36 Wang ShaoBo [this message]
2020-01-10  5:45 ` Dominik Brodowski
2020-03-25 10:27   ` Wangshaobo (bobo)
2020-03-27  5:28     ` Dominik Brodowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200109133634.176483-1-bobo.shaobowang@huawei.com \
    --to=bobo.shaobowang@huawei.com \
    --cc=cj.chengjian@huawei.com \
    --cc=guohanjun@huawei.com \
    --cc=hch@infradead.org \
    --cc=huawei.libin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=mark.rutland@arm.com \
    --cc=mtk.manpages@gmail.com \
    --cc=wcohen@redhat.com \
    --cc=wezhang@redhat.com \
    --cc=xiexiuqi@huawei.com \
    --cc=yangyingliang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®