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]
Message-ID: <5d2282ef995adddec86ae8e3240cd3f59f50b3e4.camel@linux.ibm.com>
Date: Thu, 04 Sep 2025 14:14:16 +0200
From: Niklas Schnelle <schnelle@...ux.ibm.com>
To: Thorsten Blum <thorsten.blum@...ux.dev>,
        Heiko Carstens
 <hca@...ux.ibm.com>, Vasily Gorbik <gor@...ux.ibm.com>,
        Alexander Gordeev
 <agordeev@...ux.ibm.com>,
        Christian Borntraeger	
 <borntraeger@...ux.ibm.com>,
        Sven Schnelle <svens@...ux.ibm.com>,
        Halil
 Pasic	 <pasic@...ux.ibm.com>,
        "Bill O'Donnell" <bodonnel@...hat.com>,
        Al Viro
	 <viro@...iv.linux.org.uk>,
        Tigran Mkrtchyan <tigran.mkrtchyan@...y.de>,
        Joel Granados <joel.granados@...nel.org>
Cc: Wei Liu <wei.liu@...nel.org>, linux-s390@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] s390/debug: Replace kmalloc() + copy_from_user() with
 memdup_user_nul()

On Thu, 2025-09-04 at 13:40 +0200, Thorsten Blum wrote:
> Replace kmalloc() followed by copy_from_user() with memdup_user_nul() to
> improve and simplify debug_get_user_string(). Remove the manual
> NUL-termination.
> 
> No functional changes intended.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
> ---
>  arch/s390/kernel/debug.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
> index c62100dc62c8..6a26f202441d 100644
> --- a/arch/s390/kernel/debug.c
> +++ b/arch/s390/kernel/debug.c
> @@ -1416,18 +1416,12 @@ static inline char *debug_get_user_string(const char __user *user_buf,
>  {
>  	char *buffer;
>  
> -	buffer = kmalloc(user_len + 1, GFP_KERNEL);
> -	if (!buffer)
> -		return ERR_PTR(-ENOMEM);
> -	if (copy_from_user(buffer, user_buf, user_len) != 0) {
> -		kfree(buffer);
> -		return ERR_PTR(-EFAULT);
> -	}
> +	buffer = memdup_user_nul(user_buf, user_len);
> +	if (IS_ERR(buffer))
> +		return buffer;
>  	/* got the string, now strip linefeed. */
>  	if (buffer[user_len - 1] == '\n')
>  		buffer[user_len - 1] = 0;
> -	else
> -		buffer[user_len] = 0;
>  	return buffer;
>  }
>  

I like it, thanks!

Reviewed-by: Niklas Schnelle <schnelle@...ux.ibm.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ