All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 next] drivers/md/md: Use bounded strings ops when setting disk->disk_name
@ 2026-06-26  8:43 David Laight
  2026-06-26  8:51 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2026-06-26  8:43 UTC (permalink / raw)
  To: Kees Cook, linux-hardening, linux-kernel, linux-raid
  Cc: Arnd Bergmann, Song Liu, Yu Kuai, David Laight

Replace strcpy() with strscpy() and sprintf() with snprintf() for safety.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---

v2: Make sizeof look like a function call for consistency.

This is one of a group of patches that remove potentially unbounded
strcpy() calls.

They are mostly replaced by strscpy() or, when strlen() has just been
called, with memcpy() (usually including the '\0').

Calls with copy string literals into arrays are left unchanged.
They are safe and easily detected as such.

The changes were made by getting the compiler to detect the calls and
then fixing the code by hand.

Note that all the changes are only compile tested.

Some Makefiles were changed to allow files to contain strcpy().
As well as 'difficult to fix' files, this included 'show' functions
as they really need to use sysfs_emit() or seq_printf().

All the patches are being sent individually to avoid very long cc lists.
Apologies for the terse commit messages and likely unexpected tags.
(There are about 100 patches in total.)

 drivers/md/md.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 8b568eee8743..4b659d10fa4d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -6346,11 +6346,11 @@ struct mddev *md_alloc(dev_t dev, char *name)
 	disk->first_minor = unit << shift;
 	disk->minors = 1 << shift;
 	if (name)
-		strcpy(disk->disk_name, name);
+		strscpy(disk->disk_name, name);
 	else if (partitioned)
-		sprintf(disk->disk_name, "md_d%d", unit);
+		snprintf(disk->disk_name, sizeof(disk->disk_name), "md_d%d", unit);
 	else
-		sprintf(disk->disk_name, "md%d", unit);
+		snprintf(disk->disk_name, sizeof (disk->disk_name), "md%d", unit);
 	disk->fops = &md_fops;
 	disk->private_data = mddev;
 
-- 
2.39.5


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

end of thread, other threads:[~2026-06-26 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26  8:43 [PATCH v2 next] drivers/md/md: Use bounded strings ops when setting disk->disk_name David Laight
2026-06-26  8:51 ` sashiko-bot
2026-06-26 10:52   ` David Laight

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.