* [PATCH next] nxen/xenbus: Replace strcpy() with memcpy()
@ 2026-06-06 20:25 david.laight.linux
2026-06-08 13:34 ` Jürgen Groß
0 siblings, 1 reply; 2+ messages in thread
From: david.laight.linux @ 2026-06-06 20:25 UTC (permalink / raw)
To: Kees Cook, linux-hardening, Arnd Bergmann, linux-kernel
Cc: Juergen Gross, Stefano Stabellini, David Laight
From: David Laight <david.laight.linux@gmail.com>
The length of the string is calculated in order to allocate the correct
sized memory block, use the same length to copy the string.
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
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/xen/xenbus/xenbus_probe.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index eb260eceb4d2..fafb2b84fa5c 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -514,7 +514,7 @@ int xenbus_probe_node(struct xen_bus_type *bus,
char devname[XEN_BUS_ID_SIZE];
int err;
struct xenbus_device *xendev;
- size_t stringlen;
+ size_t name_len, type_len;
char *tmpstring;
enum xenbus_state state = xenbus_read_driver_state(NULL, nodename);
@@ -525,8 +525,9 @@ int xenbus_probe_node(struct xen_bus_type *bus,
return 0;
}
- stringlen = strlen(nodename) + 1 + strlen(type) + 1;
- xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
+ name_len = strlen(nodename);
+ type_len = strlen(type);
+ xendev = kzalloc(sizeof(*xendev) + name_len + 1 + type_len + 1, GFP_KERNEL);
if (!xendev)
return -ENOMEM;
@@ -535,11 +536,11 @@ int xenbus_probe_node(struct xen_bus_type *bus,
/* Copy the strings into the extra space. */
tmpstring = (char *)(xendev + 1);
- strcpy(tmpstring, nodename);
+ memcpy(tmpstring, nodename, name_len);
xendev->nodename = tmpstring;
- tmpstring += strlen(tmpstring) + 1;
- strcpy(tmpstring, type);
+ tmpstring += name_len + 1;
+ memcpy(tmpstring, type, type_len);
xendev->devicetype = tmpstring;
init_completion(&xendev->down);
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH next] nxen/xenbus: Replace strcpy() with memcpy()
2026-06-06 20:25 [PATCH next] nxen/xenbus: Replace strcpy() with memcpy() david.laight.linux
@ 2026-06-08 13:34 ` Jürgen Groß
0 siblings, 0 replies; 2+ messages in thread
From: Jürgen Groß @ 2026-06-08 13:34 UTC (permalink / raw)
To: david.laight.linux, Kees Cook, linux-hardening, Arnd Bergmann,
linux-kernel
Cc: Stefano Stabellini
[-- Attachment #1.1.1: Type: text/plain, Size: 378 bytes --]
On 06.06.26 22:25, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
>
> The length of the string is calculated in order to allocate the correct
> sized memory block, use the same length to copy the string.
>
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-08 13:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-06 20:25 [PATCH next] nxen/xenbus: Replace strcpy() with memcpy() david.laight.linux
2026-06-08 13:34 ` Jürgen Groß
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox