[lustre-devel] [PATCH 17/25] lnet: check memdup_user_nul using IS_ERR

James Simmons jsimmons at infradead.org
Mon Aug 2 12:50:37 PDT 2021


From: Cyril Bordage <cbordage at whamcloud.com>

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: 986fbf5bf19 ("lnet: libcfs: discard cfs_trace_copyin_string()")
WC-bug-id: https://jira.whamcloud.com/browse/LU-14788
Lustre-commit: 449d046e55a42cc4 ("LU-14788 lnet: check memdup_user_nul using IS_ERR")
Signed-off-by: Cyril Bordage <cbordage at whamcloud.com>
Reviewed-on: https://review.whamcloud.com/44091
Reviewed-by: John L. Hammond <jhammond at whamcloud.com>
Reviewed-by: Andreas Dilger <adilger at whamcloud.com>
Reviewed-by: James Simmons <jsimmons at infradead.org>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 net/lnet/libcfs/module.c    | 4 ++--
 net/lnet/libcfs/tracefile.c | 8 ++++----
 net/lnet/lnet/router_proc.c | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/lnet/libcfs/module.c b/net/lnet/libcfs/module.c
index 8059569..a249bdd 100644
--- a/net/lnet/libcfs/module.c
+++ b/net/lnet/libcfs/module.c
@@ -317,8 +317,8 @@ static int proc_dobitmasks(struct ctl_table *table, int write,
 		}
 	} 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 */
diff --git a/net/lnet/libcfs/tracefile.c b/net/lnet/libcfs/tracefile.c
index 6321840..e0ef234 100644
--- a/net/lnet/libcfs/tracefile.c
+++ b/net/lnet/libcfs/tracefile.c
@@ -942,8 +942,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);
-	if (!str)
-		return -ENOMEM;
+	if (IS_ERR(str))
+		return PTR_ERR(str);
 
 	path = strim(str);
 	if (path[0] != '/')
@@ -1001,8 +1001,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);
-	if (!str)
-		return -ENOMEM;
+	if (IS_ERR(str))
+		return PTR_ERR(str);
 
 	rc = cfs_trace_daemon_command(str);
 	kfree(str);
diff --git a/net/lnet/lnet/router_proc.c b/net/lnet/lnet/router_proc.c
index dd52a08..0de6681 100644
--- a/net/lnet/lnet/router_proc.c
+++ b/net/lnet/lnet/router_proc.c
@@ -816,8 +816,8 @@ static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
 	}
 
 	buf = memdup_user_nul(buffer, nob);
-	if (!buf)
-		return -ENOMEM;
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
 
 	tmp = strim(buf);
 
-- 
1.8.3.1



More information about the lustre-devel mailing list