ASoC: wcd934x: Fix a incorrect use of kstrndup
Subsystems (3)
PATCH 1/1 ASoC: wcd934x: Fix a incorrect use of kstrndup
In wcd934x_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(). It's similar to CVE-2019-12454.
--- sound/soc/codecs/wcd934x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/wcd934x.c +1 -1
@@ -5005,7 +5005,7 @@ static int wcd934x_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.17.1
Quoted 15 lines · Miaoqian Lin
In
wcd934x_codec_enable_dec(),widget_nameis allocated bykstrndup(). However, according to doc: "Note: Usekmemdup_nul()instead if the size is known exactly." So we should usekmemdup_nul()here instead ofkstrndup(). It's similar to CVE-2019-12454.Signed-off-by Miaoqian Lin <[email protected]>--- sound/soc/codecs/wcd934x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/soc/codecs/wcd934x.c +0
-0
sound/soc/codecs/wcd934x.c static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w, · line 5008
Quoted 5 lines
sound/soc/codecs/wcd934x.c +1
-1@@ -5005,7 +5005,7 @@ static int wcd934x_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 );
I'm wondering if it isn't better to re-structure the code to not allocate any memory.
something like
ret = sscan(w->name, "ADC MUX%d", &decimator);
if (ret != 1)
...
Quoted 15 lines · Miaoqian Lin
In
wcd934x_codec_enable_dec(),widget_nameis allocated bykstrndup(). However, according to doc: "Note: Usekmemdup_nul()instead if the size is known exactly." So we should usekmemdup_nul()here instead ofkstrndup(). It's similar to CVE-2019-12454.Signed-off-by Miaoqian Lin <[email protected]>--- sound/soc/codecs/wcd934x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/soc/codecs/wcd934x.c +0
-0
sound/soc/codecs/wcd934x.c static int wcd934x_codec_enable_dec(struct snd_soc_dapm_widget *w, · line 5008
Quoted 5 lines
sound/soc/codecs/wcd934x.c +1
-1@@ -5005,7 +5005,7 @@ static int wcd934x_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 );
Thinking a bit more about it, this is wrong. The source string is shorter than 15 character. So with this change you are copying past the end of the string, which depending on where in memory the string is placed can cause undefined behavior.