Whamcloud - gitweb
LU-14788 lnet: check memdup_user_nul using IS_ERR 91/44091/4
authorCyril Bordage <cbordage@whamcloud.com>
Mon, 28 Jun 2021 13:13:21 +0000 (15:13 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 27 Jul 2021 21:37:37 +0000 (21:37 +0000)
Crash in __proc_lnet_portal_rotor. memdup_user_nul returns an ERR_PTR
on error, not a NULL pointer. IS_ERR and PTR_ERR functions have to be
used to check and return the correct error code. The fix has been
applied in other locations having the wrong check.

Fixes: 67af976c806 ("LU-14428 libcfs: discard cfs_trace_copyin_string()"
Signed-off-by: Cyril Bordage <cbordage@whamcloud.com>
Change-Id: I1fabf2499b6bbee7b94a2f802fbcbd9270d901b3
Reviewed-on: https://review.whamcloud.com/44091
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/module.c
libcfs/libcfs/tracefile.c
lnet/lnet/router_proc.c

index 549a98c..f966e61 100644 (file)
@@ -307,8 +307,8 @@ static int __proc_dobitmasks(void *data, int write,
                }
        } else {
                tmpstr = memdup_user_nul(buffer, nob);
                }
        } else {
                tmpstr = memdup_user_nul(buffer, nob);
-               if (!tmpstr)
-                       return -ENOMEM;
+               if (IS_ERR(tmpstr))
+                       return PTR_ERR(tmpstr);
 
                rc = libcfs_debug_str2mask(mask, strim(tmpstr), is_subsys);
                /* Always print LBUG/LASSERT to console, so keep this mask */
 
                rc = libcfs_debug_str2mask(mask, strim(tmpstr), is_subsys);
                /* Always print LBUG/LASSERT to console, so keep this mask */
index 6bb451d..5db7394 100644 (file)
@@ -904,8 +904,8 @@ int cfs_trace_dump_debug_buffer_usrstr(void __user *usr_str, int usr_str_nob)
        int rc;
 
        str = memdup_user_nul(usr_str, usr_str_nob);
        int rc;
 
        str = memdup_user_nul(usr_str, usr_str_nob);
-       if (!str)
-               return -ENOMEM;
+       if (IS_ERR(str))
+               return PTR_ERR(str);
 
        path = strim(str);
        if (path[0] != '/')
 
        path = strim(str);
        if (path[0] != '/')
@@ -962,8 +962,8 @@ int cfs_trace_daemon_command_usrstr(void __user *usr_str, int usr_str_nob)
        int   rc;
 
        str = memdup_user_nul(usr_str, usr_str_nob);
        int   rc;
 
        str = memdup_user_nul(usr_str, usr_str_nob);
-       if (!str)
-               return -ENOMEM;
+       if (IS_ERR(str))
+               return PTR_ERR(str);
 
        rc = cfs_trace_daemon_command(strim(str));
        kfree(str);
 
        rc = cfs_trace_daemon_command(strim(str));
        kfree(str);
index 8f839d4..7edc4a8 100644 (file)
@@ -829,8 +829,8 @@ static int __proc_lnet_portal_rotor(void *data, int write,
        }
 
        buf = memdup_user_nul(buffer, nob);
        }
 
        buf = memdup_user_nul(buffer, nob);
-       if (!buf)
-               return -ENOMEM;
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
 
        tmp = strim(buf);
 
 
        tmp = strim(buf);