All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] prctl: fix compat handling for prctl
@ 2018-04-19  1:06 Li Bin
  2018-04-19  1:35 ` Andy Lutomirski
  2018-04-19  2:25 ` Andy Lutomirski
  0 siblings, 2 replies; 5+ messages in thread
From: Li Bin @ 2018-04-19  1:06 UTC (permalink / raw)
  To: Al Viro, Eric W. Biederman, Dominik Brodowski, Andrew Morton,
	Andy Lutomirski, linux-kernel
  Cc: huawei.libin, guohanjun

The member auxv in prctl_mm_map structure which be shared with
userspace is pointer type, but the kernel supporting COMPAT didn't
handle it. This patch fix the compat handling for prctl syscall.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
---
 kernel/sys.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/kernel/sys.c b/kernel/sys.c
index ad69218..d4259938 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1969,6 +1969,26 @@ static int validate_prctl_map(struct prctl_mm_map *prctl_map)
 }
 
 #ifdef CONFIG_CHECKPOINT_RESTORE
+
+#ifdef CONFIG_COMPAT
+struct compat_prctl_mm_map {
+	__u64   start_code;     /* code section bounds */
+	__u64   end_code;
+	__u64   start_data;     /* data section bounds */
+	__u64   end_data;
+	__u64   start_brk;      /* heap for brk() syscall */
+	__u64   brk;
+	__u64   start_stack;        /* stack starts at */
+	__u64   arg_start;      /* command line arguments bounds */
+	__u64   arg_end;
+	__u64   env_start;      /* environment variables bounds */
+	__u64   env_end;
+	compat_uptr_t   auxv;   /* auxiliary vector */
+	__u32   auxv_size;      /* vector size */
+	__u32   exe_fd;         /* /proc/$pid/exe link file */
+};
+#endif
+
 static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data_size)
 {
 	struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, };
@@ -1986,6 +2006,28 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data
 	if (data_size != sizeof(prctl_map))
 		return -EINVAL;
 
+#ifdef CONFIG_COMPAT
+	if (in_compat_syscall()) {
+		struct compat_prctl_mm_map prctl_map32;
+		if (copy_from_user(&prctl_map32, addr, sizeof(prctl_map32)))
+			return -EFAULT;
+
+		prctl_map.start_code = prctl_map32.start_code;
+		prctl_map.end_code = prctl_map32.end_code;
+		prctl_map.start_data = prctl_map32.start_data;
+		prctl_map.end_data = prctl_map32.end_data;
+		prctl_map.start_brk = prctl_map32.start_brk;
+		prctl_map.brk = prctl_map32.brk;
+		prctl_map.start_stack = prctl_map32.start_stack;
+		prctl_map.arg_start = prctl_map32.arg_start;
+		prctl_map.arg_end = prctl_map32.arg_end;
+		prctl_map.env_start = prctl_map32.env_start;
+		prctl_map.env_end = prctl_map32.env_end;
+		prctl_map.auxv = compat_ptr(prctl_map32.auxv);
+		prctl_map.auxv_size = prctl_map32.auxv_size;
+		prctl_map.exe_fd = prctl_map32.exe_fd;
+	} else
+#endif
 	if (copy_from_user(&prctl_map, addr, sizeof(prctl_map)))
 		return -EFAULT;
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] prctl: fix compat handling for prctl
  2018-04-19  1:06 [PATCH v2] prctl: fix compat handling for prctl Li Bin
@ 2018-04-19  1:35 ` Andy Lutomirski
  2018-04-19  2:25 ` Andy Lutomirski
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Lutomirski @ 2018-04-19  1:35 UTC (permalink / raw)
  To: Li Bin
  Cc: Al Viro, Eric W. Biederman, Dominik Brodowski, Andrew Morton,
	Andy Lutomirski, linux-kernel, guohanjun



> On Apr 18, 2018, at 9:06 PM, Li Bin <huawei.libin@huawei.com> wrote:
> 
> The member auxv in prctl_mm_map structure which be shared with
> userspace is pointer type, but the kernel supporting COMPAT didn't
> handle it. This patch fix the compat handling for prctl syscall.
> 
> Signed-off-by: Li Bin <huawei.libin@huawei.com>
> ---
> kernel/sys.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
> 
> diff --git a/kernel/sys.c b/kernel/sys.c
> index ad69218..d4259938 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -1969,6 +1969,26 @@ static int validate_prctl_map(struct prctl_mm_map *prctl_map)
> }
> 
> #ifdef CONFIG_CHECKPOINT_RESTORE
> +
> +#ifdef CONFIG_COMPAT
> +struct compat_prctl_mm_map {
> +    __u64   start_code;     /* code section bounds */
> +    __u64   end_code;
> +    __u64   start_data;     /* data section bounds */
> +    __u64   end_data;
> +    __u64   start_brk;      /* heap for brk() syscall */
> +    __u64   brk;
> +    __u64   start_stack;        /* stack starts at */
> +    __u64   arg_start;      /* command line arguments bounds */
> +    __u64   arg_end;
> +    __u64   env_start;      /* environment variables bounds */
> +    __u64   env_end;
> +    compat_uptr_t   auxv;   /* auxiliary vector */
> +    __u32   auxv_size;      /* vector size */
> +    __u32   exe_fd;         /* /proc/$pid/exe link file */
> +};
> +#endif
> +
> static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data_size)
> {
>    struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, };
> @@ -1986,6 +2006,28 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data
>    if (data_size != sizeof(prctl_map))
>        return -EINVAL;
> 
> +#ifdef CONFIG_COMPAT
> +    if (in_compat_syscall()) {
> +        struct compat_prctl_mm_map prctl_map32;
> +        if (copy_from_user(&prctl_map32, addr, sizeof(prctl_map32)))
> +            return -EFAULT;
> +
> +        prctl_map.start_code = prctl_map32.start_code;
> +        prctl_map.end_code = prctl_map32.end_code;
> +        prctl_map.start_data = prctl_map32.start_data;
> +        prctl_map.end_data = prctl_map32.end_data;
> +        prctl_map.start_brk = prctl_map32.start_brk;
> +        prctl_map.brk = prctl_map32.brk;
> +        prctl_map.start_stack = prctl_map32.start_stack;
> +        prctl_map.arg_start = prctl_map32.arg_start;
> +        prctl_map.arg_end = prctl_map32.arg_end;
> +        prctl_map.env_start = prctl_map32.env_start;
> +        prctl_map.env_end = prctl_map32.env_end;
> +        prctl_map.auxv = compat_ptr(prctl_map32.auxv);
> +        prctl_map.auxv_size = prctl_map32.auxv_size;
> +        prctl_map.exe_fd = prctl_map32.exe_fd;
> +    } else
> +#endif
>    if (copy_from_user(&prctl_map, addr, sizeof(prctl_map)))
>        return -EFAULT;
> 
> -- 
> 1.7.12.4
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] prctl: fix compat handling for prctl
  2018-04-19  1:06 [PATCH v2] prctl: fix compat handling for prctl Li Bin
  2018-04-19  1:35 ` Andy Lutomirski
@ 2018-04-19  2:25 ` Andy Lutomirski
  2018-04-19  6:03   ` Libin (Huawei)
  2018-04-26 21:13   ` Dmitry Safonov
  1 sibling, 2 replies; 5+ messages in thread
From: Andy Lutomirski @ 2018-04-19  2:25 UTC (permalink / raw)
  To: Li Bin
  Cc: Al Viro, Eric W. Biederman, Dominik Brodowski, Andrew Morton,
	Andy Lutomirski, LKML, Hanjun Guo

> On Apr 18, 2018, at 9:06 PM, Li Bin <huawei.libin@huawei.com> wrote:
>
> The member auxv in prctl_mm_map structure which be shared with
> userspace is pointer type, but the kernel supporting COMPAT didn't
> handle it. This patch fix the compat handling for prctl syscall.

I would propose an alternative fix: change the type to u64. As far as
I know, this thing is only used by CRIU, and CRIU doesn’t work (AFAIK)
on native 32-bit anyway.   Do you know of some reason that this
wouldn't work?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] prctl: fix compat handling for prctl
  2018-04-19  2:25 ` Andy Lutomirski
@ 2018-04-19  6:03   ` Libin (Huawei)
  2018-04-26 21:13   ` Dmitry Safonov
  1 sibling, 0 replies; 5+ messages in thread
From: Libin (Huawei) @ 2018-04-19  6:03 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Al Viro, Eric W. Biederman, Dominik Brodowski, Andrew Morton,
	LKML, Hanjun Guo



在 2018/4/19 10:25, Andy Lutomirski 写道:
>> On Apr 18, 2018, at 9:06 PM, Li Bin <huawei.libin@huawei.com> wrote:
>>
>> The member auxv in prctl_mm_map structure which be shared with
>> userspace is pointer type, but the kernel supporting COMPAT didn't
>> handle it. This patch fix the compat handling for prctl syscall.
> 
> I would propose an alternative fix: change the type to u64. As far as

But we also need to modify the sys/prctl.h in Glibc, right?

> I know, this thing is only used by CRIU, and CRIU doesn’t work (AFAIK)
> on native 32-bit anyway.   Do you know of some reason that this
> wouldn't work?
> 
> .
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] prctl: fix compat handling for prctl
  2018-04-19  2:25 ` Andy Lutomirski
  2018-04-19  6:03   ` Libin (Huawei)
@ 2018-04-26 21:13   ` Dmitry Safonov
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry Safonov @ 2018-04-26 21:13 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Li Bin, Al Viro, Eric W. Biederman, Dominik Brodowski,
	Andrew Morton, LKML, Hanjun Guo

2018-04-19 3:25 GMT+01:00 Andy Lutomirski <luto@kernel.org>:
>> On Apr 18, 2018, at 9:06 PM, Li Bin <huawei.libin@huawei.com> wrote:
>>
>> The member auxv in prctl_mm_map structure which be shared with
>> userspace is pointer type, but the kernel supporting COMPAT didn't
>> handle it. This patch fix the compat handling for prctl syscall.
>
> I would propose an alternative fix: change the type to u64. As far as
> I know, this thing is only used by CRIU, and CRIU doesn’t work (AFAIK)
> on native 32-bit anyway.

Yeah, it's right - CRIU doesn't work on native 32-bit and no support planned.

Thanks,
             Dmitry

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-26 21:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19  1:06 [PATCH v2] prctl: fix compat handling for prctl Li Bin
2018-04-19  1:35 ` Andy Lutomirski
2018-04-19  2:25 ` Andy Lutomirski
2018-04-19  6:03   ` Libin (Huawei)
2018-04-26 21:13   ` Dmitry Safonov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.