Skip to contentSkip to conversation

wcd9335: fix a incorrect use of kstrndup()

PATCH In review Gen Zhang 4 participants 4 messages May 29, 2019 – Jun 18, 2019

Subsystems (3)
lore
Share & tools
lore

Gen Zhang

author
#0 lore raw

PATCH 1/1 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().

---

sound/soc/codecs/wcd9335.c +1 -1
index a04a7ce..85737fe 100644
@@ -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;
 

---

maintainer
#1 lore raw

Applied "wcd9335: fix a incorrect use of kstrndup()" to the asoc tree

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

Quoted 1 line

From a54988113985ca22e414e132054f234fc8a92604 Mon Sep 17 00:00:00 2001

From: Gen Zhang <[email protected]>
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().

---
 sound/soc/codecs/wcd9335.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/wcd9335.c +1 -1
index a04a7cedd99d..85737fe54474 100644
@@ -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;
 
Signature · 1 line
2.20.1
#2 lore raw
In reply to Gen Zhang
Quoted 3 lines · Gen Zhang

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?

Quoted 10 lines

So we should use kmemdup_nul() here instead of
kstrndup().

---

sound/soc/codecs/wcd9335.c +0 -0
index a04a7ce..85737fe 100644

sound/soc/codecs/wcd9335.c static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w, · line 2740

Quoted 8 lines
sound/soc/codecs/wcd9335.c +1 -1
@@ -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,

Signature · 2 lines
js
suse labs
#3 lore raw
Quoted 6 lines · Jiri Slaby
Quoted 3 lines · Gen Zhang

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

Quoted 24 lines
Quoted 11 lines

So we should use kmemdup_nul() here instead of
kstrndup().

---

sound/soc/codecs/wcd9335.c +0 -0
index a04a7ce..85737fe 100644

sound/soc/codecs/wcd9335.c static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w, · line 2740

Quoted 8 lines
sound/soc/codecs/wcd9335.c +1 -1
@@ -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,

Signature · 2 lines
js
suse labs