Skip to content

Commit 148bcca

Browse files
Len Bakergeertu
authored andcommitted
soc: renesas: Prefer memcpy() over strcpy()
strcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors. So, use memcpy() as a safe replacement. This is a previous step in the path to remove the strcpy() function entirely from the kernel. Signed-off-by: Len Baker <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent bfe6b55 commit 148bcca

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

drivers/soc/renesas/r8a779a0-sysc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,21 @@ static int __init r8a779a0_sysc_pd_init(void)
404404
for (i = 0; i < info->num_areas; i++) {
405405
const struct r8a779a0_sysc_area *area = &info->areas[i];
406406
struct r8a779a0_sysc_pd *pd;
407+
size_t n;
407408

408409
if (!area->name) {
409410
/* Skip NULLified area */
410411
continue;
411412
}
412413

413-
pd = kzalloc(sizeof(*pd) + strlen(area->name) + 1, GFP_KERNEL);
414+
n = strlen(area->name) + 1;
415+
pd = kzalloc(sizeof(*pd) + n, GFP_KERNEL);
414416
if (!pd) {
415417
error = -ENOMEM;
416418
goto out_put;
417419
}
418420

419-
strcpy(pd->name, area->name);
421+
memcpy(pd->name, area->name, n);
420422
pd->genpd.name = pd->name;
421423
pd->pdr = area->pdr;
422424
pd->flags = area->flags;

drivers/soc/renesas/rcar-sysc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,21 @@ static int __init rcar_sysc_pd_init(void)
396396
for (i = 0; i < info->num_areas; i++) {
397397
const struct rcar_sysc_area *area = &info->areas[i];
398398
struct rcar_sysc_pd *pd;
399+
size_t n;
399400

400401
if (!area->name) {
401402
/* Skip NULLified area */
402403
continue;
403404
}
404405

405-
pd = kzalloc(sizeof(*pd) + strlen(area->name) + 1, GFP_KERNEL);
406+
n = strlen(area->name) + 1;
407+
pd = kzalloc(sizeof(*pd) + n, GFP_KERNEL);
406408
if (!pd) {
407409
error = -ENOMEM;
408410
goto out_put;
409411
}
410412

411-
strcpy(pd->name, area->name);
413+
memcpy(pd->name, area->name, n);
412414
pd->genpd.name = pd->name;
413415
pd->ch.chan_offs = area->chan_offs;
414416
pd->ch.chan_bit = area->chan_bit;

0 commit comments

Comments
 (0)