From: "Michael S. Tsirkin" <mst@redhat.com>
To: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Cc: Guanjun <guanjun@linux.alibaba.com>,
error27@gmail.com, harshit.m.mogalapalli@gmail.com,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
Xie Yongji <xieyongji@bytedance.com>,
Maxime Coquelin <maxime.coquelin@redhat.com>,
Gautam Dawar <gautam.dawar@xilinx.com>,
Eli Cohen <elic@nvidia.com>
Subject: Re: [PATCH] vduse: Fix a possible warning in vduse_create_dev()
Date: Sat, 26 Nov 2022 18:22:09 -0500 [thread overview]
Message-ID: <20221126181822-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20221126040000.775914-1-harshit.m.mogalapalli@oracle.com>
On Fri, Nov 25, 2022 at 07:59:58PM -0800, Harshit Mogalapalli wrote:
> 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;
This is insufficient - the real source of the problem is that
vq_num is not validated.
The thing to do is to validate config and limit vq_num to 0xffff;
> --
> 2.38.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next parent reply other threads:[~2022-11-26 23:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20221126040000.775914-1-harshit.m.mogalapalli@oracle.com>
2022-11-26 23:22 ` Michael S. Tsirkin [this message]
[not found] ` <8253ab3f-b4f2-ff60-7e87-6455c9c10dc8@oracle.com>
2022-11-27 16:34 ` [PATCH] vduse: Fix a possible warning in vduse_create_dev() Michael S. Tsirkin
2022-11-28 4:13 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221126181822-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=elic@nvidia.com \
--cc=error27@gmail.com \
--cc=gautam.dawar@xilinx.com \
--cc=guanjun@linux.alibaba.com \
--cc=harshit.m.mogalapalli@gmail.com \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.coquelin@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xieyongji@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).