From: Michael Ellerman <mpe@ellerman.id.au>
To: Justin Stitt <justinstitt@google.com>,
Geoff Levand <geoff@infradead.org>,
Nicholas Piggin <npiggin@gmail.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linux-hardening@vger.kernel.org,
Kees Cook <keescook@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Nathan Chancellor <nathan@kernel.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Justin Stitt <justinstitt@google.com>
Subject: Re: [PATCH RFC 1/3] powerpc/ps3: refactor strncpy usage attempt 1
Date: Mon, 14 Aug 2023 22:28:36 +1000 [thread overview]
Message-ID: <87fs4lerkb.fsf@mail.lhotse> (raw)
In-Reply-To: <20230811-strncpy-arch-powerpc-platforms-ps3-v1-1-301052a5663e@google.com>
Justin Stitt <justinstitt@google.com> writes:
> This approach simply replicates the implementation of `make_field` which
> means we drop `strncpy` for `memcpy`.
>
> Signed-off-by: Justin Stitt <justinstitt@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;
> }
I guess it's a slight improvement, because people generally know
memcpy's behaviour better than strncpy.
The change log should be a bit more verbose and mention that the result
is the same, including the NULL padding done my strncpy().
cheers
WARNING: multiple messages have this Message-ID (diff)
From: Michael Ellerman <mpe@ellerman.id.au>
To: Justin Stitt <justinstitt@google.com>,
Geoff Levand <geoff@infradead.org>,
Nicholas Piggin <npiggin@gmail.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Kees Cook <keescook@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>,
linux-kernel@vger.kernel.org,
Nathan Chancellor <nathan@kernel.org>,
linux-hardening@vger.kernel.org,
Justin Stitt <justinstitt@google.com>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH RFC 1/3] powerpc/ps3: refactor strncpy usage attempt 1
Date: Mon, 14 Aug 2023 22:28:36 +1000 [thread overview]
Message-ID: <87fs4lerkb.fsf@mail.lhotse> (raw)
In-Reply-To: <20230811-strncpy-arch-powerpc-platforms-ps3-v1-1-301052a5663e@google.com>
Justin Stitt <justinstitt@google.com> writes:
> This approach simply replicates the implementation of `make_field` which
> means we drop `strncpy` for `memcpy`.
>
> Signed-off-by: Justin Stitt <justinstitt@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;
> }
I guess it's a slight improvement, because people generally know
memcpy's behaviour better than strncpy.
The change log should be a bit more verbose and mention that the result
is the same, including the NULL padding done my strncpy().
cheers
next prev parent reply other threads:[~2023-08-14 12:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 21:19 [PATCH RFC 0/3] powerpc/ps3: refactor strncpy usage Justin Stitt
2023-08-11 21:19 ` Justin Stitt
2023-08-11 21:19 ` [PATCH RFC 1/3] powerpc/ps3: refactor strncpy usage attempt 1 Justin Stitt
2023-08-11 21:19 ` Justin Stitt
2023-08-14 12:28 ` Michael Ellerman [this message]
2023-08-14 12:28 ` Michael Ellerman
2023-08-11 21:19 ` [PATCH RFC 2/3] powerpc/ps3: refactor strncpy usage attempt 2 Justin Stitt
2023-08-11 21:19 ` Justin Stitt
2023-08-14 23:13 ` Kees Cook
2023-08-14 23:13 ` Kees Cook
2023-08-11 21:19 ` [PATCH RFC 3/3] powerpc/ps3: refactor strncpy usage attempt 2.5 Justin Stitt
2023-08-11 21:19 ` Justin Stitt
2023-08-11 21:25 ` [PATCH RFC 0/3] powerpc/ps3: refactor strncpy usage Justin Stitt
2023-08-11 21:25 ` Justin Stitt
2023-08-14 12:31 ` Michael Ellerman
2023-08-14 12:31 ` Michael Ellerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fs4lerkb.fsf@mail.lhotse \
--to=mpe@ellerman.id.au \
--cc=christophe.leroy@csgroup.eu \
--cc=geoff@infradead.org \
--cc=justinstitt@google.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.