* [PATCH] drm/gma500: refactor deprecated strncpy
@ 2023-09-14 20:52 Justin Stitt
2023-09-15 4:37 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Justin Stitt @ 2023-09-14 20:52 UTC (permalink / raw)
To: Patrik Jakobsson, David Airlie, Daniel Vetter
Cc: dri-devel, linux-kernel, linux-hardening, Justin Stitt
`strncpy` is deprecated for use on NUL-terminated destination strings [1].
We should prefer more robust and less ambiguous string interfaces.
Since `chan->base.name` is expected to be NUL-terminated, a suitable
replacement is `strscpy` [2] due to the fact that it guarantees
NUL-termination on the destination buffer without also unnecessarily
NUL-padding.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
drm/gma500: refactor deprecated strncpy
---
drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c b/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
index 06b5b2d70d48..68458cbdd6d5 100644
--- a/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
+++ b/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
@@ -141,7 +141,7 @@ struct gma_i2c_chan *oaktrail_lvds_i2c_init(struct drm_device *dev)
chan->drm_dev = dev;
chan->reg = dev_priv->lpc_gpio_base;
- strncpy(chan->base.name, "gma500 LPC", I2C_NAME_SIZE - 1);
+ strscpy(chan->base.name, "gma500 LPC", I2C_NAME_SIZE - 1);
chan->base.owner = THIS_MODULE;
chan->base.algo_data = &chan->algo;
chan->base.dev.parent = dev->dev;
---
base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
change-id: 20230914-drivers-gpu-drm-gma500-oaktrail_lvds_i2c-c-a53c6d8bd62f
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/gma500: refactor deprecated strncpy
2023-09-14 20:52 [PATCH] drm/gma500: refactor deprecated strncpy Justin Stitt
@ 2023-09-15 4:37 ` Kees Cook
2023-09-18 7:16 ` Patrik Jakobsson
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2023-09-15 4:37 UTC (permalink / raw)
To: Justin Stitt
Cc: Patrik Jakobsson, David Airlie, Daniel Vetter, dri-devel,
linux-kernel, linux-hardening
On Thu, Sep 14, 2023 at 08:52:21PM +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.
>
> Since `chan->base.name` is expected to be NUL-terminated, a suitable
> replacement is `strscpy` [2] due to the fact that it guarantees
> NUL-termination on the destination buffer without also unnecessarily
> NUL-padding.
How did you decide about %NUL padding? (I see it is kzalloc'd, so it
doesn't matter.)
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
>
>
> drm/gma500: refactor deprecated strncpy
> ---
> drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c b/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
> index 06b5b2d70d48..68458cbdd6d5 100644
> --- a/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
> +++ b/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
> @@ -141,7 +141,7 @@ struct gma_i2c_chan *oaktrail_lvds_i2c_init(struct drm_device *dev)
>
> chan->drm_dev = dev;
> chan->reg = dev_priv->lpc_gpio_base;
> - strncpy(chan->base.name, "gma500 LPC", I2C_NAME_SIZE - 1);
> + strscpy(chan->base.name, "gma500 LPC", I2C_NAME_SIZE - 1);
What's going on here with the destination buffer size? chan->base.name
is 48 bytes. I2C_NAME_SIZE is 20.
Ultimately it doesn't matter since the source is a const char string,
but it's still weird. Therefore:
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> chan->base.owner = THIS_MODULE;
> chan->base.algo_data = &chan->algo;
> chan->base.dev.parent = dev->dev;
>
> ---
> base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
> change-id: 20230914-drivers-gpu-drm-gma500-oaktrail_lvds_i2c-c-a53c6d8bd62f
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/gma500: refactor deprecated strncpy
2023-09-15 4:37 ` Kees Cook
@ 2023-09-18 7:16 ` Patrik Jakobsson
0 siblings, 0 replies; 3+ messages in thread
From: Patrik Jakobsson @ 2023-09-18 7:16 UTC (permalink / raw)
To: Kees Cook
Cc: Justin Stitt, David Airlie, Daniel Vetter, dri-devel,
linux-kernel, linux-hardening
On Thu, Sep 14, 2023 at 09:37:31PM -0700, Kees Cook wrote:
> On Thu, Sep 14, 2023 at 08:52:21PM +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.
> >
> > Since `chan->base.name` is expected to be NUL-terminated, a suitable
> > replacement is `strscpy` [2] due to the fact that it guarantees
> > NUL-termination on the destination buffer without also unnecessarily
> > NUL-padding.
>
> How did you decide about %NUL padding? (I see it is kzalloc'd, so it
> doesn't matter.)
>
> >
> > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
> > Link: https://github.com/KSPP/linux/issues/90
> > Cc: linux-hardening@vger.kernel.org
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > ---
> >
> >
> > drm/gma500: refactor deprecated strncpy
> > ---
> > drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c b/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
> > index 06b5b2d70d48..68458cbdd6d5 100644
> > --- a/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
> > +++ b/drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
> > @@ -141,7 +141,7 @@ struct gma_i2c_chan *oaktrail_lvds_i2c_init(struct drm_device *dev)
> >
> > chan->drm_dev = dev;
> > chan->reg = dev_priv->lpc_gpio_base;
> > - strncpy(chan->base.name, "gma500 LPC", I2C_NAME_SIZE - 1);
> > + strscpy(chan->base.name, "gma500 LPC", I2C_NAME_SIZE - 1);
>
> What's going on here with the destination buffer size? chan->base.name
> is 48 bytes. I2C_NAME_SIZE is 20.
It seems I2C_NAME_SIZE is used for i2c_client.name but is abused here
for i2c_adapter.name as well. Using sizeof() would be better. Justin,
would you mind changing that as well?
Thanks
Patrik
>
> Ultimately it doesn't matter since the source is a const char string,
> but it's still weird. Therefore:
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
> -Kees
>
> > chan->base.owner = THIS_MODULE;
> > chan->base.algo_data = &chan->algo;
> > chan->base.dev.parent = dev->dev;
> >
> > ---
> > base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
> > change-id: 20230914-drivers-gpu-drm-gma500-oaktrail_lvds_i2c-c-a53c6d8bd62f
> >
> > Best regards,
> > --
> > Justin Stitt <justinstitt@google.com>
> >
>
> --
> Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-18 7:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 20:52 [PATCH] drm/gma500: refactor deprecated strncpy Justin Stitt
2023-09-15 4:37 ` Kees Cook
2023-09-18 7:16 ` Patrik Jakobsson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®