* [PATCH] um: Remove strlcpy declaration
@ 2023-07-03 16:06 Azeem Shaikh
2023-07-12 23:57 ` Kees Cook
2023-07-27 15:52 ` Kees Cook
0 siblings, 2 replies; 3+ messages in thread
From: Azeem Shaikh @ 2023-07-03 16:06 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg
Cc: linux-hardening, Azeem Shaikh, linux-um, linux-kernel,
Jason A. Donenfeld, Kees Cook, Haowen Bai
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/include/shared/user.h | 1 -
arch/um/os-Linux/umid.c | 6 +++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h
index 0347a190429c..981e11d8e025 100644
--- a/arch/um/include/shared/user.h
+++ b/arch/um/include/shared/user.h
@@ -50,7 +50,6 @@ static inline int printk(const char *fmt, ...)
#endif
extern int in_aton(char *str);
-extern size_t strlcpy(char *, const char *, size_t);
extern size_t strlcat(char *, const char *, size_t);
extern size_t strscpy(char *, const char *, size_t);
diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c
index 7a1abb829930..288c422bfa96 100644
--- a/arch/um/os-Linux/umid.c
+++ b/arch/um/os-Linux/umid.c
@@ -40,7 +40,7 @@ static int __init make_uml_dir(void)
__func__);
goto err;
}
- strlcpy(dir, home, sizeof(dir));
+ strscpy(dir, home, sizeof(dir));
uml_dir++;
}
strlcat(dir, uml_dir, sizeof(dir));
@@ -243,7 +243,7 @@ int __init set_umid(char *name)
if (strlen(name) > UMID_LEN - 1)
return -E2BIG;
- strlcpy(umid, name, sizeof(umid));
+ strscpy(umid, name, sizeof(umid));
return 0;
}
@@ -262,7 +262,7 @@ static int __init make_umid(void)
make_uml_dir();
if (*umid == '\0') {
- strlcpy(tmp, uml_dir, sizeof(tmp));
+ strscpy(tmp, uml_dir, sizeof(tmp));
strlcat(tmp, "XXXXXX", sizeof(tmp));
fd = mkstemp(tmp);
if (fd < 0) {
--
2.41.0.255.g8b1d071c50-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] um: Remove strlcpy declaration
2023-07-03 16:06 [PATCH] um: Remove strlcpy declaration Azeem Shaikh
@ 2023-07-12 23:57 ` Kees Cook
2023-07-27 15:52 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-07-12 23:57 UTC (permalink / raw)
To: Azeem Shaikh
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg, linux-hardening,
linux-um, linux-kernel, Jason A. Donenfeld, Haowen Bai
On Mon, Jul 03, 2023 at 04:06:41PM +0000, Azeem Shaikh wrote:
> 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>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] um: Remove strlcpy declaration
2023-07-03 16:06 [PATCH] um: Remove strlcpy declaration Azeem Shaikh
2023-07-12 23:57 ` Kees Cook
@ 2023-07-27 15:52 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-07-27 15:52 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg, Azeem Shaikh
Cc: Kees Cook, linux-hardening, linux-um, linux-kernel,
Jason A. Donenfeld, Haowen Bai
On Mon, 03 Jul 2023 16:06:41 +0000, Azeem Shaikh wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] um: Remove strlcpy declaration
https://git.kernel.org/kees/c/61ce78f29a69
Best regards,
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-27 15:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-03 16:06 [PATCH] um: Remove strlcpy declaration Azeem Shaikh
2023-07-12 23:57 ` Kees Cook
2023-07-27 15:52 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox