All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] asm-generic: fix buffer overflow read in __strncpy_from_user
@ 2022-06-27  6:32 Yangxi Xiang
  2022-06-27  6:58 ` Arnd Bergmann
  0 siblings, 1 reply; 8+ messages in thread
From: Yangxi Xiang @ 2022-06-27  6:32 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: stable, Yangxi Xiang

a common calling pattern is strncpy_from_user(buf, user_ptr, sizeof(buf)).
However a buffer-overflow read occurs in this loop when reading the last
byte. Fix it by early checking the available bytes.

Signed-off-by: Yangxi Xiang <xyangxi5@gmail.com>
---
 include/asm-generic/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index a0b2f270dddc..d45d4f535934 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -252,7 +252,7 @@ __strncpy_from_user(char *dst, const char __user *src, long count)
 {
 	char *tmp;
 	strncpy(dst, (const char __force *)src, count);
-	for (tmp = dst; *tmp && count > 0; tmp++, count--)
+	for (tmp = dst; count > 0 && *tmp; tmp++, count--)
 		;
 	return (tmp - dst);
 }
-- 
2.17.1


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

end of thread, other threads:[~2022-06-27 11:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27  6:32 [PATCH] asm-generic: fix buffer overflow read in __strncpy_from_user Yangxi Xiang
2022-06-27  6:58 ` Arnd Bergmann
2022-06-27  7:40   ` Yangxi Xiang
2022-06-27  8:55     ` Arnd Bergmann
2022-06-27  9:38       ` Yangxi Xiang
2022-06-27 10:19         ` Arnd Bergmann
2022-06-27 10:42           ` Yangxi Xiang
2022-06-27 11:00           ` Greg KH

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.