linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc
@ 2021-10-24 11:17 Chengfeng Ye
       [not found] ` <TYCP286MB1188D80DA04A5EE1B96814B28A829@TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM>
  0 siblings, 1 reply; 3+ messages in thread
From: Chengfeng Ye @ 2021-10-24 11:17 UTC (permalink / raw)
  To: perex, tiwai, chihhao.chen, damien; +Cc: alsa-devel, linux-kernel, Chengfeng Ye

The pointer cs_desc return from snd_usb_find_clock_source could
be null, so there is a potential null pointer dereference issue.
Fix this by adding a null check before dereference.

Fixes: 9ec73005 ("ALSA: usb-audio: Refactoring UAC2/3 clock setup code")
Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
---
 sound/usb/clock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 81d5ce07d548..98345a695dcc 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -496,6 +496,10 @@ int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip,
 	union uac23_clock_source_desc *cs_desc;
 
 	cs_desc = snd_usb_find_clock_source(chip, clock, fmt->protocol);
+
+	if (!cs_desc)
+		return 0;
+
 	if (fmt->protocol == UAC_VERSION_3)
 		bmControls = le32_to_cpu(cs_desc->v3.bmControls);
 	else
-- 
2.17.1


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

* Re: 回复: [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc
       [not found] ` <TYCP286MB1188D80DA04A5EE1B96814B28A829@TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM>
@ 2021-10-26  6:10   ` Takashi Iwai
  2021-10-26 12:51     ` 回复: " YE Chengfeng
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2021-10-26  6:10 UTC (permalink / raw)
  To: YE Chengfeng; +Cc: perex, tiwai, chihhao.chen, damien, alsa-devel, linux-kernel

On Sun, 24 Oct 2021 13:20:48 +0200,
YE Chengfeng wrote:
> 
> Hi,
> 
> I found another potential null-ptr-dereference problem in this file, and not
> sure whether it is true.  I send this patch to you just for reference, thinks
> a lot if you could spare some time to look at it.

The Fixes tag doesn't look correct (the code before the refactoring
also didn't have NULL checks), so applied without it now.


thanks,

Takashi

> 
> Thanks so much,
> Chengfeng
> ------------------------------------------------------------------------------
> 发件人: YE Chengfeng <cyeaa@connect.ust.hk>
> 发送时间: 2021年10月24日 19:17
> 收件人: perex@perex.cz <perex@perex.cz>; tiwai@suse.com <tiwai@suse.com>;
> chihhao.chen@mediatek.com <chihhao.chen@mediatek.com>; damien@zamaudio.com
> <damien@zamaudio.com>
> 抄送: alsa-devel@alsa-project.org <alsa-devel@alsa-project.org>;
> linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; YE Chengfeng
> <cyeaa@connect.ust.hk>
> 主题: [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc
>  
> The pointer cs_desc return from snd_usb_find_clock_source could
> be null, so there is a potential null pointer dereference issue.
> Fix this by adding a null check before dereference.
> 
> Fixes: 9ec73005 ("ALSA: usb-audio: Refactoring UAC2/3 clock setup code")
> Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
> ---
>  sound/usb/clock.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/sound/usb/clock.c b/sound/usb/clock.c
> index 81d5ce07d548..98345a695dcc 100644
> --- a/sound/usb/clock.c
> +++ b/sound/usb/clock.c
> @@ -496,6 +496,10 @@ int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio
> *chip,
>          union uac23_clock_source_desc *cs_desc;
>  
>          cs_desc = snd_usb_find_clock_source(chip, clock, fmt->protocol);
> +
> +       if (!cs_desc)
> +               return 0;
> +
>          if (fmt->protocol == UAC_VERSION_3)
>                  bmControls = le32_to_cpu(cs_desc->v3.bmControls);
>          else
> --
> 2.17.1
> 
> 

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

* 回复: 回复: [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc
  2021-10-26  6:10   ` 回复: " Takashi Iwai
@ 2021-10-26 12:51     ` YE Chengfeng
  0 siblings, 0 replies; 3+ messages in thread
From: YE Chengfeng @ 2021-10-26 12:51 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: perex, tiwai, chihhao.chen, damien, alsa-devel, linux-kernel

Got it. 

Thanks so much.
-Chengfeng

-----邮件原件-----
发件人: Takashi Iwai <tiwai@suse.de> 
发送时间: 2021年10月26日 14:11
收件人: YE Chengfeng <cyeaa@connect.ust.hk>
抄送: perex@perex.cz; tiwai@suse.com; chihhao.chen@mediatek.com; damien@zamaudio.com; alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org
主题: Re: 回复: [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc

On Sun, 24 Oct 2021 13:20:48 +0200,
YE Chengfeng wrote:
> 
> Hi,
> 
> I found another potential null-ptr-dereference problem in this file, 
> and not sure whether it is true.  I send this patch to you just for 
> reference, thinks a lot if you could spare some time to look at it.

The Fixes tag doesn't look correct (the code before the refactoring also didn't have NULL checks), so applied without it now.


thanks,

Takashi

> 
> Thanks so much,
> Chengfeng
> ----------------------------------------------------------------------
> --------
> 发件人: YE Chengfeng <cyeaa@connect.ust.hk>
> 发送时间: 2021年10月24日 19:17
> 收件人: perex@perex.cz <perex@perex.cz>; tiwai@suse.com <tiwai@suse.com>; 
> chihhao.chen@mediatek.com <chihhao.chen@mediatek.com>; 
> damien@zamaudio.com <damien@zamaudio.com>
> 抄送: alsa-devel@alsa-project.org <alsa-devel@alsa-project.org>; 
> linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; YE 
> Chengfeng <cyeaa@connect.ust.hk>
> 主题: [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc
>  
> The pointer cs_desc return from snd_usb_find_clock_source could be 
> null, so there is a potential null pointer dereference issue.
> Fix this by adding a null check before dereference.
> 
> Fixes: 9ec73005 ("ALSA: usb-audio: Refactoring UAC2/3 clock setup 
> code")
> Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
> ---
>  sound/usb/clock.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/sound/usb/clock.c b/sound/usb/clock.c index 
> 81d5ce07d548..98345a695dcc 100644
> --- a/sound/usb/clock.c
> +++ b/sound/usb/clock.c
> @@ -496,6 +496,10 @@ int snd_usb_set_sample_rate_v2v3(struct 
> snd_usb_audio *chip,
>          union uac23_clock_source_desc *cs_desc;
>  
>          cs_desc = snd_usb_find_clock_source(chip, clock, 
> fmt->protocol);
> +
> +       if (!cs_desc)
> +               return 0;
> +
>          if (fmt->protocol == UAC_VERSION_3)
>                  bmControls = le32_to_cpu(cs_desc->v3.bmControls);
>          else
> --
> 2.17.1
> 
> 

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

end of thread, other threads:[~2021-10-26 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 11:17 [PATCH] sound/usb: fix null pointer dereference on pointer cs_desc Chengfeng Ye
     [not found] ` <TYCP286MB1188D80DA04A5EE1B96814B28A829@TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM>
2021-10-26  6:10   ` 回复: " Takashi Iwai
2021-10-26 12:51     ` 回复: " YE Chengfeng

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