linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vhost: handle zero regions in vhost_set_memory
@ 2022-02-21  7:28 Anirudh Rayabharam
  2022-02-21  7:56 ` Jason Wang
  2022-02-21 16:48 ` Stefano Garzarella
  0 siblings, 2 replies; 6+ messages in thread
From: Anirudh Rayabharam @ 2022-02-21  7:28 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang
  Cc: mail, syzbot+0abd373e2e50d704db87, kvm, virtualization, netdev,
	linux-kernel

Return early when userspace sends zero regions in the VHOST_SET_MEM_TABLE
ioctl.

Otherwise, this causes an erroneous entry to be added to the iotlb. This
entry has a range size of 0 (due to u64 overflow). This then causes
iotlb_access_ok() to loop indefinitely resulting in a hung thread.
Syzbot has reported this here:

https://syzkaller.appspot.com/bug?extid=0abd373e2e50d704db87

Reported-and-tested-by: syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com
Signed-off-by: Anirudh Rayabharam <mail@anirudhrb.com>
---
 drivers/vhost/vhost.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 59edb5a1ffe2..821aba60eac2 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1428,6 +1428,8 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
 		return -EFAULT;
 	if (mem.padding)
 		return -EOPNOTSUPP;
+	if (mem.nregions == 0)
+		return 0;
 	if (mem.nregions > max_mem_regions)
 		return -E2BIG;
 	newmem = kvzalloc(struct_size(newmem, regions, mem.nregions),
-- 
2.35.1


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

end of thread, other threads:[~2022-02-21 19:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21  7:28 [PATCH] vhost: handle zero regions in vhost_set_memory Anirudh Rayabharam
2022-02-21  7:56 ` Jason Wang
2022-02-21  8:11   ` Anirudh Rayabharam
2022-02-21 16:48 ` Stefano Garzarella
2022-02-21 17:59   ` Anirudh Rayabharam
2022-02-21 19:57   ` Anirudh Rayabharam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).