public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] net: fix compat pointer in get_compat_msghdr()
@ 2022-07-15 22:03 Jens Axboe
       [not found] ` <CGME20220716204701eucas1p1cd9d17857b50339074b22320373ef1b6@eucas1p1.samsung.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2022-07-15 22:03 UTC (permalink / raw)
  To: io-uring, netdev; +Cc: Dylan Yudaken

A previous change enabled external users to copy the data before
calling __get_compat_msghdr(), but didn't modify get_compat_msghdr() or
__io_compat_recvmsg_copy_hdr() to take that into account. They are both
stil passing in the __user pointer rather than the copied version.

Ensure we pass in the kernel struct, not the pointer to the user data.

Link: https://lore.kernel.org/all/[email protected]/
Fixes: 1a3e4e94a1b9 ("net: copy from user before calling __get_compat_msghdr")
Reported-by: Marek Szyprowski <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>

---

As this was staged in the io_uring tree, I plan on applying this fix
there as well. Holler if anyone disagrees.

diff --git a/io_uring/net.c b/io_uring/net.c
index 6b7d5f33e642..e61efa31c729 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -398,7 +398,7 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
 	if (copy_from_user(&msg, sr->umsg_compat, sizeof(msg)))
 		return -EFAULT;
 
-	ret = __get_compat_msghdr(&iomsg->msg, sr->umsg_compat, &iomsg->uaddr);
+	ret = __get_compat_msghdr(&iomsg->msg, &msg, &iomsg->uaddr);
 	if (ret)
 		return ret;
 
diff --git a/net/compat.c b/net/compat.c
index 513aa9a3fc64..ed880729d159 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -89,7 +89,7 @@ int get_compat_msghdr(struct msghdr *kmsg,
 	if (copy_from_user(&msg, umsg, sizeof(*umsg)))
 		return -EFAULT;
 
-	err = __get_compat_msghdr(kmsg, umsg, save_addr);
+	err = __get_compat_msghdr(kmsg, &msg, save_addr);
 	if (err)
 		return err;
 
-- 
Jens Axboe


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

* Re: [PATCH] net: fix compat pointer in get_compat_msghdr()
       [not found] ` <CGME20220716204701eucas1p1cd9d17857b50339074b22320373ef1b6@eucas1p1.samsung.com>
@ 2022-07-16 20:47   ` Marek Szyprowski
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Szyprowski @ 2022-07-16 20:47 UTC (permalink / raw)
  To: Jens Axboe, io-uring, netdev; +Cc: Dylan Yudaken

On 16.07.2022 00:03, Jens Axboe wrote:
> A previous change enabled external users to copy the data before
> calling __get_compat_msghdr(), but didn't modify get_compat_msghdr() or
> __io_compat_recvmsg_copy_hdr() to take that into account. They are both
> stil passing in the __user pointer rather than the copied version.
>
> Ensure we pass in the kernel struct, not the pointer to the user data.
>
> Link: https://lore.kernel.org/all/[email protected]/
> Fixes: 1a3e4e94a1b9 ("net: copy from user before calling __get_compat_msghdr")
> Reported-by: Marek Szyprowski <[email protected]>
> Signed-off-by: Jens Axboe <[email protected]>

This fixes the issue I've reported.

Tested-by: Marek Szyprowski <[email protected]>

> ---
>
> As this was staged in the io_uring tree, I plan on applying this fix
> there as well. Holler if anyone disagrees.
>
> diff --git a/io_uring/net.c b/io_uring/net.c
> index 6b7d5f33e642..e61efa31c729 100644
> --- a/io_uring/net.c
> +++ b/io_uring/net.c
> @@ -398,7 +398,7 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
>   	if (copy_from_user(&msg, sr->umsg_compat, sizeof(msg)))
>   		return -EFAULT;
>   
> -	ret = __get_compat_msghdr(&iomsg->msg, sr->umsg_compat, &iomsg->uaddr);
> +	ret = __get_compat_msghdr(&iomsg->msg, &msg, &iomsg->uaddr);
>   	if (ret)
>   		return ret;
>   
> diff --git a/net/compat.c b/net/compat.c
> index 513aa9a3fc64..ed880729d159 100644
> --- a/net/compat.c
> +++ b/net/compat.c
> @@ -89,7 +89,7 @@ int get_compat_msghdr(struct msghdr *kmsg,
>   	if (copy_from_user(&msg, umsg, sizeof(*umsg)))
>   		return -EFAULT;
>   
> -	err = __get_compat_msghdr(kmsg, umsg, save_addr);
> +	err = __get_compat_msghdr(kmsg, &msg, save_addr);
>   	if (err)
>   		return err;
>   

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

end of thread, other threads:[~2022-07-16 20:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-15 22:03 [PATCH] net: fix compat pointer in get_compat_msghdr() Jens Axboe
     [not found] ` <CGME20220716204701eucas1p1cd9d17857b50339074b22320373ef1b6@eucas1p1.samsung.com>
2022-07-16 20:47   ` Marek Szyprowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox