]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fs/orangefs: Replace kzalloc + copy_from_user with memdup_user_nul
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 18 Sep 2025 15:08:10 +0000 (17:08 +0200)
committerMike Marshall <hubcap@omnibond.com>
Tue, 30 Sep 2025 14:23:24 +0000 (10:23 -0400)
Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to
simplify and improve orangefs_debug_write(). Allocate only 'count' bytes
instead of the maximum size ORANGEFS_MAX_DEBUG_STRING_LEN, and set 'buf'
to NULL to ensure kfree(buf) still works.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
fs/orangefs/orangefs-debugfs.c

index 1c375fb650185c691d21ae3cfa5617f9f32d67e2..79267b3419f2c377880de727143993b7054932d9 100644 (file)
@@ -440,14 +440,13 @@ static ssize_t orangefs_debug_write(struct file *file,
                count = ORANGEFS_MAX_DEBUG_STRING_LEN;
        }
 
-       buf = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
-       if (!buf)
-               goto out;
-
-       if (copy_from_user(buf, ubuf, count - 1)) {
+       buf = memdup_user_nul(ubuf, count - 1);
+       if (IS_ERR(buf)) {
                gossip_debug(GOSSIP_DEBUGFS_DEBUG,
-                            "%s: copy_from_user failed!\n",
+                            "%s: memdup_user_nul failed!\n",
                             __func__);
+               rc = PTR_ERR(buf);
+               buf = NULL;
                goto out;
        }