All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vduse: Fix a possible warning in vduse_create_dev()
@ 2022-11-26  3:59 Harshit Mogalapalli
  2022-11-26 23:22   ` Michael S. Tsirkin
  0 siblings, 1 reply; 9+ messages in thread
From: Harshit Mogalapalli @ 2022-11-26  3:59 UTC (permalink / raw)
  Cc: harshit.m.mogalapalli, error27, harshit.m.mogalapalli,
	Michael S. Tsirkin, Jason Wang, Xie Yongji, Gautam Dawar,
	Maxime Coquelin, Guanjun, Parav Pandit, Eli Cohen,
	virtualization, linux-kernel

As 'dev->vq_num' is user-controlled data, if user tries to allocate
memory larger than(>=) MAX_ORDER, then kcalloc() will fail, it
creates a stack trace and messes up dmesg with a warning.

Call trace:
-> vduse_ioctl
--> vduse_create_dev
'config->vq_num' is user data as it comes from ioctl, which is
assigned to 'dev->vq_num'.

Add __GFP_NOWARN in order to avoid too large allocation warning.
This is detected by static analysis using smatch.

Fixes: c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 35dceee3ed56..5e9546b16165 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1512,7 +1512,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
 	dev->config_size = config->config_size;
 	dev->vq_align = config->vq_align;
 	dev->vq_num = config->vq_num;
-	dev->vqs = kcalloc(dev->vq_num, sizeof(*dev->vqs), GFP_KERNEL);
+	dev->vqs = kcalloc(dev->vq_num, sizeof(*dev->vqs),
+			   GFP_KERNEL | __GFP_NOWARN);
 	if (!dev->vqs)
 		goto err_vqs;
 
-- 
2.38.1


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

end of thread, other threads:[~2022-11-28  8:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26  3:59 [PATCH] vduse: Fix a possible warning in vduse_create_dev() Harshit Mogalapalli
2022-11-26 23:22 ` Michael S. Tsirkin
2022-11-26 23:22   ` Michael S. Tsirkin
2022-11-27  2:46   ` Harshit Mogalapalli
2022-11-27 16:34     ` Michael S. Tsirkin
2022-11-27 16:34       ` Michael S. Tsirkin
2022-11-28  4:13       ` Dan Carpenter
2022-11-28  4:13         ` Dan Carpenter
2022-11-28  8:38       ` Harshit Mogalapalli

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.