[PATCH v2 4/6] userns: Use copy_from_user_nul() instead of copy_from_user()

From
Fushuai Wang <hidden>
Date
2026-01-12 07:32:10
Also in
lkml
Reply to
Fushuai Wang, 2026-01-12
From: Fushuai Wang <redacted>

Use copy_from_user_nul() instead of copy_from_user() to simplify
the code.

No functional change.

Signed-off-by: Fushuai Wang <redacted>
---
 kernel/user_namespace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 03cb63883d04..881a05a3502c 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -1239,9 +1239,8 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
 
 	/* What was written? */
 	ret = -EFAULT;
-	if (copy_from_user(kbuf, buf, count))
+	if (copy_from_user_nul(kbuf, buf, count))
 		goto out;
-	kbuf[count] = '\0';
 	pos = kbuf;
 
 	/* What is being requested? */
-- 
2.36.1
Thread (21 messages) 21 messages, 5 authors, last reply 2026-01-16
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help