Skip to contentSkip to conversation

drivers: dio: replace deprecated strcpy with strscpy in dio_init

PATCH In review Thorsten Blum 2 participants 4 messages May 4

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drivers: dio: replace deprecated strcpy with strscpy in dio_init

strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. While the current code works correctly, replace strcpy() with the safer strscpy() to follow secure coding best practices.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

---
 drivers/dio/dio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dio/dio.c +1 -1
index 419b3c13d491..4a3ddda97d7c 100644
@@ -247,7 +247,7 @@ static int __init dio_init(void)
 			dev->id = prid;
 
 		dev->ipl = DIO_IPL(va);
-		strcpy(dev->name, dio_getname(dev->id));
+		strscpy(dev->name, dio_getname(dev->id));
                 printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
 		if (DIO_NEEDSSECID(prid))
                         printk(":%02X", secid);
#1 lore raw

PATCH v2 2/2 drivers: dio: use tabs and avoid continuation logging in dio_init

Indent multiple lines using tabs instead of spaces. Use pr_info() and avoid continuation logging.

---
 drivers/dio/dio.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/dio/dio.c +7 -6
index 4a3ddda97d7c..b39ae25d060e 100644
@@ -178,7 +178,7 @@ static int __init dio_init(void)
 	if (!MACH_IS_HP300)
 		return 0;
 
-        printk(KERN_INFO "Scanning for DIO devices...\n");
+	pr_info("Scanning for DIO devices...\n");
 
 	/* Initialize the DIO bus */
 	INIT_LIST_HEAD(&dio_bus.devices);
@@ -248,17 +248,18 @@ static int __init dio_init(void)
 
 		dev->ipl = DIO_IPL(va);
 		strscpy(dev->name, dio_getname(dev->id));
-                printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
 		if (DIO_NEEDSSECID(prid))
-                        printk(":%02X", secid);
-                printk(": %s\n", dev->name);
+			pr_info("select code %3d: ipl %d: ID %02X:%02X: %s\n",
+				dev->scode, dev->ipl, prid, secid, dev->name);
+		else
+			pr_info("select code %3d: ipl %d: ID %02X: %s\n",
+				dev->scode, dev->ipl, prid, dev->name);
 
 		if (scode >= DIOII_SCBASE)
 			iounmap(va);
 		error = device_register(&dev->dev);
 		if (error) {
-			pr_err("DIO: Error registering device %s\n",
-			       dev->name);
+			pr_err("DIO: Error registering device %s\n", dev->name);
 			put_device(&dev->dev);
 			continue;
 		}
Reviewed-by on v2 1/2
#3 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. While the current code works correctly, replace strcpy() with the safer strscpy() to follow secure coding best practices.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

i.e. will queue in the m68k tree for v7.2.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] drivers: dio: use tabs and avoid continuation logging in dio_init

In reply to Thorsten Blum

Hi Thorsten,

Quoted 4 lines · Thorsten Blum

Indent multiple lines using tabs instead of spaces. Use pr_info() and avoid continuation logging.

i.e. will queue in the m68k tree for v7.2.

Quoted 6 lines
drivers/dio/dio.c +0 -0
@@ -248,17 +248,18 @@ static int __init dio_init(void)
 
                dev->ipl = DIO_IPL(va);

drivers/dio/dio.c static int __init dio_init(void) · line 256

Quoted 10 lines
drivers/dio/dio.c +5 -3
                strscpy(dev->name, dio_getname(dev->id));
-                printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
                if (DIO_NEEDSSECID(prid))
-                        printk(":%02X", secid);
-                printk(": %s\n", dev->name);
+                       pr_info("select code %3d: ipl %d: ID %02X:%02X: %s\n",
+                               dev->scode, dev->ipl, prid, secid, dev->name);
+               else
+                       pr_info("select code %3d: ipl %d: ID %02X: %s\n",
+                               dev->scode, dev->ipl, prid, dev->name);

I'll change these "%d" to print dev->ipl to "%u" while applying.

drivers/dio/dio.c static int __init dio_init(void) · line 259

Quoted 3 lines
drivers/dio/dio.c +0 -0
                if (scode >= DIOII_SCBASE)
                        iounmap(va);

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds