From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Haofeng Li <lihaofeng@kylinos.cn>
Cc: dan.scally@ideasonboard.com, gregkh@linuxfoundation.org,
xu.yang_2@nxp.com, hhhuuu@google.com, kees@kernel.org,
kai.aizen.dev@gmail.com, rdunlap@infradead.org,
christophe.jaillet@wanadoo.fr, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, 13266079573@163.com
Subject: Re: [PATCH v3] usb: gadget: f_uvc: fix Extension Unit descriptor heap overflow
Date: Mon, 24 Aug 2026 18:29:00 +0300 [thread overview]
Message-ID: <aoxjPAo6pKWOL82N@ashevche-desk.local> (raw)
In-Reply-To: <20260824094456.1562456-1-lihaofeng@kylinos.cn>
On Mon, Aug 24, 2026 at 05:44:56PM +0800, Haofeng Li wrote:
> An Extension Unit descriptor is 24 + bNrInPins + bControlSize bytes long
> (UVC_DT_EXTENSION_UNIT_SIZE(p, n)), where bNrInPins and bControlSize are
> configfs attributes each accepted over the full 0..255 range by
> kstrtou8(). uvc_configfs stores the computed size in the u8 bLength
> field of the descriptor, so once 24 + p + n exceeds 255 it silently
> wraps: p = n = 255 describes a 534-byte descriptor with bLength = 22.
>
> uvc_copy_descriptors() reserves xu->desc.bLength bytes per Extension Unit
> in the descriptor buffer it allocates at bind time, but
> UVC_COPY_XU_DESCRIPTOR() copies the real descriptor contents, i.e.
> 22 + bNrInPins + 1 + bControlSize + 1 bytes. With the wrapped length the
> copy overruns the allocation by up to 512 bytes.
>
> Attack chain (write access to a UVC gadget's configfs attributes; no
> race, no USB traffic, a single bind triggers it):
>
> echo 255 > .../functions/uvc.0/extensions/ext.0/b_nr_in_pins
> echo 255 > .../functions/uvc.0/extensions/ext.0/b_control_size
> -> uvcg_extension_b_nr_in_pins_store() /
> uvcg_extension_b_control_size_store()
> -> bLength = UVC_DT_EXTENSION_UNIT_SIZE(255, 255) wraps to 22
> bind the gadget to a UDC
> -> uvc_function_bind() -> uvc_copy_descriptors()
> -> kmalloc() sized using the wrapped bLength: 22 bytes for the XU
> -> UVC_COPY_XU_DESCRIPTOR() writes the real 534 bytes into that
> slot (22-byte head, 255 baSourceID, bControlSize, 255
> bmControls, iExtension)
> -> heap out-of-bounds write during bind
>
> Reproduced on 7.2.0+: a stock build (FORTIFY on) can derive the remaining
> allocation size at the bmControls memcpy and BUGs in __fortify_panic()
> during bind - a deterministic kernel crash; with FORTIFY disabled for the
> file, KASAN reports "slab-out-of-bounds Write of size 255" in
> uvc_copy_descriptors() against the kmalloc-192 descriptor buffer.
>
> Reject combinations whose descriptor does not fit into bLength at all four
> configfs entry points that can grow an Extension Unit (b_nr_in_pins,
> b_control_size, ba_source_id, bm_controls), and make uvc_copy_descriptors()
> refuse an Extension Unit whose bLength does not match its contents instead
> of overflowing the buffer.
>
> Fixes: 0525210c9840 ("usb: gadget: uvc: Allow definition of XUs in configfs")
> Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
> Assisted-by: opencode:deepseek-v4-flash-free
>
> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Should be no blank lines in the tag block. You may use `b4` tool (check your
Linux distro for the respective package) to automate that.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-08-24 15:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 19:47 [PATCH] " Haofeng Li
2026-08-22 20:01 ` Randy Dunlap
2026-08-22 20:26 ` Haofeng Li
2026-08-22 20:26 ` [PATCH v2] " Haofeng Li
2026-08-24 8:38 ` [PATCH] " Dan Scally
2026-08-24 9:44 ` [PATCH v3] " Haofeng Li
2026-08-24 15:29 ` Andy Shevchenko [this message]
2026-08-24 17:04 ` [PATCH v4] " Haofeng Li
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=aoxjPAo6pKWOL82N@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=13266079573@163.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.scally@ideasonboard.com \
--cc=gregkh@linuxfoundation.org \
--cc=hhhuuu@google.com \
--cc=kai.aizen.dev@gmail.com \
--cc=kees@kernel.org \
--cc=lihaofeng@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=xu.yang_2@nxp.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
all inboxes | Powered by JetHome®