linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/ps3: refactor strncpy usage
@ 2023-08-16 21:39 Justin Stitt
  2023-08-17  3:06 ` Kees Cook
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Justin Stitt @ 2023-08-16 21:39 UTC (permalink / raw)
  To: Geoff Levand, Michael Ellerman, Nicholas Piggin, Christophe Leroy
  Cc: linux-hardening, Justin Stitt, linuxppc-dev, linux-kernel,
	Kees Cook

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

`make_first_field()` should use similar implementation to `make_field()`
due to memcpy having more obvious behavior here. The end result yields
the same behavior as the previous `strncpy`-based implementation
including the NUL-padding.

Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note:
This follows up on a previous RFC which can be found here:
https://lore.kernel.org/all/20230811-strncpy-arch-powerpc-platforms-ps3-v1-0-301052a5663e@google.com/
---
 arch/powerpc/platforms/ps3/repository.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/ps3/repository.c b/arch/powerpc/platforms/ps3/repository.c
index 205763061a2d..1abe33fbe529 100644
--- a/arch/powerpc/platforms/ps3/repository.c
+++ b/arch/powerpc/platforms/ps3/repository.c
@@ -73,9 +73,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
 
 static u64 make_first_field(const char *text, u64 index)
 {
-	u64 n;
+	u64 n = 0;
 
-	strncpy((char *)&n, text, 8);
+	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
 	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
 }
 

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230816-strncpy-arch-powerpc-platforms-ps3-repository-85a1c867ed23

Best regards,
--
Justin Stitt <justinstitt@google.com>


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

* Re: [PATCH] powerpc/ps3: refactor strncpy usage
  2023-08-16 21:39 [PATCH] powerpc/ps3: refactor strncpy usage Justin Stitt
@ 2023-08-17  3:06 ` Kees Cook
  2023-08-17  6:34 ` Michael Ellerman
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2023-08-17  3:06 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Geoff Levand, linux-kernel, Nicholas Piggin, linuxppc-dev,
	linux-hardening

On Wed, Aug 16, 2023 at 09:39:24PM +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
> 
> `make_first_field()` should use similar implementation to `make_field()`
> due to memcpy having more obvious behavior here. The end result yields
> the same behavior as the previous `strncpy`-based implementation
> including the NUL-padding.
> 
> Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

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

* Re: [PATCH] powerpc/ps3: refactor strncpy usage
  2023-08-16 21:39 [PATCH] powerpc/ps3: refactor strncpy usage Justin Stitt
  2023-08-17  3:06 ` Kees Cook
@ 2023-08-17  6:34 ` Michael Ellerman
  2023-08-17 19:58 ` Geoff Levand
  2023-08-23 11:55 ` Michael Ellerman
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2023-08-17  6:34 UTC (permalink / raw)
  To: Justin Stitt, Geoff Levand, Nicholas Piggin, Christophe Leroy
  Cc: linux-hardening, Justin Stitt, linuxppc-dev, linux-kernel,
	Kees Cook

Justin Stitt <justinstitt@google.com> writes:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>
> `make_first_field()` should use similar implementation to `make_field()`
> due to memcpy having more obvious behavior here. The end result yields
> the same behavior as the previous `strncpy`-based implementation
> including the NUL-padding.
>
> Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> Note:
> This follows up on a previous RFC which can be found here:
> https://lore.kernel.org/all/20230811-strncpy-arch-powerpc-platforms-ps3-v1-0-301052a5663e@google.com/
> ---
>  arch/powerpc/platforms/ps3/repository.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

This looks good to me. I'll pick this up directly, Geoff let me know if
this breaks something somehow.

cheers

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

* Re: [PATCH] powerpc/ps3: refactor strncpy usage
  2023-08-16 21:39 [PATCH] powerpc/ps3: refactor strncpy usage Justin Stitt
  2023-08-17  3:06 ` Kees Cook
  2023-08-17  6:34 ` Michael Ellerman
@ 2023-08-17 19:58 ` Geoff Levand
  2023-08-23 11:55 ` Michael Ellerman
  3 siblings, 0 replies; 5+ messages in thread
From: Geoff Levand @ 2023-08-17 19:58 UTC (permalink / raw)
  To: Justin Stitt, Michael Ellerman, Nicholas Piggin, Christophe Leroy
  Cc: linux-hardening, linuxppc-dev, linux-kernel, Kees Cook

On 8/16/23 14:39, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
> 
> `make_first_field()` should use similar implementation to `make_field()`
> due to memcpy having more obvious behavior here. The end result yields
> the same behavior as the previous `strncpy`-based implementation
> including the NUL-padding.

> diff --git a/arch/powerpc/platforms/ps3/repository.c b/arch/powerpc/platforms/ps3/repository.c
> index 205763061a2d..1abe33fbe529 100644
> --- a/arch/powerpc/platforms/ps3/repository.c
> +++ b/arch/powerpc/platforms/ps3/repository.c
> @@ -73,9 +73,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,

I tested this on PS3 and it seems to be working OK.

Tested-by: Geoff Levand <geoff@infradead.org>



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

* Re: [PATCH] powerpc/ps3: refactor strncpy usage
  2023-08-16 21:39 [PATCH] powerpc/ps3: refactor strncpy usage Justin Stitt
                   ` (2 preceding siblings ...)
  2023-08-17 19:58 ` Geoff Levand
@ 2023-08-23 11:55 ` Michael Ellerman
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2023-08-23 11:55 UTC (permalink / raw)
  To: Geoff Levand, Nicholas Piggin, Christophe Leroy, Justin Stitt
  Cc: linux-hardening, linuxppc-dev, linux-kernel, Kees Cook

On Wed, 16 Aug 2023 21:39:24 +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
> 
> `make_first_field()` should use similar implementation to `make_field()`
> due to memcpy having more obvious behavior here. The end result yields
> the same behavior as the previous `strncpy`-based implementation
> including the NUL-padding.
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/ps3: refactor strncpy usage
      https://git.kernel.org/powerpc/c/f94a84a0914841d79a38df7cc75512d88b31a0dc

cheers

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

end of thread, other threads:[~2023-08-23 12:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 21:39 [PATCH] powerpc/ps3: refactor strncpy usage Justin Stitt
2023-08-17  3:06 ` Kees Cook
2023-08-17  6:34 ` Michael Ellerman
2023-08-17 19:58 ` Geoff Levand
2023-08-23 11:55 ` Michael Ellerman

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).