linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: SOF: Intel: Check the bar size before remapping
@ 2022-04-09 14:39 Zheyu Ma
  2022-04-11 15:28 ` Pierre-Louis Bossart
  2022-04-13 17:36 ` Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Zheyu Ma @ 2022-04-09 14:39 UTC (permalink / raw)
  To: pierre-louis.bossart, lgirdwood, ranjani.sridharan, kai.vehmanen,
	broonie, perex, tiwai, peter.ujfalusi
  Cc: sound-open-firmware, alsa-devel, linux-kernel, Zheyu Ma

The driver should use the pci_resource_len() to get the actual length of
pci bar, and compare it with the expect value. If the bar size is too
small (such as a broken device), the driver should return an error.

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
---
 sound/soc/sof/intel/pci-tng.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sof/intel/pci-tng.c b/sound/soc/sof/intel/pci-tng.c
index 6efef225973f..7d502cc3ca80 100644
--- a/sound/soc/sof/intel/pci-tng.c
+++ b/sound/soc/sof/intel/pci-tng.c
@@ -75,7 +75,11 @@ static int tangier_pci_probe(struct snd_sof_dev *sdev)
 
 	/* LPE base */
 	base = pci_resource_start(pci, desc->resindex_lpe_base) - IRAM_OFFSET;
-	size = PCI_BAR_SIZE;
+	size = pci_resource_len(pci, desc->resindex_lpe_base);
+	if (size < PCI_BAR_SIZE) {
+		dev_err(sdev->dev, "error: I/O region is too small.\n");
+		return -ENODEV;
+	}
 
 	dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size);
 	sdev->bar[DSP_BAR] = devm_ioremap(sdev->dev, base, size);
-- 
2.25.1


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

* Re: [PATCH] ASoC: SOF: Intel: Check the bar size before remapping
  2022-04-09 14:39 [PATCH] ASoC: SOF: Intel: Check the bar size before remapping Zheyu Ma
@ 2022-04-11 15:28 ` Pierre-Louis Bossart
  2022-04-12  1:55   ` Zheyu Ma
  2022-04-13 17:36 ` Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Pierre-Louis Bossart @ 2022-04-11 15:28 UTC (permalink / raw)
  To: Zheyu Ma, lgirdwood, ranjani.sridharan, kai.vehmanen, broonie,
	perex, tiwai, peter.ujfalusi
  Cc: alsa-devel, linux-kernel, sound-open-firmware



On 4/9/22 09:39, Zheyu Ma wrote:
> The driver should use the pci_resource_len() to get the actual length of
> pci bar, and compare it with the expect value. If the bar size is too
> small (such as a broken device), the driver should return an error.
> 
> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> ---
>  sound/soc/sof/intel/pci-tng.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/sof/intel/pci-tng.c b/sound/soc/sof/intel/pci-tng.c
> index 6efef225973f..7d502cc3ca80 100644
> --- a/sound/soc/sof/intel/pci-tng.c
> +++ b/sound/soc/sof/intel/pci-tng.c
> @@ -75,7 +75,11 @@ static int tangier_pci_probe(struct snd_sof_dev *sdev)
>  
>  	/* LPE base */
>  	base = pci_resource_start(pci, desc->resindex_lpe_base) - IRAM_OFFSET;
> -	size = PCI_BAR_SIZE;
> +	size = pci_resource_len(pci, desc->resindex_lpe_base);
> +	if (size < PCI_BAR_SIZE) {
> +		dev_err(sdev->dev, "error: I/O region is too small.\n");
> +		return -ENODEV;
> +	}

May I ask how you found this issue?

I am not clear on why there's a patch dedicated for a single device, but the same pattern in hda.c and in the HDaudio legacy driver exists.

>  
>  	dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size);
>  	sdev->bar[DSP_BAR] = devm_ioremap(sdev->dev, base, size);

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

* Re: [PATCH] ASoC: SOF: Intel: Check the bar size before remapping
  2022-04-11 15:28 ` Pierre-Louis Bossart
@ 2022-04-12  1:55   ` Zheyu Ma
  0 siblings, 0 replies; 4+ messages in thread
From: Zheyu Ma @ 2022-04-12  1:55 UTC (permalink / raw)
  To: Pierre-Louis Bossart
  Cc: lgirdwood, ranjani.sridharan, kai.vehmanen, broonie, perex,
	tiwai, peter.ujfalusi, alsa-devel, Linux Kernel Mailing List,
	sound-open-firmware

On Tue, Apr 12, 2022 at 12:23 AM Pierre-Louis Bossart
<pierre-louis.bossart@linux.intel.com> wrote:
>
>
>
> On 4/9/22 09:39, Zheyu Ma wrote:
> > The driver should use the pci_resource_len() to get the actual length of
> > pci bar, and compare it with the expect value. If the bar size is too
> > small (such as a broken device), the driver should return an error.
> >
> > Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> > ---
> >  sound/soc/sof/intel/pci-tng.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/sound/soc/sof/intel/pci-tng.c b/sound/soc/sof/intel/pci-tng.c
> > index 6efef225973f..7d502cc3ca80 100644
> > --- a/sound/soc/sof/intel/pci-tng.c
> > +++ b/sound/soc/sof/intel/pci-tng.c
> > @@ -75,7 +75,11 @@ static int tangier_pci_probe(struct snd_sof_dev *sdev)
> >
> >       /* LPE base */
> >       base = pci_resource_start(pci, desc->resindex_lpe_base) - IRAM_OFFSET;
> > -     size = PCI_BAR_SIZE;
> > +     size = pci_resource_len(pci, desc->resindex_lpe_base);
> > +     if (size < PCI_BAR_SIZE) {
> > +             dev_err(sdev->dev, "error: I/O region is too small.\n");
> > +             return -ENODEV;
> > +     }
>
> May I ask how you found this issue?

Actually, I tested this driver via fuzzing in a simulated environment
and got a crash. Hence, I try to propose a patch and ask for the help
of maintainers to determine whether this is an issue.

Thanks,
Zheyu Ma

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

* Re: [PATCH] ASoC: SOF: Intel: Check the bar size before remapping
  2022-04-09 14:39 [PATCH] ASoC: SOF: Intel: Check the bar size before remapping Zheyu Ma
  2022-04-11 15:28 ` Pierre-Louis Bossart
@ 2022-04-13 17:36 ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2022-04-13 17:36 UTC (permalink / raw)
  To: lgirdwood, tiwai, pierre-louis.bossart, perex, kai.vehmanen,
	peter.ujfalusi, ranjani.sridharan, zheyuma97
  Cc: sound-open-firmware, alsa-devel, linux-kernel

On Sat, 9 Apr 2022 22:39:50 +0800, Zheyu Ma wrote:
> The driver should use the pci_resource_len() to get the actual length of
> pci bar, and compare it with the expect value. If the bar size is too
> small (such as a broken device), the driver should return an error.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: SOF: Intel: Check the bar size before remapping
      commit: 5947b2726beb61fe7911580f239222ec9c4f6967

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2022-04-13 17:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-09 14:39 [PATCH] ASoC: SOF: Intel: Check the bar size before remapping Zheyu Ma
2022-04-11 15:28 ` Pierre-Louis Bossart
2022-04-12  1:55   ` Zheyu Ma
2022-04-13 17:36 ` Mark Brown

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).