Skip to content

Commit 8a473c3

Browse files
fredoh9broonie
authored andcommitted
ASoC: Intel: Boards: cml_rt1011_rt5682: use statically define codec config
When the cml_rt1011_rt5682_dailink[].codecs pointer is overridden by a quirk with a devm allocated structure and the probe is deferred, in the next probe we will see an use-after-free condition (verified with KASAN). This can be avoided by using statically allocated configurations - which simplifies the code quite a bit as well. KASAN issue fixed. [ 23.301373] cml_rt1011_rt5682 cml_rt1011_rt5682: sof_rt1011_quirk = f [ 23.301875] ================================================================== [ 23.302018] BUG: KASAN: use-after-free in snd_cml_rt1011_probe+0x23a/0x3d0 [snd_soc_cml_rt1011_rt5682] [ 23.302178] Read of size 8 at addr ffff8881ec6acae0 by task kworker/0:2/105 [ 23.302320] CPU: 0 PID: 105 Comm: kworker/0:2 Not tainted 5.7.0-rc7-test+ #3 [ 23.302322] Hardware name: Google Helios/Helios, BIOS 01/21/2020 [ 23.302329] Workqueue: events deferred_probe_work_func [ 23.302331] Call Trace: [ 23.302339] dump_stack+0x76/0xa0 [ 23.302345] print_address_description.constprop.0.cold+0xd3/0x43e [ 23.302351] ? _raw_spin_lock_irqsave+0x7b/0xd0 [ 23.302355] ? _raw_spin_trylock_bh+0xf0/0xf0 [ 23.302362] ? snd_cml_rt1011_probe+0x23a/0x3d0 [snd_soc_cml_rt1011_rt5682] [ 23.302365] __kasan_report.cold+0x37/0x86 [ 23.302371] ? snd_cml_rt1011_probe+0x23a/0x3d0 [snd_soc_cml_rt1011_rt5682] [ 23.302375] kasan_report+0x38/0x50 [ 23.302382] snd_cml_rt1011_probe+0x23a/0x3d0 [snd_soc_cml_rt1011_rt5682] [ 23.302389] platform_drv_probe+0x66/0xc0 Fixes: 629ba12 ("ASoC: Intel: boards: split woofer and tweeter support") Suggested-by: Ranjani Sridharan <[email protected]> Signed-off-by: Fred Oh <[email protected]> Signed-off-by: Pierre-Louis Bossart <[email protected]> Reviewed-by: Ranjani Sridharan <[email protected]> Reviewed-by: Bard Liao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent e1a31c0 commit 8a473c3

File tree

1 file changed

+23
-60
lines changed

1 file changed

+23
-60
lines changed

sound/soc/intel/boards/cml_rt1011_rt5682.c

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#define SOF_RT1011_SPEAKER_WR BIT(1)
3535
#define SOF_RT1011_SPEAKER_TL BIT(2)
3636
#define SOF_RT1011_SPEAKER_TR BIT(3)
37-
#define SPK_CH 4
3837

3938
/* Default: Woofer speakers */
4039
static unsigned long sof_rt1011_quirk = SOF_RT1011_SPEAKER_WL |
@@ -383,10 +382,17 @@ SND_SOC_DAILINK_DEF(ssp0_codec,
383382

384383
SND_SOC_DAILINK_DEF(ssp1_pin,
385384
DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
386-
SND_SOC_DAILINK_DEF(ssp1_codec,
385+
SND_SOC_DAILINK_DEF(ssp1_codec_2spk,
387386
DAILINK_COMP_ARRAY(
388387
/* WL */ COMP_CODEC("i2c-10EC1011:00", CML_RT1011_CODEC_DAI),
389388
/* WR */ COMP_CODEC("i2c-10EC1011:01", CML_RT1011_CODEC_DAI)));
389+
SND_SOC_DAILINK_DEF(ssp1_codec_4spk,
390+
DAILINK_COMP_ARRAY(
391+
/* WL */ COMP_CODEC("i2c-10EC1011:00", CML_RT1011_CODEC_DAI),
392+
/* WR */ COMP_CODEC("i2c-10EC1011:01", CML_RT1011_CODEC_DAI),
393+
/* TL */ COMP_CODEC("i2c-10EC1011:02", CML_RT1011_CODEC_DAI),
394+
/* TR */ COMP_CODEC("i2c-10EC1011:03", CML_RT1011_CODEC_DAI)));
395+
390396

391397
SND_SOC_DAILINK_DEF(dmic_pin,
392398
DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
@@ -483,7 +489,7 @@ static struct snd_soc_dai_link cml_rt1011_rt5682_dailink[] = {
483489
.no_pcm = 1,
484490
.init = cml_rt1011_spk_init,
485491
.ops = &cml_rt1011_ops,
486-
SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
492+
SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec_2spk, platform),
487493
},
488494
};
489495

@@ -496,6 +502,15 @@ static struct snd_soc_codec_conf rt1011_conf[] = {
496502
.dlc = COMP_CODEC_CONF("i2c-10EC1011:01"),
497503
.name_prefix = "WR",
498504
},
505+
/* single configuration structure for 2 and 4 channels */
506+
{
507+
.dlc = COMP_CODEC_CONF("i2c-10EC1011:02"),
508+
.name_prefix = "TL",
509+
},
510+
{
511+
.dlc = COMP_CODEC_CONF("i2c-10EC1011:03"),
512+
.name_prefix = "TR",
513+
},
499514
};
500515

501516
/* Cometlake audio machine driver for RT1011 and RT5682 */
@@ -518,8 +533,6 @@ static struct snd_soc_card snd_soc_card_cml = {
518533

519534
static int snd_cml_rt1011_probe(struct platform_device *pdev)
520535
{
521-
struct snd_soc_dai_link_component *rt1011_dais_components;
522-
struct snd_soc_codec_conf *rt1011_dais_confs;
523536
struct card_private *ctx;
524537
struct snd_soc_acpi_mach *mach;
525538
const char *platform_name;
@@ -538,65 +551,15 @@ static int snd_cml_rt1011_probe(struct platform_device *pdev)
538551

539552
dev_dbg(&pdev->dev, "sof_rt1011_quirk = %lx\n", sof_rt1011_quirk);
540553

554+
/* when 4 speaker is available, update codec config */
541555
if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
542556
SOF_RT1011_SPEAKER_TR)) {
543-
rt1011_dais_confs = devm_kzalloc(&pdev->dev,
544-
sizeof(struct snd_soc_codec_conf) *
545-
SPK_CH, GFP_KERNEL);
546-
547-
if (!rt1011_dais_confs)
548-
return -ENOMEM;
549-
550-
rt1011_dais_components = devm_kzalloc(&pdev->dev,
551-
sizeof(struct snd_soc_dai_link_component) *
552-
SPK_CH, GFP_KERNEL);
553-
554-
if (!rt1011_dais_components)
555-
return -ENOMEM;
556-
557-
for (i = 0; i < SPK_CH; i++) {
558-
rt1011_dais_confs[i].dlc.name = devm_kasprintf(&pdev->dev,
559-
GFP_KERNEL,
560-
"i2c-10EC1011:0%d",
561-
i);
562-
563-
if (!rt1011_dais_confs[i].dlc.name)
564-
return -ENOMEM;
565-
566-
switch (i) {
567-
case 0:
568-
rt1011_dais_confs[i].name_prefix = "WL";
569-
break;
570-
case 1:
571-
rt1011_dais_confs[i].name_prefix = "WR";
572-
break;
573-
case 2:
574-
rt1011_dais_confs[i].name_prefix = "TL";
575-
break;
576-
case 3:
577-
rt1011_dais_confs[i].name_prefix = "TR";
578-
break;
579-
default:
580-
return -EINVAL;
581-
}
582-
rt1011_dais_components[i].name = devm_kasprintf(&pdev->dev,
583-
GFP_KERNEL,
584-
"i2c-10EC1011:0%d",
585-
i);
586-
if (!rt1011_dais_components[i].name)
587-
return -ENOMEM;
588-
589-
rt1011_dais_components[i].dai_name = CML_RT1011_CODEC_DAI;
590-
}
591-
592-
snd_soc_card_cml.codec_conf = rt1011_dais_confs;
593-
snd_soc_card_cml.num_configs = SPK_CH;
594-
595557
for (i = 0; i < ARRAY_SIZE(cml_rt1011_rt5682_dailink); i++) {
596558
if (!strcmp(cml_rt1011_rt5682_dailink[i].codecs->dai_name,
597-
CML_RT1011_CODEC_DAI)) {
598-
cml_rt1011_rt5682_dailink[i].codecs = rt1011_dais_components;
599-
cml_rt1011_rt5682_dailink[i].num_codecs = SPK_CH;
559+
CML_RT1011_CODEC_DAI)) {
560+
cml_rt1011_rt5682_dailink[i].codecs = ssp1_codec_4spk;
561+
cml_rt1011_rt5682_dailink[i].num_codecs =
562+
ARRAY_SIZE(ssp1_codec_4spk);
600563
}
601564
}
602565
}

0 commit comments

Comments
 (0)