Skip to contentSkip to conversation

net: fix compat pointer in get_compat_msghdr()

PATCH In review Jens Axboe 2 participants 2 messages Jul 15, 2022 – Jul 16, 2022

Subsystems (3)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 net: fix compat pointer in get_compat_msghdr()

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.

Fixes 1a3e4e94a1b9 ("net: copy from user before calling __get_compat_msghdr")

---

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

io_uring/net.c +1 -1
index 6b7d5f33e642..e61efa31c729 100644
@@ -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;
 
net/compat.c +1 -1
index 513aa9a3fc64..ed880729d159 100644
@@ -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;
 
Signature · 1 line
Jens Axboe
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jens Axboe

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.

Fixes 1a3e4e94a1b9 ("net: copy from user before calling __get_compat_msghdr")

This fixes the issue I've reported.

Quoted 23 lines

---

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

io_uring/net.c +1 -1
index 6b7d5f33e642..e61efa31c729 100644
@@ -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;
 
net/compat.c +0 -0
index 513aa9a3fc64..ed880729d159 100644

net/compat.c int get_compat_msghdr(struct msghdr *kmsg, · line 95

Quoted 8 lines
net/compat.c +1 -1
@@ -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

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland