Skip to content

Commit 172a0f5

Browse files
Murad Masimovtiwai
authored andcommitted
ALSA: usx2y: validate nrpacks module parameter on probe
The module parameter defines number of iso packets per one URB. User is allowed to set any value to the parameter of type int, which can lead to various kinds of weird and incorrect behavior like integer overflows, truncations, etc. Number of packets should be a small non-negative number. Since this parameter is read-only, its value can be validated on driver probe. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Murad Masimov <m.masimov@mt-integration.ru> Link: https://patch.msgid.link/20250303100413.835-1-m.masimov@mt-integration.ru Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent f603b15 commit 172a0f5

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

sound/usb/usx2y/usbusx2y.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ static int snd_usx2y_card_used[SNDRV_CARDS];
151151
static void snd_usx2y_card_private_free(struct snd_card *card);
152152
static void usx2y_unlinkseq(struct snd_usx2y_async_seq *s);
153153

154+
#ifdef USX2Y_NRPACKS_VARIABLE
155+
int nrpacks = USX2Y_NRPACKS; /* number of packets per urb */
156+
module_param(nrpacks, int, 0444);
157+
MODULE_PARM_DESC(nrpacks, "Number of packets per URB.");
158+
#endif
159+
154160
/*
155161
* pipe 4 is used for switching the lamps, setting samplerate, volumes ....
156162
*/
@@ -432,6 +438,11 @@ static int snd_usx2y_probe(struct usb_interface *intf,
432438
struct snd_card *card;
433439
int err;
434440

441+
#ifdef USX2Y_NRPACKS_VARIABLE
442+
if (nrpacks < 0 || nrpacks > USX2Y_NRPACKS_MAX)
443+
return -EINVAL;
444+
#endif
445+
435446
if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 ||
436447
(le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 &&
437448
le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 &&

sound/usb/usx2y/usbusx2y.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@
77

88
#define NRURBS 2
99

10+
/* Default value used for nr of packs per urb.
11+
* 1 to 4 have been tested ok on uhci.
12+
* To use 3 on ohci, you'd need a patch:
13+
* look for "0000425-linux-2.6.9-rc4-mm1_ohci-hcd.patch.gz" on
14+
* "https://bugtrack.alsa-project.org/alsa-bug/bug_view_page.php?bug_id=0000425"
15+
*
16+
* 1, 2 and 4 work out of the box on ohci, if I recall correctly.
17+
* Bigger is safer operation, smaller gives lower latencies.
18+
*/
19+
#define USX2Y_NRPACKS 4
20+
21+
#define USX2Y_NRPACKS_MAX 1024
22+
23+
/* If your system works ok with this module's parameter
24+
* nrpacks set to 1, you might as well comment
25+
* this define out, and thereby produce smaller, faster code.
26+
* You'd also set USX2Y_NRPACKS to 1 then.
27+
*/
28+
#define USX2Y_NRPACKS_VARIABLE 1
29+
30+
#ifdef USX2Y_NRPACKS_VARIABLE
31+
extern int nrpacks;
32+
#define nr_of_packs() nrpacks
33+
#else
34+
#define nr_of_packs() USX2Y_NRPACKS
35+
#endif
1036

1137
#define URBS_ASYNC_SEQ 10
1238
#define URB_DATA_LEN_ASYNC_SEQ 32

sound/usb/usx2y/usbusx2yaudio.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,6 @@
2828
#include "usx2y.h"
2929
#include "usbusx2y.h"
3030

31-
/* Default value used for nr of packs per urb.
32-
* 1 to 4 have been tested ok on uhci.
33-
* To use 3 on ohci, you'd need a patch:
34-
* look for "0000425-linux-2.6.9-rc4-mm1_ohci-hcd.patch.gz" on
35-
* "https://bugtrack.alsa-project.org/alsa-bug/bug_view_page.php?bug_id=0000425"
36-
*
37-
* 1, 2 and 4 work out of the box on ohci, if I recall correctly.
38-
* Bigger is safer operation, smaller gives lower latencies.
39-
*/
40-
#define USX2Y_NRPACKS 4
41-
42-
/* If your system works ok with this module's parameter
43-
* nrpacks set to 1, you might as well comment
44-
* this define out, and thereby produce smaller, faster code.
45-
* You'd also set USX2Y_NRPACKS to 1 then.
46-
*/
47-
#define USX2Y_NRPACKS_VARIABLE 1
48-
49-
#ifdef USX2Y_NRPACKS_VARIABLE
50-
static int nrpacks = USX2Y_NRPACKS; /* number of packets per urb */
51-
#define nr_of_packs() nrpacks
52-
module_param(nrpacks, int, 0444);
53-
MODULE_PARM_DESC(nrpacks, "Number of packets per URB.");
54-
#else
55-
#define nr_of_packs() USX2Y_NRPACKS
56-
#endif
57-
5831
static int usx2y_urb_capt_retire(struct snd_usx2y_substream *subs)
5932
{
6033
struct urb *urb = subs->completed_urb;

0 commit comments

Comments
 (0)