All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue
@ 2021-02-06  5:34 Sabyrzhan Tasbolatov
  2021-02-09  8:38 ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: Sabyrzhan Tasbolatov @ 2021-02-06  5:34 UTC (permalink / raw)
  To: arnd, gregkh; +Cc: alex.dewar90, linux-kernel, syzbot+15ec7391f3d6a1a7cc7d

syzbot found WARNING in qp_broker_alloc[1] in qp_host_alloc_queue()
when num_pages is 0x100001, giving queue_size + queue_page_size
bigger than KMALLOC_MAX_SIZE for kzalloc(), resulting order >= MAX_ORDER
condition.

queue_size + queue_page_size=0x8000d8, where KMALLOC_MAX_SIZE=0x400000.


FYI, I've also noticed in vmci_queue_pair.c other SLAB allocations with no
length check that might exceed KMALLOC_MAX_SIZE as well,
but syzbot doesn't have reproduces for them.

in qp_alloc_ppn_set():
	produce_ppns =
	    kmalloc_array(num_produce_pages, sizeof(*produce_ppns),
			  GFP_KERNEL);
[..]
	consume_ppns =
	    kmalloc_array(num_consume_pages, sizeof(*consume_ppns),
			  GFP_KERNEL);
[..]
in qp_alloc_hypercall():
	msg_size = sizeof(*alloc_msg) +
	    (size_t) entry->num_ppns * ppn_size;
	alloc_msg = kmalloc(msg_size, GFP_KERNEL);
[..]
in qp_broker_create():
	entry->local_mem = kcalloc(QPE_NUM_PAGES(entry->qp),
					   PAGE_SIZE, GFP_KERNEL);

[1]
Call Trace:
 alloc_pages include/linux/gfp.h:547 [inline]
 kmalloc_order+0x40/0x130 mm/slab_common.c:837
 kmalloc_order_trace+0x15/0x70 mm/slab_common.c:853
 kmalloc_large include/linux/slab.h:481 [inline]
 __kmalloc+0x257/0x330 mm/slub.c:3959
 kmalloc include/linux/slab.h:557 [inline]
 kzalloc include/linux/slab.h:682 [inline]
 qp_host_alloc_queue drivers/misc/vmw_vmci/vmci_queue_pair.c:540 [inline]
 qp_broker_create drivers/misc/vmw_vmci/vmci_queue_pair.c:1351 [inline]
 qp_broker_alloc+0x936/0x2740 drivers/misc/vmw_vmci/vmci_queue_pair.c:1739

Reported-by: syzbot+15ec7391f3d6a1a7cc7d@syzkaller.appspotmail.com
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index c49065887e8f..f6af406fda80 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -537,6 +537,11 @@ static struct vmci_queue *qp_host_alloc_queue(u64 size)
 
 	queue_page_size = num_pages * sizeof(*queue->kernel_if->u.h.page);
 
+	if (queue_size + queue_page_size > KMALLOC_MAX_SIZE) {
+		pr_warn("too big queue to allocate\n");
+		return NULL;
+	}
+
 	queue = kzalloc(queue_size + queue_page_size, GFP_KERNEL);
 	if (queue) {
 		queue->q_header = NULL;
-- 
2.25.1


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

end of thread, other threads:[~2021-02-09 10:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-06  5:34 [PATCH] drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue Sabyrzhan Tasbolatov
2021-02-09  8:38 ` Greg KH
2021-02-09  9:31   ` [PATCH v2] drivers/misc/vmw_vmci: restrict too big queue size in Sabyrzhan Tasbolatov
2021-02-09  9:32     ` Alex Dewar
2021-02-09  9:45       ` [PATCH v3] " Sabyrzhan Tasbolatov
2021-02-09  9:54         ` Greg KH
2021-02-09 10:26           ` [PATCH v4] drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue Sabyrzhan Tasbolatov
2021-02-09  9:49     ` [PATCH v2] drivers/misc/vmw_vmci: restrict too big queue size in Greg KH

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.