Linux Media Controller development
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: Yousef Alhouseen <alhouseenyousef@gmail.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Vivek Kasireddy <vivek.kasireddy@intel.com>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
	linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-buf: udmabuf: avoid list copy size overflow
Date: Fri, 26 Jun 2026 12:31:39 +0100	[thread overview]
Message-ID: <20260626123139.7d6ec6ec@pumpkin> (raw)
In-Reply-To: <06bddfca-d868-4043-ac6f-28ca103fff02@amd.com>

On Wed, 24 Jun 2026 14:58:58 +0200
Christian König <christian.koenig@amd.com> wrote:

> On 6/24/26 14:52, Yousef Alhouseen wrote:
> > UDMABUF_CREATE_LIST copies an array whose element count comes from
> > userspace. The count is compared against list_limit, but list_limit is a
> > signed module parameter while the count is u32.  
> 
> We should probably just drop the sign from the module parameter instead.

Does anything sanity-check the module parameter?

	David

> 
> I don't see an use case for negative values here.
> 
> Regards,
> Christian.
> 
> > 
> > If the limit is raised too far or made negative, that comparison no
> > longer bounds the count to a range where sizeof(*list) * count fits in
> > the u32 temporary used for the copy length. A wrapped copy length lets
> > memdup_user() copy fewer entries than udmabuf_create() subsequently
> > walks, leading to out-of-bounds reads from the copied list.
> > 
> > Take a positive snapshot of the module limit and use memdup_array_user()
> > so the multiplication is checked before copying.
> > 
> > Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
> > ---
> >  drivers/dma-buf/udmabuf.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
> > index bced421c0..b4078ec84 100644
> > --- a/drivers/dma-buf/udmabuf.c
> > +++ b/drivers/dma-buf/udmabuf.c
> > @@ -469,14 +469,15 @@ static long udmabuf_ioctl_create_list(struct file *filp, unsigned long arg)
> >         struct udmabuf_create_list head;
> >         struct udmabuf_create_item *list;
> >         int ret = -EINVAL;
> > -       u32 lsize;
> > +       int limit;
> > 
> >         if (copy_from_user(&head, (void __user *)arg, sizeof(head)))
> >                 return -EFAULT;
> > -       if (head.count > list_limit)
> > +       limit = READ_ONCE(list_limit);
> > +       if (!head.count || limit <= 0 || head.count > limit)
> >                 return -EINVAL;
> > -       lsize = sizeof(struct udmabuf_create_item) * head.count;
> > -       list = memdup_user((void __user *)(arg + sizeof(head)), lsize);
> > +       list = memdup_array_user((void __user *)(arg + sizeof(head)),
> > +                                head.count, sizeof(*list));
> >         if (IS_ERR(list))
> >                 return PTR_ERR(list);
> > 
> > --
> > 2.54.0
> >   
> 
> 


  parent reply	other threads:[~2026-06-26 11:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 12:52 [PATCH] dma-buf: udmabuf: avoid list copy size overflow Yousef Alhouseen
2026-06-24 12:58 ` Christian König
2026-06-25  9:07   ` Yousef Alhouseen
2026-06-26 11:31   ` David Laight [this message]
2026-06-26 12:23     ` Christian König

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=20260626123139.7d6ec6ec@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=alhouseenyousef@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=vivek.kasireddy@intel.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