* [PATCH] ALSA: es18xx: check control allocation before private data setup
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: gus: check PCM volume control allocation Ruoyu Wang
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_es18xx_mixer() creates controls with snd_ctl_new1() and then stores
hardware-volume bookkeeping in the returned control before calling
snd_ctl_add(). snd_ctl_new1() can return NULL on allocation failure, so
those private_free writes can dereference NULL before snd_ctl_add() gets a
chance to reject the missing control.
Check the returned control pointers before using them and return -ENOMEM
on allocation failure.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/isa/es18xx.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 1da7b400a17b6..2f454f7797ce2 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -1762,6 +1762,8 @@ static int snd_es18xx_mixer(struct snd_card *card)
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
struct snd_kcontrol *kctl;
kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip);
+ if (!kctl)
+ return -ENOMEM;
if (chip->caps & ES18XX_HWV) {
switch (idx) {
case 0:
@@ -1823,6 +1825,8 @@ static int snd_es18xx_mixer(struct snd_card *card)
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) {
struct snd_kcontrol *kctl;
kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip);
+ if (!kctl)
+ return -ENOMEM;
if (idx == 0)
chip->hw_volume = kctl;
else
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: gus: check PCM volume control allocation
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: es18xx: check control allocation before private data setup Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: cmipci: check S/PDIF control allocations Ruoyu Wang
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_gf1_pcm_new() creates a PCM volume control and then updates
kctl->id.index before adding it to the card. snd_ctl_new1() can return
NULL on allocation failure, so the id update can dereference NULL before
snd_ctl_add() can handle the error.
Return -ENOMEM when the control allocation fails.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/isa/gus/gus_pcm.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index a0757e1ede465..08ccb4d80adeb 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -851,6 +851,8 @@ int snd_gf1_pcm_new(struct snd_gus_card *gus, int pcm_dev, int control_index)
kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control1, gus);
else
kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control, gus);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.index = control_index;
err = snd_ctl_add(card, kctl);
if (err < 0)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: cmipci: check S/PDIF control allocations
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: es18xx: check control allocation before private data setup Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: gus: check PCM volume control allocation Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: es1938: check control allocation before private data setup Ruoyu Wang
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_cmipci_mixer_new() creates several S/PDIF controls and adjusts
kctl->id.device before adding each control to the card. If snd_ctl_new1()
returns NULL, the id update dereferences NULL before snd_ctl_add() can
reject the missing control.
Check each S/PDIF control allocation before setting the device id.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/pci/cmipci.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index cd73b68336394..ff4bfbf94b81b 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2637,16 +2637,22 @@ static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
}
if (cm->can_ac3_hw) {
kctl = snd_ctl_new1(&snd_cmipci_spdif_default, cm);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = pcm_spdif_device;
err = snd_ctl_add(card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_cmipci_spdif_mask, cm);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = pcm_spdif_device;
err = snd_ctl_add(card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_cmipci_spdif_stream, cm);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = pcm_spdif_device;
err = snd_ctl_add(card, kctl);
if (err < 0)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: es1938: check control allocation before private data setup
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
` (2 preceding siblings ...)
2026-06-07 2:56 ` [PATCH] ALSA: cmipci: check S/PDIF control allocations Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: ice1712: aureon: check CS8415 control allocation Ruoyu Wang
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_es1938_mixer() creates mixer controls with snd_ctl_new1() and then
stores hardware-volume pointers and private_free hooks in the returned
controls before calling snd_ctl_add(). snd_ctl_new1() can return NULL on
allocation failure, so these setup writes can dereference NULL.
Check the allocation result before using the control pointer.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/pci/es1938.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 280125eff3624..b6dcb721fffce 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1655,6 +1655,8 @@ static int snd_es1938_mixer(struct es1938 *chip)
for (idx = 0; idx < ARRAY_SIZE(snd_es1938_controls); idx++) {
struct snd_kcontrol *kctl;
kctl = snd_ctl_new1(&snd_es1938_controls[idx], chip);
+ if (!kctl)
+ return -ENOMEM;
switch (idx) {
case 0:
chip->master_volume = kctl;
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: ice1712: aureon: check CS8415 control allocation
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
` (3 preceding siblings ...)
2026-06-07 2:56 ` [PATCH] ALSA: es1938: check control allocation before private data setup Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: ice1712: check pro S/PDIF control allocations Ruoyu Wang
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
aureon_add_controls() creates CS8415 controls and, for later entries,
adjusts kctl->id.device before adding the control. snd_ctl_new1() can
return NULL, so the device-id update can dereference NULL before the
control core sees the pointer.
Return -ENOMEM when the control allocation fails.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/pci/ice1712/aureon.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 1191a2686dfd2..d6abff2978f3d 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -1891,6 +1891,8 @@ static int aureon_add_controls(struct snd_ice1712 *ice)
for (i = 0; i < ARRAY_SIZE(cs8415_controls); i++) {
struct snd_kcontrol *kctl;
kctl = snd_ctl_new1(&cs8415_controls[i], ice);
+ if (!kctl)
+ return -ENOMEM;
if (i > 1)
kctl->id.device = ice->pcm->device;
err = snd_ctl_add(ice->card, kctl);
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: ice1712: check pro S/PDIF control allocations
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
` (4 preceding siblings ...)
2026-06-07 2:56 ` [PATCH] ALSA: ice1712: aureon: check CS8415 control allocation Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: ice1724: check " Ruoyu Wang
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_ice1712_spdif_build_controls() creates pro S/PDIF controls and then
sets kctl->id.device before calling snd_ctl_add(). snd_ctl_new1() can
return NULL on allocation failure, making the device-id write a NULL
pointer dereference.
Check each control allocation before using the returned pointer.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/pci/ice1712/ice1712.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 1e39b985bef26..4cec56769c0f6 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2346,21 +2346,29 @@ int snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
if (snd_BUG_ON(!ice->pcm_pro))
return -EIO;
kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm_pro->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm_pro->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm_pro->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm_pro->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: ice1724: check S/PDIF control allocations
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
` (5 preceding siblings ...)
2026-06-07 2:56 ` [PATCH] ALSA: ice1712: check pro S/PDIF control allocations Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 2:56 ` [PATCH] ALSA: ymfpci: " Ruoyu Wang
2026-06-07 7:27 ` [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Takashi Iwai
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_vt1724_spdif_build_controls() creates S/PDIF controls and then sets
kctl->id.device before calling snd_ctl_add(). snd_ctl_new1() can return
NULL on allocation failure, so these device-id writes can dereference
NULL.
Check each live control allocation before using the returned pointer.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/pci/ice1712/ice1724.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 65bf48647d089..b16c84983b81a 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -2379,16 +2379,22 @@ static int snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
return err;
kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = ice->pcm->device;
err = snd_ctl_add(ice->card, kctl);
if (err < 0)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] ALSA: ymfpci: check S/PDIF control allocations
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
` (6 preceding siblings ...)
2026-06-07 2:56 ` [PATCH] ALSA: ice1724: check " Ruoyu Wang
@ 2026-06-07 2:56 ` Ruoyu Wang
2026-06-07 7:27 ` [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Takashi Iwai
8 siblings, 0 replies; 10+ messages in thread
From: Ruoyu Wang @ 2026-06-07 2:56 UTC (permalink / raw)
To: tiwai; +Cc: alsa-devel, linux-kernel, Ruoyu Wang
snd_ymfpci_mixer() creates S/PDIF controls and then sets kctl->id.device
before adding each control. snd_ctl_new1() can return NULL on allocation
failure, and snd_ctl_add() cannot protect these earlier id writes.
Check the control allocation results before using them.
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
sound/pci/ymfpci/ymfpci_main.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index b9a09568afc9e..2ccb976e68e0b 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -1781,16 +1781,22 @@ int snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch)
if (snd_BUG_ON(!chip->pcm_spdif))
return -ENXIO;
kctl = snd_ctl_new1(&snd_ymfpci_spdif_default, chip);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = chip->pcm_spdif->device;
err = snd_ctl_add(chip->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_ymfpci_spdif_mask, chip);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = chip->pcm_spdif->device;
err = snd_ctl_add(chip->card, kctl);
if (err < 0)
return err;
kctl = snd_ctl_new1(&snd_ymfpci_spdif_stream, chip);
+ if (!kctl)
+ return -ENOMEM;
kctl->id.device = chip->pcm_spdif->device;
err = snd_ctl_add(chip->card, kctl);
if (err < 0)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing
2026-06-07 2:56 [PATCH 0/8] ALSA: check snd_ctl_new1() return before dereferencing Ruoyu Wang
` (7 preceding siblings ...)
2026-06-07 2:56 ` [PATCH] ALSA: ymfpci: " Ruoyu Wang
@ 2026-06-07 7:27 ` Takashi Iwai
8 siblings, 0 replies; 10+ messages in thread
From: Takashi Iwai @ 2026-06-07 7:27 UTC (permalink / raw)
To: Ruoyu Wang; +Cc: alsa-devel, linux-kernel
On Sun, 07 Jun 2026 04:56:05 +0200,
Ruoyu Wang wrote:
>
> Several ALSA drivers dereference the pointer returned by snd_ctl_new1()
> to adjust id.device, id.index, or store bookkeeping pointers before
> calling snd_ctl_add(). snd_ctl_new1() can return NULL on allocation
> failure, making these writes a NULL pointer dereference.
>
> This series adds NULL checks to all affected call sites found by static
> analysis.
>
> Ruoyu Wang (8):
> ALSA: es18xx: check control allocation before private data setup
> ALSA: gus: check PCM volume control allocation
> ALSA: cmipci: check S/PDIF control allocations
> ALSA: es1938: check control allocation before private data setup
> ALSA: ice1712: aureon: check CS8415 control allocation
> ALSA: ice1712: check pro S/PDIF control allocations
> ALSA: ice1724: check S/PDIF control allocations
> ALSA: ymfpci: check S/PDIF control allocations
Some of them seems to have been already applied or conflicting.
Please rebase on the latest for-next branch of sound.git tree and
resubmit.
thanks,
Takashi
^ permalink raw reply [flat|nested] 10+ messages in thread