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] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z73HDk9p2P_Zigu2@gmail.com>
Date: Tue, 25 Feb 2025 14:35:10 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Thorsten Blum <thorsten.blum@...ux.dev>
Cc: Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>,
	Borislav Petkov <bp@...en8.de>,
	Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
	"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] x86/mtrr: Remove unnecessary strlen() in mtrr_write()


* Thorsten Blum <thorsten.blum@...ux.dev> wrote:

> The local variable length already holds the string length after calling
> strncpy_from_user(). Using another local variable linlen and calling
> strlen() is therefore unnecessary and can be removed. Remove linlen
> and strlen() and use length instead.
> 
> Compile-tested only.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
> ---
>  arch/x86/kernel/cpu/mtrr/if.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
> index a5c506f6da7f..4049235b1bfe 100644
> --- a/arch/x86/kernel/cpu/mtrr/if.c
> +++ b/arch/x86/kernel/cpu/mtrr/if.c
> @@ -99,7 +99,6 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
>  	char *ptr;
>  	char line[LINE_SIZE];
>  	int length;
> -	size_t linelen;
>  
>  	memset(line, 0, LINE_SIZE);
>  
> @@ -108,9 +107,8 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
>  	if (length < 0)
>  		return length;
>  
> -	linelen = strlen(line);
> -	ptr = line + linelen - 1;
> -	if (linelen && *ptr == '\n')
> +	ptr = line + length - 1;
> +	if (length && *ptr == '\n')
>  		*ptr = '\0';

I see no corner-case analysis in the changelog about what may happen if 
the copy fails partially.

Thanks,

	Ingo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ