All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] uml: Replace all non-returning strlcpy with strscpy
@ 2023-05-30 16:40 ` Azeem Shaikh
  0 siblings, 0 replies; 19+ messages in thread
From: Azeem Shaikh @ 2023-05-30 16:40 UTC (permalink / raw)
  To: Maxim Krasnyansky
  Cc: linux-hardening, Azeem Shaikh, linux-kernel, Richard Weinberger,
	Anton Ivanov, Johannes Berg, linux-um

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
---
 arch/um/os-Linux/drivers/tuntap_user.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c
index 53eb3d508645..2284e9c1cbbb 100644
--- a/arch/um/os-Linux/drivers/tuntap_user.c
+++ b/arch/um/os-Linux/drivers/tuntap_user.c
@@ -146,7 +146,7 @@ static int tuntap_open(void *data)
 		}
 		memset(&ifr, 0, sizeof(ifr));
 		ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-		strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
+		strscpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
 		if (ioctl(pri->fd, TUNSETIFF, &ifr) < 0) {
 			err = -errno;
 			printk(UM_KERN_ERR "TUNSETIFF failed, errno = %d\n",


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

end of thread, other threads:[~2023-06-05 20:07 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 16:40 [PATCH] uml: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-30 16:40 ` Azeem Shaikh
2023-05-30 23:21 ` Kees Cook
2023-05-31  3:18 ` kernel test robot
2023-05-31  3:18   ` kernel test robot
2023-05-31  4:41   ` Kees Cook
2023-05-31  4:41     ` Kees Cook
2023-05-31  6:18     ` Johannes Berg
2023-05-31  6:18       ` Johannes Berg
2023-05-31  6:26       ` Richard Weinberger
2023-05-31  6:26         ` Richard Weinberger
2023-05-31  6:23     ` Richard Weinberger
2023-05-31  6:23       ` Richard Weinberger
2023-05-31  8:05       ` Geert Uytterhoeven
2023-05-31  8:05         ` Geert Uytterhoeven
2023-05-31 14:48         ` Azeem Shaikh
2023-05-31 14:48           ` Azeem Shaikh
2023-06-05 20:07           ` Richard Weinberger
2023-06-05 20:07             ` Richard Weinberger

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.