From: "Yannick Müller" <mail@ynnk.dev>
To: tiwai@suse.com, perex@perex.cz
Cc: linux-sound@vger.kernel.org, "Yannick Müller" <mail@ynnk.dev>
Subject: [PATCH 1/2] ALSA: usb-audio: Limit the depth of the clock topology walk
Date: Tue, 24 Nov 2026 14:25:50 +0100 [thread overview]
Message-ID: <20261124132551.137134-2-mail@ynnk.dev> (raw)
In-Reply-To: <20261124132551.137134-1-mail@ynnk.dev>
__uac_clock_find_source() recurses through clock selectors and
multipliers using entity IDs from the device's descriptors. The
visited bitmap stops loops, but a device can still chain up to 255
distinct clock entities. At about 96 bytes of stack per nested call
(x86-64, gcc 14) that is roughly 24 KB on a 16 KB kernel stack, so
a device with crafted descriptors can overflow it.
Pass the nesting depth down and fail with -EINVAL beyond 16 levels.
Signed-off-by: Yannick Müller <mail@ynnk.dev>
---
sound/usb/clock.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index cc77eace7b59..74f9923e5015 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -292,9 +292,12 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
return uac_clock_source_is_valid_quirk(chip, fmt, source_id);
}
+#define MAX_CLOCK_DEPTH 16
+
static int __uac_clock_find_source(struct snd_usb_audio *chip,
const struct audioformat *fmt, int entity_id,
- unsigned long *visited, bool validate)
+ unsigned long *visited, bool validate,
+ int depth)
{
union uac23_clock_source_desc *source;
union uac23_clock_selector_desc *selector;
@@ -307,6 +310,13 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
entity_id &= 0xff;
+ if (depth >= MAX_CLOCK_DEPTH) {
+ usb_audio_warn(chip,
+ "%s(): clock topology is too deep, id %d.\n",
+ __func__, entity_id);
+ return -EINVAL;
+ }
+
if (test_and_set_bit(entity_id, visited)) {
usb_audio_warn(chip,
"%s(): recursive clock topology detected, id %d.\n",
@@ -381,7 +391,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
cur = ret;
ret = __uac_clock_find_source(chip, fmt,
sources[ret - 1],
- visited, validate);
+ visited, validate, depth + 1);
if (ret > 0) {
/* Skip setting clock selector again for some devices */
if (chip->quirk_flags & QUIRK_FLAG_SKIP_CLOCK_SELECTOR ||
@@ -414,7 +424,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
ret = __uac_clock_find_source(chip, fmt,
sources[i - 1],
- visited, true);
+ visited, true, depth + 1);
if (ret < 0)
continue;
@@ -436,7 +446,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
if (multiplier)
return __uac_clock_find_source(chip, fmt,
GET_VAL(multiplier, proto, bCSourceID),
- visited, validate);
+ visited, validate, depth + 1);
return -EINVAL;
}
@@ -462,7 +472,7 @@ int snd_usb_clock_find_source(struct snd_usb_audio *chip,
case UAC_VERSION_2:
case UAC_VERSION_3:
return __uac_clock_find_source(chip, fmt, fmt->clock, visited,
- validate);
+ validate, 0);
default:
return -EINVAL;
}
--
2.47.3
next prev parent reply other threads:[~2026-11-24 13:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:25 [PATCH 0/2] ALSA: usb-audio: Limit recursion depth when walking audio units Yannick Müller
2026-11-24 13:25 ` Yannick Müller [this message]
2026-11-24 13:30 ` [PATCH 1/2] ALSA: usb-audio: Limit the depth of the clock topology walk sashiko-bot
2026-11-24 13:25 ` [PATCH 2/2] ALSA: usb-audio: Limit the unit nesting depth in the mixer parser Yannick Müller
2026-11-25 13:44 ` [PATCH 0/2] ALSA: usb-audio: Limit recursion depth when walking audio units Takashi Iwai
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=20261124132551.137134-2-mail@ynnk.dev \
--to=mail@ynnk.dev \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.