From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Rituparna Warwatkar <rwarwatkar@gmail.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Grzeschik <m.grzeschik@pengutronix.de>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Daniel Scally <dan.scally@ideasonboard.com>,
syzbot+54927260acba030187a6@syzkaller.appspotmail.com
Subject: Re: [PATCH] usb: gadget: uvc: don't pack struct uvcg_extension_unit_descriptor
Date: Sun, 2 Aug 2026 08:48:45 +0200 [thread overview]
Message-ID: <2026080223-turbojet-unsold-7290@gregkh> (raw)
In-Reply-To: <20260801163747.82910-1-rwarwatkar@gmail.com>
On Sat, Aug 01, 2026 at 06:37:47PM +0200, Rituparna Warwatkar wrote:
> kmemleak reports the baSourceID and bmControls arrays allocated by the
> UVC extension-unit configfs attributes as leaked, e.g.:
>
> BUG: memory leak
> unreferenced object 0xffff888114fee2c0 (size 8):
> __kmalloc_noprof
> uvcg_extension_ba_source_id_store
> configfs_write_iter
> vfs_write
> ksys_write
>
> The arrays are not actually leaked: they are reachable through
> xu->desc.baSourceID / xu->desc.bmControls and are freed when the
> extension unit is removed. The problem is that struct
> uvcg_extension_unit_descriptor is marked __packed, so these two heap
> pointers are stored at unaligned offsets (22 and 31). kmemleak only
> scans memory on pointer-aligned boundaries, so it never sees the
> pointers and reports the arrays as unreferenced.
>
> Unlike the UAPI struct uvc_extension_unit_descriptor, this is a purely
> in-memory staging structure: baSourceID and bmControls are pointers,
> not inline arrays, and the wire descriptor is assembled field by field
> in UVC_COPY_XU_DESCRIPTOR(). Nothing relies on the packed layout, so
> the __packed attribute is unnecessary and only serves to misalign the
> pointers.
>
> Drop __packed so the pointers are naturally aligned and visible to
> kmemleak, silencing the false positive.
>
> Fixes: 0525210c9840 ("usb: gadget: uvc: Allow definition of XUs in configfs")
> Reported-by: syzbot+54927260acba030187a6@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=54927260acba030187a6
> Signed-off-by: Rituparna Warwatkar <rwarwatkar@gmail.com>
> ---
> drivers/usb/gadget/function/uvc_configfs.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/uvc_configfs.h b/drivers/usb/gadget/function/uvc_configfs.h
> index 9391614135e..5a882afbce4 100644
> --- a/drivers/usb/gadget/function/uvc_configfs.h
> +++ b/drivers/usb/gadget/function/uvc_configfs.h
> @@ -176,7 +176,7 @@ struct uvcg_extension_unit_descriptor {
> u8 bControlSize;
> u8 *bmControls;
> u8 iExtension;
> -} __packed;
> +};
Why not rearrange the structure so that there is no space in it now
instead?
thanks,
greg k-h
prev parent reply other threads:[~2026-08-02 6:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-01 16:37 [PATCH] usb: gadget: uvc: don't pack struct uvcg_extension_unit_descriptor Rituparna Warwatkar
2026-08-02 6:48 ` Greg Kroah-Hartman [this message]
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=2026080223-turbojet-unsold-7290@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=dan.scally@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=m.grzeschik@pengutronix.de \
--cc=rwarwatkar@gmail.com \
--cc=syzbot+54927260acba030187a6@syzkaller.appspotmail.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