2017-08-10 15:56:47

by Anton Vasilyev

[permalink] [raw]
Subject: [PATCH] ASoC: samsung: i2s: Null pointer dereference on samsung_i2s_remove

If (quirks & QUIRK_SEC_DAI == 0) then samsung_i2s_probe() doesn't allocate
sec_dai and pri_dai->sec_dai remains Null, but samsung_i2s_remove()
permorms pri_dai->sec_dai dereference in any case.

The patch adds sec_dai check on Null before derefence at
samsung_i2s_remove().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <[email protected]>
---
sound/soc/samsung/i2s.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index af3ba4d..6beeea8 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -1382,7 +1382,8 @@ static int samsung_i2s_remove(struct platform_device *pdev)
sec_dai = pri_dai->sec_dai;

pri_dai->sec_dai = NULL;
- sec_dai->pri_dai = NULL;
+ if (sec_dai)
+ sec_dai->pri_dai = NULL;

pm_runtime_get_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);
--
2.7.4


2017-08-10 16:23:59

by Sylwester Nawrocki

[permalink] [raw]
Subject: Re: [PATCH] ASoC: samsung: i2s: Null pointer dereference on samsung_i2s_remove

On 08/10/2017 05:56 PM, Anton Vasilyev wrote:
> If (quirks & QUIRK_SEC_DAI == 0) then samsung_i2s_probe() doesn't allocate
> sec_dai and pri_dai->sec_dai remains Null, but samsung_i2s_remove()
> permorms pri_dai->sec_dai dereference in any case.

s/permorms/performs

> The patch adds sec_dai check on Null before derefence at
> samsung_i2s_remove().
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Anton Vasilyev <[email protected]>
> ---
> sound/soc/samsung/i2s.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
> index af3ba4d..6beeea8 100644
> --- a/sound/soc/samsung/i2s.c
> +++ b/sound/soc/samsung/i2s.c
> @@ -1382,7 +1382,8 @@ static int samsung_i2s_remove(struct platform_device *pdev)
> sec_dai = pri_dai->sec_dai;
>
> pri_dai->sec_dai = NULL;
> - sec_dai->pri_dai = NULL;

Thanks for the patch. AFAICS above 4 lines could be removed altogether
since pri_dai and sec_dai is being allocated with devm_kzalloc().
So initializing in remove() is meaningless as afterwards the data will
not be used any more. The memory will be just freed by the devres code.

> + if (sec_dai)
> + sec_dai->pri_dai = NULL;

--
Regards,
Sylwester