linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: Loongson64: Replace deprecated strcpy() with strscpy_pad()
@ 2025-08-19 10:23 Thorsten Blum
  2025-08-29 10:27 ` Thomas Bogendoerfer
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-08-19 10:23 UTC (permalink / raw)
  To: Huacai Chen, Jiaxun Yang, Thomas Bogendoerfer
  Cc: linux-hardening, Thorsten Blum, linux-mips, linux-kernel

strcpy() is deprecated; use strscpy_pad() instead.

strscpy_pad() already copies the source strings and zero-pads the tail
of the destination buffers, making the explicit initializations to zero
redundant. Remove them to ensure the buffers are only written to once.

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/mips/loongson64/boardinfo.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/mips/loongson64/boardinfo.c b/arch/mips/loongson64/boardinfo.c
index 8bb275c93ac0..827ab94b98b3 100644
--- a/arch/mips/loongson64/boardinfo.c
+++ b/arch/mips/loongson64/boardinfo.c
@@ -1,17 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/kobject.h>
+#include <linux/string.h>
 #include <boot_param.h>
 
 static ssize_t boardinfo_show(struct kobject *kobj,
 			      struct kobj_attribute *attr, char *buf)
 {
-	char board_manufacturer[64] = {0};
+	char board_manufacturer[64];
 	char *tmp_board_manufacturer = board_manufacturer;
-	char bios_vendor[64] = {0};
+	char bios_vendor[64];
 	char *tmp_bios_vendor = bios_vendor;
 
-	strcpy(board_manufacturer, eboard->name);
-	strcpy(bios_vendor, einter->description);
+	strscpy_pad(board_manufacturer, eboard->name);
+	strscpy_pad(bios_vendor, einter->description);
 
 	return sprintf(buf,
 		       "Board Info\n"
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MIPS: Loongson64: Replace deprecated strcpy() with strscpy_pad()
  2025-08-19 10:23 [PATCH] MIPS: Loongson64: Replace deprecated strcpy() with strscpy_pad() Thorsten Blum
@ 2025-08-29 10:27 ` Thomas Bogendoerfer
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Bogendoerfer @ 2025-08-29 10:27 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Huacai Chen, Jiaxun Yang, linux-hardening, linux-mips,
	linux-kernel

On Tue, Aug 19, 2025 at 12:23:19PM +0200, Thorsten Blum wrote:
> strcpy() is deprecated; use strscpy_pad() instead.
> 
> strscpy_pad() already copies the source strings and zero-pads the tail
> of the destination buffers, making the explicit initializations to zero
> redundant. Remove them to ensure the buffers are only written to once.
> 
> No functional changes intended.
> 
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/mips/loongson64/boardinfo.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/mips/loongson64/boardinfo.c b/arch/mips/loongson64/boardinfo.c
> index 8bb275c93ac0..827ab94b98b3 100644
> --- a/arch/mips/loongson64/boardinfo.c
> +++ b/arch/mips/loongson64/boardinfo.c
> @@ -1,17 +1,18 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #include <linux/kobject.h>
> +#include <linux/string.h>
>  #include <boot_param.h>
>  
>  static ssize_t boardinfo_show(struct kobject *kobj,
>  			      struct kobj_attribute *attr, char *buf)
>  {
> -	char board_manufacturer[64] = {0};
> +	char board_manufacturer[64];
>  	char *tmp_board_manufacturer = board_manufacturer;
> -	char bios_vendor[64] = {0};
> +	char bios_vendor[64];
>  	char *tmp_bios_vendor = bios_vendor;
>  
> -	strcpy(board_manufacturer, eboard->name);
> -	strcpy(bios_vendor, einter->description);
> +	strscpy_pad(board_manufacturer, eboard->name);
> +	strscpy_pad(bios_vendor, einter->description);
>  
>  	return sprintf(buf,
>  		       "Board Info\n"
> -- 
> 2.50.1

applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-29 10:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 10:23 [PATCH] MIPS: Loongson64: Replace deprecated strcpy() with strscpy_pad() Thorsten Blum
2025-08-29 10:27 ` Thomas Bogendoerfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).