LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] i2c: sun6i-pw2i: Prefer strscpy over strlcpy
@ 2021-08-17 16:58 Len Baker
  2021-08-17 19:36 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Len Baker @ 2021-08-17 16:58 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec
  Cc: Len Baker, linux-i2c, linux-arm-kernel, linux-sunxi, linux-kernel

strlcpy() reads the entire source buffer first. This read may exceed the
destination size limit. This is both inefficient and can lead to linear
read overflows if a source string is not NUL-terminated. The safe
replacement is strscpy().

This is a previous step in the path to remove the strlcpy() function
entirely from the kernel [1].

[1] https://github.com/KSPP/linux/issues/89

Signed-off-by: Len Baker <len.baker@gmx.com>
---
 drivers/i2c/busses/i2c-sun6i-p2wi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c
index 2f6f6468214d..9e3483f507ff 100644
--- a/drivers/i2c/busses/i2c-sun6i-p2wi.c
+++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c
@@ -234,7 +234,7 @@ static int p2wi_probe(struct platform_device *pdev)
 	if (IS_ERR(p2wi->regs))
 		return PTR_ERR(p2wi->regs);

-	strlcpy(p2wi->adapter.name, pdev->name, sizeof(p2wi->adapter.name));
+	strscpy(p2wi->adapter.name, pdev->name, sizeof(p2wi->adapter.name));
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
--
2.25.1


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

* Re: [PATCH] i2c: sun6i-pw2i: Prefer strscpy over strlcpy
  2021-08-17 16:58 [PATCH] i2c: sun6i-pw2i: Prefer strscpy over strlcpy Len Baker
@ 2021-08-17 19:36 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2021-08-17 19:36 UTC (permalink / raw)
  To: Len Baker
  Cc: Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux-i2c,
	linux-arm-kernel, linux-sunxi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

On Tue, Aug 17, 2021 at 06:58:59PM +0200, Len Baker wrote:
> strlcpy() reads the entire source buffer first. This read may exceed the
> destination size limit. This is both inefficient and can lead to linear
> read overflows if a source string is not NUL-terminated. The safe
> replacement is strscpy().
> 
> This is a previous step in the path to remove the strlcpy() function
> entirely from the kernel [1].
> 
> [1] https://github.com/KSPP/linux/issues/89
> 
> Signed-off-by: Len Baker <len.baker@gmx.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2021-08-17 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 16:58 [PATCH] i2c: sun6i-pw2i: Prefer strscpy over strlcpy Len Baker
2021-08-17 19:36 ` Wolfram Sang

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