LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] wcd9335: fix a incorrect use of kstrndup()
@ 2019-05-29  1:53 Gen Zhang
  2019-05-29 15:45 ` Applied "wcd9335: fix a incorrect use of kstrndup()" to the asoc tree Mark Brown
  2019-06-05  4:57 ` [PATCH] wcd9335: fix a incorrect use of kstrndup() Jiri Slaby
  0 siblings, 2 replies; 4+ messages in thread
From: Gen Zhang @ 2019-05-29  1:53 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, wen.yang99; +Cc: alsa-devel, linux-kernel

In wcd9335_codec_enable_dec(), 'widget_name' is allocated by kstrndup().
However, according to doc: "Note: Use kmemdup_nul() instead if the size
is known exactly." So we should use kmemdup_nul() here instead of
kstrndup().

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
---
diff --git a/sound/soc/codecs/wcd9335.c b/sound/soc/codecs/wcd9335.c
index a04a7ce..85737fe 100644
--- a/sound/soc/codecs/wcd9335.c
+++ b/sound/soc/codecs/wcd9335.c
@@ -2734,7 +2734,7 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
 	char *dec;
 	u8 hpf_coff_freq;
 
-	widget_name = kstrndup(w->name, 15, GFP_KERNEL);
+	widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL);
 	if (!widget_name)
 		return -ENOMEM;
 
---

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

* Applied "wcd9335: fix a incorrect use of kstrndup()" to the asoc tree
  2019-05-29  1:53 [PATCH] wcd9335: fix a incorrect use of kstrndup() Gen Zhang
@ 2019-05-29 15:45 ` Mark Brown
  2019-06-05  4:57 ` [PATCH] wcd9335: fix a incorrect use of kstrndup() Jiri Slaby
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2019-05-29 15:45 UTC (permalink / raw)
  To: Gen Zhang
  Cc: alsa-devel, broonie, lgirdwood, linux-kernel, Mark Brown, perex,
	wen.yang99

The patch

   wcd9335: fix a incorrect use of kstrndup()

has been applied to the asoc tree at

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

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

From a54988113985ca22e414e132054f234fc8a92604 Mon Sep 17 00:00:00 2001
From: Gen Zhang <blackgod016574@gmail.com>
Date: Wed, 29 May 2019 09:53:05 +0800
Subject: [PATCH] wcd9335: fix a incorrect use of kstrndup()

In wcd9335_codec_enable_dec(), 'widget_name' is allocated by kstrndup().
However, according to doc: "Note: Use kmemdup_nul() instead if the size
is known exactly." So we should use kmemdup_nul() here instead of
kstrndup().

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/wcd9335.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/wcd9335.c b/sound/soc/codecs/wcd9335.c
index a04a7cedd99d..85737fe54474 100644
--- a/sound/soc/codecs/wcd9335.c
+++ b/sound/soc/codecs/wcd9335.c
@@ -2734,7 +2734,7 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
 	char *dec;
 	u8 hpf_coff_freq;
 
-	widget_name = kstrndup(w->name, 15, GFP_KERNEL);
+	widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL);
 	if (!widget_name)
 		return -ENOMEM;
 
-- 
2.20.1


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

* Re: [PATCH] wcd9335: fix a incorrect use of kstrndup()
  2019-05-29  1:53 [PATCH] wcd9335: fix a incorrect use of kstrndup() Gen Zhang
  2019-05-29 15:45 ` Applied "wcd9335: fix a incorrect use of kstrndup()" to the asoc tree Mark Brown
@ 2019-06-05  4:57 ` Jiri Slaby
  2019-06-18 23:05   ` Tyler Hicks
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Slaby @ 2019-06-05  4:57 UTC (permalink / raw)
  To: Gen Zhang, broonie, lgirdwood, perex, wen.yang99; +Cc: alsa-devel, linux-kernel

On 29. 05. 19, 3:53, Gen Zhang wrote:
> In wcd9335_codec_enable_dec(), 'widget_name' is allocated by kstrndup().
> However, according to doc: "Note: Use kmemdup_nul() instead if the size
> is known exactly."

Except the size is not known exactly. It is at most 15, not 15. Right?

> So we should use kmemdup_nul() here instead of
> kstrndup().
> 
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> ---
> diff --git a/sound/soc/codecs/wcd9335.c b/sound/soc/codecs/wcd9335.c
> index a04a7ce..85737fe 100644
> --- a/sound/soc/codecs/wcd9335.c
> +++ b/sound/soc/codecs/wcd9335.c
> @@ -2734,7 +2734,7 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
>  	char *dec;
>  	u8 hpf_coff_freq;
>  
> -	widget_name = kstrndup(w->name, 15, GFP_KERNEL);
> +	widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL);
>  	if (!widget_name)
>  		return -ENOMEM;
>  

thanks,
-- 
js
suse labs

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

* Re: [PATCH] wcd9335: fix a incorrect use of kstrndup()
  2019-06-05  4:57 ` [PATCH] wcd9335: fix a incorrect use of kstrndup() Jiri Slaby
@ 2019-06-18 23:05   ` Tyler Hicks
  0 siblings, 0 replies; 4+ messages in thread
From: Tyler Hicks @ 2019-06-18 23:05 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Gen Zhang, broonie, lgirdwood, perex, wen.yang99, alsa-devel,
	linux-kernel

On 2019-06-05 06:57:02, Jiri Slaby wrote:
> On 29. 05. 19, 3:53, Gen Zhang wrote:
> > In wcd9335_codec_enable_dec(), 'widget_name' is allocated by kstrndup().
> > However, according to doc: "Note: Use kmemdup_nul() instead if the size
> > is known exactly."
> 
> Except the size is not known exactly. It is at most 15, not 15. Right?

That's my understanding, as well. This change looks incorrect/misguided
to me.

CVE-2019-12454 was assigned for this but I've requested that MITRE
reject it as there doesn't seem to be any security impact and possibly
no reason at all for this change.

Tyler

> 
> > So we should use kmemdup_nul() here instead of
> > kstrndup().
> > 
> > Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> > ---
> > diff --git a/sound/soc/codecs/wcd9335.c b/sound/soc/codecs/wcd9335.c
> > index a04a7ce..85737fe 100644
> > --- a/sound/soc/codecs/wcd9335.c
> > +++ b/sound/soc/codecs/wcd9335.c
> > @@ -2734,7 +2734,7 @@ static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w,
> >  	char *dec;
> >  	u8 hpf_coff_freq;
> >  
> > -	widget_name = kstrndup(w->name, 15, GFP_KERNEL);
> > +	widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL);
> >  	if (!widget_name)
> >  		return -ENOMEM;
> >  
> 
> thanks,
> -- 
> js
> suse labs

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

end of thread, other threads:[~2019-06-18 23:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-29  1:53 [PATCH] wcd9335: fix a incorrect use of kstrndup() Gen Zhang
2019-05-29 15:45 ` Applied "wcd9335: fix a incorrect use of kstrndup()" to the asoc tree Mark Brown
2019-06-05  4:57 ` [PATCH] wcd9335: fix a incorrect use of kstrndup() Jiri Slaby
2019-06-18 23:05   ` Tyler Hicks

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