linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access
@ 2022-07-01  8:19 Brent Lu
  2022-07-01 10:58 ` Péter Ujfalusi
  2022-07-01 13:53 ` Pierre-Louis Bossart
  0 siblings, 2 replies; 4+ messages in thread
From: Brent Lu @ 2022-07-01  8:19 UTC (permalink / raw)
  To: alsa-devel
  Cc: Cezary Rojewski, Pierre-Louis Bossart, Liam Girdwood,
	Peter Ujfalusi, Bard Liao, Ranjani Sridharan, Kai Vehmanen,
	Mark Brown, Jaroslav Kysela, Takashi Iwai, Brent Lu, Yong Zhi,
	Mac Chiang, Ajye Huang, linux-kernel

Starting from ADL platform we have four HDMI PCM devices which exceeds
the size of sof_hdmi array. Since each sof_hdmi_pcm structure
represents one HDMI PCM device, we remove the sof_hdmi array and add a
new member hdmi_jack to the snd_soc_jack structure to fix the
out-of-bounds problem.

Signed-off-by: Brent Lu <brent.lu@intel.com>
---
 sound/soc/intel/boards/sof_rt5682.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c
index a24fb71d5ff3..1384716c6360 100644
--- a/sound/soc/intel/boards/sof_rt5682.c
+++ b/sound/soc/intel/boards/sof_rt5682.c
@@ -69,11 +69,10 @@ static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
 
 static int is_legacy_cpu;
 
-static struct snd_soc_jack sof_hdmi[3];
-
 struct sof_hdmi_pcm {
 	struct list_head head;
 	struct snd_soc_dai *codec_dai;
+	struct snd_soc_jack hdmi_jack;
 	int device;
 };
 
@@ -447,7 +446,6 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 	char jack_name[NAME_SIZE];
 	struct sof_hdmi_pcm *pcm;
 	int err;
-	int i = 0;
 
 	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
 	if (is_legacy_cpu || !ctx->idisp_codec)
@@ -468,17 +466,15 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 		snprintf(jack_name, sizeof(jack_name),
 			 "HDMI/DP, pcm=%d Jack", pcm->device);
 		err = snd_soc_card_jack_new(card, jack_name,
-					    SND_JACK_AVOUT, &sof_hdmi[i]);
+					    SND_JACK_AVOUT, &pcm->hdmi_jack);
 
 		if (err)
 			return err;
 
 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
-					  &sof_hdmi[i]);
+					  &pcm->hdmi_jack);
 		if (err < 0)
 			return err;
-
-		i++;
 	}
 
 	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access
  2022-07-01  8:19 [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access Brent Lu
@ 2022-07-01 10:58 ` Péter Ujfalusi
  2022-07-01 14:18   ` Lu, Brent
  2022-07-01 13:53 ` Pierre-Louis Bossart
  1 sibling, 1 reply; 4+ messages in thread
From: Péter Ujfalusi @ 2022-07-01 10:58 UTC (permalink / raw)
  To: Brent Lu, alsa-devel
  Cc: Cezary Rojewski, Kai Vehmanen, Takashi Iwai,
	Pierre-Louis Bossart, Ranjani Sridharan, Liam Girdwood,
	Mac Chiang, Mark Brown, Ajye Huang, Bard Liao, linux-kernel,
	Yong Zhi



On 01/07/2022 11:19, Brent Lu wrote:
> Starting from ADL platform we have four HDMI PCM devices which exceeds
> the size of sof_hdmi array. Since each sof_hdmi_pcm structure
> represents one HDMI PCM device, we remove the sof_hdmi array and add a
> new member hdmi_jack to the snd_soc_jack structure to fix the

"new member hdmi_jack to the sof_hdmi_pcm structure to fix the"

> out-of-bounds problem.

Other than that:
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

> Signed-off-by: Brent Lu <brent.lu@intel.com>
> ---
>  sound/soc/intel/boards/sof_rt5682.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c
> index a24fb71d5ff3..1384716c6360 100644
> --- a/sound/soc/intel/boards/sof_rt5682.c
> +++ b/sound/soc/intel/boards/sof_rt5682.c
> @@ -69,11 +69,10 @@ static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
>  
>  static int is_legacy_cpu;
>  
> -static struct snd_soc_jack sof_hdmi[3];
> -
>  struct sof_hdmi_pcm {
>  	struct list_head head;
>  	struct snd_soc_dai *codec_dai;
> +	struct snd_soc_jack hdmi_jack;
>  	int device;
>  };
>  
> @@ -447,7 +446,6 @@ static int sof_card_late_probe(struct snd_soc_card *card)
>  	char jack_name[NAME_SIZE];
>  	struct sof_hdmi_pcm *pcm;
>  	int err;
> -	int i = 0;
>  
>  	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
>  	if (is_legacy_cpu || !ctx->idisp_codec)
> @@ -468,17 +466,15 @@ static int sof_card_late_probe(struct snd_soc_card *card)
>  		snprintf(jack_name, sizeof(jack_name),
>  			 "HDMI/DP, pcm=%d Jack", pcm->device);
>  		err = snd_soc_card_jack_new(card, jack_name,
> -					    SND_JACK_AVOUT, &sof_hdmi[i]);
> +					    SND_JACK_AVOUT, &pcm->hdmi_jack);
>  
>  		if (err)
>  			return err;
>  
>  		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
> -					  &sof_hdmi[i]);
> +					  &pcm->hdmi_jack);
>  		if (err < 0)
>  			return err;
> -
> -		i++;
>  	}
>  
>  	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {

-- 
Péter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access
  2022-07-01  8:19 [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access Brent Lu
  2022-07-01 10:58 ` Péter Ujfalusi
@ 2022-07-01 13:53 ` Pierre-Louis Bossart
  1 sibling, 0 replies; 4+ messages in thread
From: Pierre-Louis Bossart @ 2022-07-01 13:53 UTC (permalink / raw)
  To: Brent Lu, alsa-devel
  Cc: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Yong Zhi, Mac Chiang, Ajye Huang, linux-kernel



On 7/1/22 03:19, Brent Lu wrote:
> Starting from ADL platform we have four HDMI PCM devices which exceeds
> the size of sof_hdmi array. Since each sof_hdmi_pcm structure
> represents one HDMI PCM device, we remove the sof_hdmi array and add a
> new member hdmi_jack to the snd_soc_jack structure to fix the
> out-of-bounds problem.

Valid fix aligned with other machine drivers, but the commit message is
incorrect: the 4th HDMI link was added in TGL, not ADL.

See e.g. 'Google Volteer', this quirk is already enabled:
SOF_RT5682_NUM_HDMIDEV(4)),

I guess existing topologies for Volteer never used the 4th link?

Wondering how we didn't this problem sooner - and if this needs to be
added to -stable, or if this is only needed for newer platforms.

> Signed-off-by: Brent Lu <brent.lu@intel.com>
> ---
>  sound/soc/intel/boards/sof_rt5682.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c
> index a24fb71d5ff3..1384716c6360 100644
> --- a/sound/soc/intel/boards/sof_rt5682.c
> +++ b/sound/soc/intel/boards/sof_rt5682.c
> @@ -69,11 +69,10 @@ static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
>  
>  static int is_legacy_cpu;
>  
> -static struct snd_soc_jack sof_hdmi[3];
> -
>  struct sof_hdmi_pcm {
>  	struct list_head head;
>  	struct snd_soc_dai *codec_dai;
> +	struct snd_soc_jack hdmi_jack;
>  	int device;
>  };
>  
> @@ -447,7 +446,6 @@ static int sof_card_late_probe(struct snd_soc_card *card)
>  	char jack_name[NAME_SIZE];
>  	struct sof_hdmi_pcm *pcm;
>  	int err;
> -	int i = 0;
>  
>  	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
>  	if (is_legacy_cpu || !ctx->idisp_codec)
> @@ -468,17 +466,15 @@ static int sof_card_late_probe(struct snd_soc_card *card)
>  		snprintf(jack_name, sizeof(jack_name),
>  			 "HDMI/DP, pcm=%d Jack", pcm->device);
>  		err = snd_soc_card_jack_new(card, jack_name,
> -					    SND_JACK_AVOUT, &sof_hdmi[i]);
> +					    SND_JACK_AVOUT, &pcm->hdmi_jack);
>  
>  		if (err)
>  			return err;
>  
>  		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
> -					  &sof_hdmi[i]);
> +					  &pcm->hdmi_jack);
>  		if (err < 0)
>  			return err;
> -
> -		i++;
>  	}
>  
>  	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access
  2022-07-01 10:58 ` Péter Ujfalusi
@ 2022-07-01 14:18   ` Lu, Brent
  0 siblings, 0 replies; 4+ messages in thread
From: Lu, Brent @ 2022-07-01 14:18 UTC (permalink / raw)
  To: Péter Ujfalusi, alsa-devel
  Cc: Rojewski, Cezary, Kai Vehmanen, Takashi Iwai,
	Pierre-Louis Bossart, Ranjani Sridharan, Liam Girdwood, Chiang,
	Mac, Mark Brown, Ajye Huang, Bard Liao, linux-kernel, Zhi, Yong

> On 01/07/2022 11:19, Brent Lu wrote:
> > Starting from ADL platform we have four HDMI PCM devices which exceeds
> > the size of sof_hdmi array. Since each sof_hdmi_pcm structure
> > represents one HDMI PCM device, we remove the sof_hdmi array and add a
> > new member hdmi_jack to the snd_soc_jack structure to fix the
> 
> "new member hdmi_jack to the sof_hdmi_pcm structure to fix the"
> 
> > out-of-bounds problem.
> 
> Other than that:
> Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
> 

Thanks for the review. Will fix it in V2 patch.

Brent


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-01 14:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01  8:19 [PATCH] ASoC: Intel: sof_rt5682: fix out-of-bounds array access Brent Lu
2022-07-01 10:58 ` Péter Ujfalusi
2022-07-01 14:18   ` Lu, Brent
2022-07-01 13:53 ` Pierre-Louis Bossart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).