Skip to contentSkip to conversation

i2c: Replace all non-returning strlcpy with strscpy

PATCH In review Azeem Shaikh 4 participants 6 messages May 23, 2023 – May 24, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: Replace all non-returning strlcpy with strscpy

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 [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 drivers/leds/flash/leds-as3645a.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/flash/leds-as3645a.c +2 -2
index bb2249771acb..7dc574b18f5f 100644
@@ -651,8 +651,8 @@ static int as3645a_v4l2_setup(struct as3645a *flash)
 		},
 	};
 
-	strlcpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name));
-	strlcpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name,
+	strscpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name));
+	strscpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name,
 		sizeof(cfgind.dev_name));
 
 	flash->vf = v4l2_flash_init(
maintainer
#1 lore raw
Quoted 8 lines · Azeem Shaikh

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 [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

Quoted 7 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 drivers/leds/flash/leds-as3645a.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Please resubmit, taking the time to check the subject line please.

Quoted 16 lines
drivers/leds/flash/leds-as3645a.c +2 -2
index bb2249771acb..7dc574b18f5f 100644
@@ -651,8 +651,8 @@ static int as3645a_v4l2_setup(struct as3645a *flash)
 		},
 	};
 
-	strlcpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name));
-	strlcpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name,
+	strscpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name));
+	strscpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name,
 		sizeof(cfgind.dev_name));
 
 	flash->vf = v4l2_flash_init(
Signature · 1 line
Lee Jones [李琼斯]
#2 lore raw

Hi Lee, Azeem,

Quoted 13 lines · Lee Jones
Quoted 11 lines · Azeem Shaikh

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 [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Quoted 6 lines
Quoted 4 lines
---
 drivers/leds/flash/leds-as3645a.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Please resubmit, taking the time to check the subject line please.

I'd say also shorter description will suffice. Nowadays people understand the motivation replacing strlcpy() by strscpy() without too much elaboration. Lines may be up to 74 characters long, too, and period isn't automatically followed by a newline.

The patch itself seems fine.

I also prefer my @linux.intel.com address, as in MAINTAINERS for this driver.

Signature · 3 lines
Kind regards,

Sakari Ailus
#3 lore raw

Thanks for the quick response Lee and Sakari.

Quoted 22 lines · Sakari Ailus

Hi Lee, Azeem,

Quoted 18 lines · Lee Jones
Quoted 15 lines · Azeem Shaikh

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 [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 drivers/leds/flash/leds-as3645a.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 1 line

Please resubmit, taking the time to check the subject line please.

I'd say also shorter description will suffice. Nowadays people understand the motivation replacing strlcpy() by strscpy() without too much elaboration. Lines may be up to 74 characters long, too, and period isn't automatically followed by a newline.

Let me know if this commit log looks good to you both and I'll send over a v2.

Subject: [PATCH] leds: as3645a: Replace all non-returning strlcpy with strscpy

Part of a tree-wide effort to remove deprecated strlcpy()[1] and replace it with strscpy()[2]. No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Quoted 2 lines

I also prefer my @linux.intel.com address, as in MAINTAINERS for this driver.

Fyi that the email address mentioned for this driver is not the @linux.intel.com -
https://github.com/torvalds/linux/blob/44c026a73be8038f03dbdeef028b642880cf1511/MAINTAINERS#L3070.
I'm happy to send the v2 patch to [email protected] if you prefer that instead.

#4 lore raw

Hi Azeema,

Quoted 34 lines · Azeem Shaikh

Thanks for the quick response Lee and Sakari.

Quoted 22 lines · Sakari Ailus

Hi Lee, Azeem,

Quoted 18 lines · Lee Jones
Quoted 15 lines · Azeem Shaikh

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 [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 drivers/leds/flash/leds-as3645a.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 1 line

Please resubmit, taking the time to check the subject line please.

I'd say also shorter description will suffice. Nowadays people understand the motivation replacing strlcpy() by strscpy() without too much elaboration. Lines may be up to 74 characters long, too, and period isn't automatically followed by a newline.

Quoted 3 lines

Let me know if this commit log looks good to you both and I'll send over a v2.

Subject: [PATCH] leds: as3645a: Replace all non-returning strlcpy with strscpy

All instances are replaced, so you can drop "all non-returning ".

Quoted 7 lines

Part of a tree-wide effort to remove deprecated strlcpy()[1] and replace it with strscpy()[2]. No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Looks good to me.

Quoted 9 lines
Quoted 3 lines

I also prefer my @linux.intel.com address, as in MAINTAINERS for this driver.

Fyi that the email address mentioned for this driver is not the @linux.intel.com -
https://github.com/torvalds/linux/blob/44c026a73be8038f03dbdeef028b642880cf1511/MAINTAINERS#L3070.
I'm happy to send the v2 patch to [email protected] if you prefer that instead.

Oops, my mistake then. :-) I thought I already had changed this. Oh well.

Signature · 3 lines
Regards,

Sakari Ailus
Reviewed-by on v1 1/1
#5 lore raw
In reply to Azeem Shaikh
Quoted 8 lines · Azeem Shaikh

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 [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

Quoted 4 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signature · 1 line
Kees Cook