* [PATCH v2] drm/etnaviv: refactor deprecated strncpy
@ 2023-09-18 13:34 Justin Stitt
2023-09-24 2:53 ` Kees Cook
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Justin Stitt @ 2023-09-18 13:34 UTC (permalink / raw)
To: Lucas Stach, Russell King, Christian Gmeiner, David Airlie,
Daniel Vetter
Cc: etnaviv, dri-devel, linux-kernel, linux-hardening, Bo YU,
Justin Stitt
`strncpy` is deprecated for use on NUL-terminated destination strings [1].
We should prefer more robust and less ambiguous string interfaces.
A suitable replacement is `strscpy_pad` due to the fact that it
guarantees NUL-termination on the destination buffer whilst maintaining
the NUL-padding behavior that strncpy provides.
Link: https://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
Cc: Bo YU <tsu.yubo@gmail.com>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Changes in v2:
- use strscpy_pad (thanks Kees)
- Link to v1: https://lore.kernel.org/r/20230914-strncpy-drivers-gpu-drm-etnaviv-etnaviv_perfmon-c-v1-1-3adc2d9bfc52@google.com
---
Similar to [2] which was never picked up. Let's prefer strscpy_pad to strlcpy, though
[2]: https://lore.kernel.org/all/20190328080918.9290-1-tsu.yubo@gmail.com/
---
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
index bafdfe49c1d8..dc9dea664a28 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
@@ -511,7 +511,7 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
domain->id = domain->iter;
domain->nr_signals = dom->nr_signals;
- strncpy(domain->name, dom->name, sizeof(domain->name));
+ strscpy_pad(domain->name, dom->name, sizeof(domain->name));
domain->iter++;
if (domain->iter == nr_domains)
@@ -540,7 +540,7 @@ int etnaviv_pm_query_sig(struct etnaviv_gpu *gpu,
sig = &dom->signal[signal->iter];
signal->id = signal->iter;
- strncpy(signal->name, sig->name, sizeof(signal->name));
+ strscpy_pad(signal->name, sig->name, sizeof(signal->name));
signal->iter++;
if (signal->iter == dom->nr_signals)
---
base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
change-id: 20230914-strncpy-drivers-gpu-drm-etnaviv-etnaviv_perfmon-c-dd095491dfde
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] drm/etnaviv: refactor deprecated strncpy
2023-09-18 13:34 [PATCH v2] drm/etnaviv: refactor deprecated strncpy Justin Stitt
@ 2023-09-24 2:53 ` Kees Cook
2023-10-06 20:23 ` Kees Cook
2023-10-11 17:03 ` Lucas Stach
2 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2023-09-24 2:53 UTC (permalink / raw)
To: Justin Stitt
Cc: Lucas Stach, Russell King, Christian Gmeiner, David Airlie,
Daniel Vetter, etnaviv, dri-devel, linux-kernel, linux-hardening,
Bo YU
On Mon, Sep 18, 2023 at 01:34:08PM +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>
> We should prefer more robust and less ambiguous string interfaces.
>
> A suitable replacement is `strscpy_pad` due to the fact that it
> guarantees NUL-termination on the destination buffer whilst maintaining
> the NUL-padding behavior that strncpy provides.
>
> Link: https://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
> Cc: Bo YU <tsu.yubo@gmail.com>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Looks good to me now. Thanks!
Reviewed-by: Kees Cook <keescook@chromium.org>
(Though again if you need a v3, making the Subject more specific would
be nice, "...: Replace strncpy with strscpy_pad"
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/etnaviv: refactor deprecated strncpy
2023-09-18 13:34 [PATCH v2] drm/etnaviv: refactor deprecated strncpy Justin Stitt
2023-09-24 2:53 ` Kees Cook
@ 2023-10-06 20:23 ` Kees Cook
2023-10-09 9:13 ` Christian Gmeiner
2023-10-11 17:03 ` Lucas Stach
2 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2023-10-06 20:23 UTC (permalink / raw)
To: Justin Stitt
Cc: Lucas Stach, Russell King, Christian Gmeiner, David Airlie,
Daniel Vetter, etnaviv, dri-devel, linux-kernel, linux-hardening,
Bo YU
On Mon, Sep 18, 2023 at 01:34:08PM +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>
> We should prefer more robust and less ambiguous string interfaces.
>
> A suitable replacement is `strscpy_pad` due to the fact that it
> guarantees NUL-termination on the destination buffer whilst maintaining
> the NUL-padding behavior that strncpy provides.
Friend ping. Who can pick this change up?
Thanks!
-Kees
>
> Link: https://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
> Cc: Bo YU <tsu.yubo@gmail.com>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> Changes in v2:
> - use strscpy_pad (thanks Kees)
> - Link to v1: https://lore.kernel.org/r/20230914-strncpy-drivers-gpu-drm-etnaviv-etnaviv_perfmon-c-v1-1-3adc2d9bfc52@google.com
> ---
> Similar to [2] which was never picked up. Let's prefer strscpy_pad to strlcpy, though
>
> [2]: https://lore.kernel.org/all/20190328080918.9290-1-tsu.yubo@gmail.com/
> ---
> drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> index bafdfe49c1d8..dc9dea664a28 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> @@ -511,7 +511,7 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
>
> domain->id = domain->iter;
> domain->nr_signals = dom->nr_signals;
> - strncpy(domain->name, dom->name, sizeof(domain->name));
> + strscpy_pad(domain->name, dom->name, sizeof(domain->name));
>
> domain->iter++;
> if (domain->iter == nr_domains)
> @@ -540,7 +540,7 @@ int etnaviv_pm_query_sig(struct etnaviv_gpu *gpu,
> sig = &dom->signal[signal->iter];
>
> signal->id = signal->iter;
> - strncpy(signal->name, sig->name, sizeof(signal->name));
> + strscpy_pad(signal->name, sig->name, sizeof(signal->name));
>
> signal->iter++;
> if (signal->iter == dom->nr_signals)
>
> ---
> base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
> change-id: 20230914-strncpy-drivers-gpu-drm-etnaviv-etnaviv_perfmon-c-dd095491dfde
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/etnaviv: refactor deprecated strncpy
2023-10-06 20:23 ` Kees Cook
@ 2023-10-09 9:13 ` Christian Gmeiner
0 siblings, 0 replies; 5+ messages in thread
From: Christian Gmeiner @ 2023-10-09 9:13 UTC (permalink / raw)
To: Kees Cook
Cc: Justin Stitt, Lucas Stach, Russell King, David Airlie,
Daniel Vetter, etnaviv, dri-devel, linux-kernel, linux-hardening,
Bo YU
Am Fr., 6. Okt. 2023 um 22:23 Uhr schrieb Kees Cook <keescook@chromium.org>:
>
> On Mon, Sep 18, 2023 at 01:34:08PM +0000, Justin Stitt wrote:
> > `strncpy` is deprecated for use on NUL-terminated destination strings [1].
> >
> > We should prefer more robust and less ambiguous string interfaces.
> >
> > A suitable replacement is `strscpy_pad` due to the fact that it
> > guarantees NUL-termination on the destination buffer whilst maintaining
> > the NUL-padding behavior that strncpy provides.
>
> Friend ping. Who can pick this change up?
>
Lucas is the one who is responsible for this job.
>
> Thanks!
>
> -Kees
>
> >
> > Link: https://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
> > Cc: Bo YU <tsu.yubo@gmail.com>
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
--
greets
--
Christian Gmeiner, MSc
https://christian-gmeiner.info/privacypolicy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/etnaviv: refactor deprecated strncpy
2023-09-18 13:34 [PATCH v2] drm/etnaviv: refactor deprecated strncpy Justin Stitt
2023-09-24 2:53 ` Kees Cook
2023-10-06 20:23 ` Kees Cook
@ 2023-10-11 17:03 ` Lucas Stach
2 siblings, 0 replies; 5+ messages in thread
From: Lucas Stach @ 2023-10-11 17:03 UTC (permalink / raw)
To: Justin Stitt, Russell King, Christian Gmeiner, David Airlie,
Daniel Vetter
Cc: etnaviv, dri-devel, linux-kernel, linux-hardening, Bo YU
Am Montag, dem 18.09.2023 um 13:34 +0000 schrieb Justin Stitt:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>
> We should prefer more robust and less ambiguous string interfaces.
>
> A suitable replacement is `strscpy_pad` due to the fact that it
> guarantees NUL-termination on the destination buffer whilst maintaining
> the NUL-padding behavior that strncpy provides.
>
> Link: https://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
> Cc: Bo YU <tsu.yubo@gmail.com>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Thanks, applied to my etnaviv/next branch.
Regards,
Lucas
> ---
> Changes in v2:
> - use strscpy_pad (thanks Kees)
> - Link to v1: https://lore.kernel.org/r/20230914-strncpy-drivers-gpu-drm-etnaviv-etnaviv_perfmon-c-v1-1-3adc2d9bfc52@google.com
> ---
> Similar to [2] which was never picked up. Let's prefer strscpy_pad to strlcpy, though
>
> [2]: https://lore.kernel.org/all/20190328080918.9290-1-tsu.yubo@gmail.com/
> ---
> drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> index bafdfe49c1d8..dc9dea664a28 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> @@ -511,7 +511,7 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
>
> domain->id = domain->iter;
> domain->nr_signals = dom->nr_signals;
> - strncpy(domain->name, dom->name, sizeof(domain->name));
> + strscpy_pad(domain->name, dom->name, sizeof(domain->name));
>
> domain->iter++;
> if (domain->iter == nr_domains)
> @@ -540,7 +540,7 @@ int etnaviv_pm_query_sig(struct etnaviv_gpu *gpu,
> sig = &dom->signal[signal->iter];
>
> signal->id = signal->iter;
> - strncpy(signal->name, sig->name, sizeof(signal->name));
> + strscpy_pad(signal->name, sig->name, sizeof(signal->name));
>
> signal->iter++;
> if (signal->iter == dom->nr_signals)
>
> ---
> base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
> change-id: 20230914-strncpy-drivers-gpu-drm-etnaviv-etnaviv_perfmon-c-dd095491dfde
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-11 17:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-18 13:34 [PATCH v2] drm/etnaviv: refactor deprecated strncpy Justin Stitt
2023-09-24 2:53 ` Kees Cook
2023-10-06 20:23 ` Kees Cook
2023-10-09 9:13 ` Christian Gmeiner
2023-10-11 17:03 ` Lucas Stach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox