From: sashiko-bot@kernel.org
To: "Timo Joannin" <timo.joannin@gmail.com>
Cc: "open list:USB WEBCAM GADGET" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] usb: gadget: uvc: remove su_mutex from configfs _show/_store callbacks
Date: Thu, 19 Nov 2026 16:30:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-223524@kernel.org> (raw)
In-Reply-To: <20261119161742.758715-1-timo.joannin@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: uvc: missing Fixes trailer for configfs su_mutex
deadlock fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] usb: gadget: uvc: u8 bLength truncation in
uvcg_extension_bm_controls_store() overflows heap [1]
--
commit a01d42011350eddd8e616a06c5a390f67d1d73f0
Author: Timo Joannin <timo.joannin@gmail.com>
> usb: gadget: uvc: remove su_mutex from configfs _show/_store callbacks
>
> Syzbot reported a possible deadlock when reading UVC configfs attributes:
>
> su_mutex->func_lock->tpg_instances_lock->i_mutex->frag_sem->su_mutex
>
> When calling _store or _show functions, the configfs framework
> already grabs a frag_sem lock in fs/configfs/file.c, which pins
> the ci_parent chain in memory making grabbing su_mutex
> inside _store and _show calls for protection obsolete.
>
> This su_mutex lock acquisition is what triggered lockdep.
>
> Remove mutex_lock(su_mutex) from the UVC configfs _store and _show
> calls to break the final frag_sem->su_mutex link. Furthermore,
> since color_match->refcnt was protected by su_mutex, protect it
> with opts->lock in uvcg_color_matching_*_store(),
> uvcg_format_allow_link(), and uvcg_format_drop_link().
>
> Reported-by: syzbot+caf0e2bd08dda787005d@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=caf0e2bd08dda787005d
> Signed-off-by: Timo Joannin <timo.joannin@gmail.com>
[Severity: Low]
Since this fixes the su_mutex deadlock introduced with UVC configfs support,
should the commit message include a Fixes tag?
Fixes: 46919a23ee87 ("usb: gadget: uvc: configfs support in uvc function")
> diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
> index b9af49940d5f2..d7594406f1753 100644
> --- a/drivers/usb/gadget/function/uvc_configfs.c
> +++ b/drivers/usb/gadget/function/uvc_configfs.c
[ ... ]
> @@ -1106,24 +1007,18 @@ static ssize_t uvcg_extension_bm_controls_show(struct config_item *item,
> }
> mutex_unlock(&opts->lock);
>
> - mutex_unlock(su_mutex);
> -
> return ret;
> }
>
> static ssize_t uvcg_extension_bm_controls_store(struct config_item *item,
> const char *page, size_t len)
> {
> - struct config_group *group = to_config_group(item->ci_parent);
> - struct mutex *su_mutex = &group->cg_subsys->su_mutex;
> struct uvcg_extension *xu = to_uvcg_extension(item);
> struct config_item *opts_item;
> struct f_uvc_opts *opts;
> u8 *bm_controls, *iter;
> int ret, n = 0;
>
> - mutex_lock(su_mutex);
> -
> opts_item = item->ci_parent->ci_parent->ci_parent;
> opts = to_f_uvc_opts(opts_item);
>
> @@ -1157,7 +1052,6 @@ static ssize_t uvcg_extension_bm_controls_store(struct config_item *item,
>
> unlock:
> mutex_unlock(&opts->lock);
> - mutex_unlock(su_mutex);
> return ret;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can [1]
uvcg_extension_bm_controls_store() (along with
uvcg_extension_ba_source_id_store(), uvcg_extension_b_control_size_store(),
and uvcg_extension_b_nr_in_pins_store()) truncate xu->desc.bLength and
cause a heap buffer overflow in uvc_copy_descriptors()?
When 24 + bNrInPins + bControlSize >= 256, assigning
UVC_DT_EXTENSION_UNIT_SIZE(xu->desc.bNrInPins, xu->desc.bControlSize) to
the u8 xu->desc.bLength field wraps modulo 256 while bNrInPins and
bControlSize keep their larger values:
drivers/usb/gadget/function/uvc_configfs.c:uvcg_extension_bm_controls_store() {
...
xu->desc.bmControls = bm_controls;
xu->desc.bControlSize = n;
xu->desc.bLength = UVC_DT_EXTENSION_UNIT_SIZE(xu->desc.bNrInPins,
xu->desc.bControlSize);
...
}
During UDC bind, uvc_copy_descriptors() allocates mem using the truncated
xu->desc.bLength, and UVC_COPY_XU_DESCRIPTOR() then copies the full
24 + bNrInPins + bControlSize bytes into mem, overflowing the heap buffer.
[1] https://sashiko.dev/#/bug/linux-b5a5242b-262c-45f0-8665-4d268c233a8e
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119161742.758715-1-timo.joannin@gmail.com?part=1
prev parent reply other threads:[~2026-11-19 16:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:17 [PATCH] usb: gadget: uvc: remove su_mutex from configfs _show/_store callbacks Timo Joannin
2026-11-19 16:30 ` sashiko-bot [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=sashiko-outbox-223524@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=timo.joannin@gmail.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