strncpy() may not provide a NUL terminator, which means that a 1-byte
leak would be possible *if* this was ever copied to userspace.  Ensure
the buffer will always be NUL terminated by using the kernel's
strscpy() which a) uses the destination (instead of the source) size
as the bytes to copy and b) is *always* NUL terminated.

Cc: Rodolfo Giometti <[email protected]>
Cc: "Eurotech S.p.A" <[email protected]>
Reported-by: Geert Uytterhoeven <[email protected]>
Acked-by: Arnd Bergmann <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
---
 drivers/misc/c2port/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
index 80d87e8a0bea9..b96444ec94c7e 100644
--- a/drivers/misc/c2port/core.c
+++ b/drivers/misc/c2port/core.c
@@ -923,7 +923,7 @@ struct c2port_device *c2port_device_register(char *name,
        }
        dev_set_drvdata(c2dev->dev, c2dev);
 
-       strncpy(c2dev->name, name, C2PORT_NAME_LEN - 1);
+       strscpy(c2dev->name, name, sizeof(c2dev->name));
        c2dev->ops = ops;
        mutex_init(&c2dev->mutex);
 
-- 
2.25.1

Reply via email to