Skip to content

Commit ccfd614

Browse files
committed
ALSA: usb-audio: Fix out of bounds reads when finding clock sources
jira VULN-46526 cve CVE-2024-53150 commit-author Takashi Iwai <tiwai@suse.de> commit a3dd4d6 upstream-diff used linux-stable LT-5.4 sha a632bdc The current USB-audio driver code doesn't check bLength of each descriptor at traversing for clock descriptors. That is, when a device provides a bogus descriptor with a shorter bLength, the driver might hit out-of-bounds reads. For addressing it, this patch adds sanity checks to the validator functions for the clock descriptor traversal. When the descriptor length is shorter than expected, it's skipped in the loop. For the clock source and clock multiplier descriptors, we can just check bLength against the sizeof() of each descriptor type. OTOH, the clock selector descriptor of UAC2 and UAC3 has an array of bNrInPins elements and two more fields at its tail, hence those have to be checked in addition to the sizeof() check. Reported-by: Benoît Sevens <bsevens@google.com> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/20241121140613.3651-1-bsevens@google.com Link: https://patch.msgid.link/20241125144629.20757-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de> (cherry picked from commit a3dd4d6) Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
1 parent 59212ca commit ccfd614

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

sound/usb/clock.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include "clock.h"
3636
#include "quirks.h"
3737

38+
/* check whether the descriptor bLength has the minimal length */
39+
#define DESC_LENGTH_CHECK(p) \
40+
(p->bLength >= sizeof(*p))
41+
3842
static void *find_uac_clock_desc(struct usb_host_interface *iface, int id,
3943
bool (*validator)(void *, int), u8 type)
4044
{
@@ -52,36 +56,60 @@ static void *find_uac_clock_desc(struct usb_host_interface *iface, int id,
5256
static bool validate_clock_source_v2(void *p, int id)
5357
{
5458
struct uac_clock_source_descriptor *cs = p;
59+
if (!DESC_LENGTH_CHECK(cs))
60+
return false;
5561
return cs->bClockID == id;
5662
}
5763

5864
static bool validate_clock_source_v3(void *p, int id)
5965
{
6066
struct uac3_clock_source_descriptor *cs = p;
67+
if (!DESC_LENGTH_CHECK(cs))
68+
return false;
6169
return cs->bClockID == id;
6270
}
6371

6472
static bool validate_clock_selector_v2(void *p, int id)
6573
{
6674
struct uac_clock_selector_descriptor *cs = p;
67-
return cs->bClockID == id;
75+
if (!DESC_LENGTH_CHECK(cs))
76+
return false;
77+
if (cs->bClockID != id)
78+
return false;
79+
/* additional length check for baCSourceID array (in bNrInPins size)
80+
* and two more fields (which sizes depend on the protocol)
81+
*/
82+
return cs->bLength >= sizeof(*cs) + cs->bNrInPins +
83+
1 /* bmControls */ + 1 /* iClockSelector */;
6884
}
6985

7086
static bool validate_clock_selector_v3(void *p, int id)
7187
{
7288
struct uac3_clock_selector_descriptor *cs = p;
73-
return cs->bClockID == id;
89+
if (!DESC_LENGTH_CHECK(cs))
90+
return false;
91+
if (cs->bClockID != id)
92+
return false;
93+
/* additional length check for baCSourceID array (in bNrInPins size)
94+
* and two more fields (which sizes depend on the protocol)
95+
*/
96+
return cs->bLength >= sizeof(*cs) + cs->bNrInPins +
97+
4 /* bmControls */ + 2 /* wCSelectorDescrStr */;
7498
}
7599

76100
static bool validate_clock_multiplier_v2(void *p, int id)
77101
{
78102
struct uac_clock_multiplier_descriptor *cs = p;
103+
if (!DESC_LENGTH_CHECK(cs))
104+
return false;
79105
return cs->bClockID == id;
80106
}
81107

82108
static bool validate_clock_multiplier_v3(void *p, int id)
83109
{
84110
struct uac3_clock_multiplier_descriptor *cs = p;
111+
if (!DESC_LENGTH_CHECK(cs))
112+
return false;
85113
return cs->bClockID == id;
86114
}
87115

0 commit comments

Comments
 (0)