fs/orangefs: Replace kzalloc + copy_from_user with memdup_user_nul
PATCH 1/1 fs/orangefs: Replace kzalloc + copy_from_user with memdup_user_nul
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.
--- fs/orangefs/orangefs-debugfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/orangefs/orangefs-debugfs.c +5 -6
@@ -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; }
Signature · 1 line
2.51.0
Mike Marshall
maintainerThanks, that looks better in several ways. I ran it through xfstests, and have added it to my linux-next tree...
-Mike
Quoted 40 lines · Thorsten Blum
Replace
kzalloc()followed bycopy_from_user()withmemdup_user_nul()to simplify and improveorangefs_debug_write(). Allocate only 'count' bytes instead of the maximum sizeORANGEFS_MAX_DEBUG_STRING_LEN, and set 'buf' to NULL to ensure kfree(buf) still works.No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>--- fs/orangefs/orangefs-debugfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)fs/orangefs/orangefs-debugfs.c +5
-7@@ -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; } --2.51.0