diff mbox

[PATCHv3,13/19] kernel: add ksys_personality()

Message ID 20180618120310.39527-14-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mark Rutland June 18, 2018, 12:03 p.m. UTC
Using this helper allows us to avoid the in-kernel call to the
sys_personality() syscall. The ksys_ prefix denotes that this function
is meant as a drop-in replacement for the syscall. In particular, it
uses the same calling convention as sys_personality().

Since ksys_personality is trivial, it is implemented directly in
<linux/syscalls.h>, as we do for ksys_close() and friends.

This helper is necessary to enable conversion of arm64's syscall
handling to use pt_regs wrappers.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Martin <dave.martin@arm.com>
---
 include/linux/syscalls.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Catalin Marinas June 19, 2018, 3:45 p.m. UTC | #1
On Mon, Jun 18, 2018 at 01:03:04PM +0100, Mark Rutland wrote:
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index 73810808cdf2..14312d334345 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -80,6 +80,7 @@ union bpf_attr;
>  #include <linux/unistd.h>
>  #include <linux/quota.h>
>  #include <linux/key.h>
> +#include <linux/personality.h>
>  #include <trace/syscall.h>
>  
>  #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
> @@ -1277,4 +1278,14 @@ 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;
> +}
> +
>  #endif

It looks like this is identical to sys_personality() in
kernel/exec_domain.c. Should you call ksys_personality() from there
directly (a few lines saved)?
Mark Rutland June 19, 2018, 3:53 p.m. UTC | #2
On Tue, Jun 19, 2018 at 04:45:41PM +0100, Catalin Marinas wrote:
> On Mon, Jun 18, 2018 at 01:03:04PM +0100, Mark Rutland wrote:
> > diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> > index 73810808cdf2..14312d334345 100644
> > --- a/include/linux/syscalls.h
> > +++ b/include/linux/syscalls.h
> > @@ -80,6 +80,7 @@ union bpf_attr;
> >  #include <linux/unistd.h>
> >  #include <linux/quota.h>
> >  #include <linux/key.h>
> > +#include <linux/personality.h>
> >  #include <trace/syscall.h>
> >  
> >  #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
> > @@ -1277,4 +1278,14 @@ 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;
> > +}
> > +
> >  #endif
> 
> It looks like this is identical to sys_personality() in
> kernel/exec_domain.c. Should you call ksys_personality() from there
> directly (a few lines saved)?

I had originally done so [1], but Christophe preferred that I open-code
the logic [2].

Thanks,
Mark.

[1] https://lkml.kernel.org/r/20180514094640.27569-13-mark.rutland@arm.com
[2] https://lkml.kernel.org/r/20180514120756.GA11638@infradead.org
diff mbox

Patch

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 73810808cdf2..14312d334345 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -80,6 +80,7 @@  union bpf_attr;
 #include <linux/unistd.h>
 #include <linux/quota.h>
 #include <linux/key.h>
+#include <linux/personality.h>
 #include <trace/syscall.h>
 
 #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
@@ -1277,4 +1278,14 @@  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;
+}
+
 #endif