Skip to contentSkip to conversation

RISC-V: cpu: refactor deprecated strncpy

PATCH Applied Justin Stitt 7 participants 8 messages Aug 2, 2023 – Aug 9, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RISC-V: cpu: refactor deprecated strncpy

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

---
Changes in v2:
- Use strings directly instead of copying onto stack with strscpy (thanks Kees)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 arch/riscv/kernel/cpu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/riscv/kernel/cpu.c +6 -6
index a2fc952318e9..872fa7a47d68 100644
@@ -271,21 +271,21 @@ static void print_isa(struct seq_file *f, const char *isa)
 
 static void print_mmu(struct seq_file *f)
 {
-	char sv_type[16];
+	const char *sv_type;
 
 #ifdef CONFIG_MMU
 #if defined(CONFIG_32BIT)
-	strncpy(sv_type, "sv32", 5);
+	sv_type = "sv32";
 #elif defined(CONFIG_64BIT)
 	if (pgtable_l5_enabled)
-		strncpy(sv_type, "sv57", 5);
+		sv_type = "sv57";
 	else if (pgtable_l4_enabled)
-		strncpy(sv_type, "sv48", 5);
+		sv_type = "sv48";
 	else
-		strncpy(sv_type, "sv39", 5);
+		sv_type = "sv39";
 #endif
 #else
-	strncpy(sv_type, "none", 5);
+	sv_type = "none";
 #endif /* CONFIG_MMU */
 	seq_printf(f, "mmu\t\t: %s\n", sv_type);
 }

---
base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4
change-id: 20230801-arch-riscv-kernel-14a048cc6467

Best regards,
--
Justin Stitt <[email protected]>

Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Justin Stitt

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

Quoted 7 lines

---
Changes in v2:
- Use strings directly instead of copying onto stack with strscpy (thanks Kees)

Yeah, that is what I was thinking of when I decried it as being horrid.

Thanks,
Conor.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by on v2 1/1
#2 lore raw
In reply to Justin Stitt
Quoted 9 lines · Justin Stitt

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

I like it! ;)

Signature · 1 line
Kees Cook
maintainer Reviewed-by Acked-by
#3 lore raw
Quoted 6 lines · On Wed, 02 Aug 2023 13:36:03 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Justin Stitt

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

Quoted 8 lines
Quoted 4 lines

I like it! ;)

Thanks, I just queue it up for fixes (might take a bit to build test, I'm a bit backed up).

If you wanted to take it for some hardening thing, though -- otherwise it'll likely end up on my fixes later today.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#4 lore raw
Quoted 16 lines · Palmer Dabbelt
Quoted 6 lines · On Wed, 02 Aug 2023 13:36:03 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Justin Stitt

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

Quoted 8 lines
Quoted 4 lines

I like it! ;)

Quoted 8 lines

Thanks, I just queue it up for fixes (might take a bit to build test, I'm a bit backed up).

If you wanted to take it for some hardening thing, though -- otherwise it'll likely end up on my fixes later today.

Sorry this is for-next as it's not a fix, I was just looking at other fixes. It's queued up aimed at for-next.

#5 lore raw
Quoted 20 lines · Palmer Dabbelt
Quoted 19 lines · Palmer Dabbelt
Quoted 6 lines · On Wed, 02 Aug 2023 13:36:03 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Justin Stitt

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

Quoted 8 lines
Quoted 4 lines

I like it! ;)

Thanks, I just queue it up for fixes (might take a bit to build test, I'm a bit backed up).

Quoted 8 lines
Quoted 5 lines

If you wanted to take it for some hardening thing, though -- otherwise it'll likely end up on my fixes later today.

Sorry this is for-next as it's not a fix, I was just looking at other fixes. It's queued up aimed at for-next.

Awesome; thank you! :)

Signature · 1 line
Kees Cook
#7 lore raw
In reply to Justin Stitt
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 11 lines · On Wed, 02 Aug 2023 00:21:58 +0000 you wrote:

strncpy is deprecated for use on NUL-terminated destination strings [1].

Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.

[...]

Here is the summary with links:
- [v2] RISC-V: cpu: refactor deprecated strncpy

    https://git.kernel.org/riscv/c/12d61a1bc28e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html