lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 04 Jul 2019 15:13:01 +0200
From:   Takashi Iwai <tiwai@...e.de>
To:     "Fuqian Huang" <huangfq.daxian@...il.com>
Cc:     <alsa-devel@...a-project.org>, "Jaroslav Kysela" <perex@...ex.cz>,
        "Takashi Iwai" <tiwai@...e.com>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 33/35] sound/pci: Use kmemdup rather than duplicating its implementation

On Wed, 03 Jul 2019 18:32:10 +0200,
Fuqian Huang wrote:
> 
> kmemdup is introduced to duplicate a region of memory in a neat way.
> Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
> write the size twice (sometimes lead to mistakes), kmemdup improves
> readability, leads to smaller code and also reduce the chances of mistakes.
> Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.
> 
> Signed-off-by: Fuqian Huang <huangfq.daxian@...il.com>
> ---
> Changes in v2:
>   - Fix a typo in commit message (memset -> memcpy)
> 
>  sound/pci/echoaudio/echoaudio.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
> index b612a536a5a1..35bd3e7c8ce1 100644
> --- a/sound/pci/echoaudio/echoaudio.c
> +++ b/sound/pci/echoaudio/echoaudio.c
> @@ -2189,11 +2189,10 @@ static int snd_echo_resume(struct device *dev)
>  	u32 pipe_alloc_mask;
>  	int err;
>  
> -	commpage_bak = kmalloc(sizeof(*commpage), GFP_KERNEL);
> +	commpage_bak = kmemdup(commpage, sizeof(*commpage), GFP_KERNEL);
>  	if (commpage_bak == NULL)
>  		return -ENOMEM;
>  	commpage = chip->comm_page;
> -	memcpy(commpage_bak, commpage, sizeof(*commpage));
>  
>  	err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
>  	if (err < 0) {

The patch is obviously wrong and leads to a crash.  See that the
assignment of the source address is done after the kmalloc() call but
before memcpy().  With kmemdup(), this will be screwed up.

This error could be caught easily by just compiling the kernel, too.
Please do at least the proper build test at the next time.


thanks,

Takashi

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ