Skip to contentSkip to conversation

lib: Add might_fault() to strncpy_from_user.

PATCH Applied KP Singh 1 participant 1 message Apr 14, 2020 Library code

lore
Share & tools
lore

KP Singh

author
#0 lore raw

PATCH 1/1 lib: Add might_fault() to strncpy_from_user.

From: KP Singh <[email protected]>

When updating a piece of broken logic from using get_user to strncpy_from_user, we noticed that a warning which is expected when calling a function that might fault from an atomic context with pagefaults enabled disappeared.

Not having this warning in place can lead to calling strncpy_from_user from an atomic context and eventually kernel crashes/stack corruption.

Cc Jann Horn <[email protected]>
---
 lib/strncpy_from_user.c | 1 +
 1 file changed, 1 insertion(+)
lib/strncpy_from_user.c +1 -0
index 706020b06617..16e78d0bb5d4 100644
@@ -98,6 +98,7 @@ long strncpy_from_user(char *dst, const char __user *src, long count)
 {
 	unsigned long max_addr, src_addr;
 
+	might_fault();
 	if (unlikely(count <= 0))
 		return 0;
 
Signature · 1 line
2.26.0.110.g2183baf09c-goog