From 449d046e55a42cc4d1c4ab0217551cded1864bc4 Mon Sep 17 00:00:00 2001 From: Cyril Bordage Date: Mon, 28 Jun 2021 15:13:21 +0200 Subject: [PATCH] LU-14788 lnet: check memdup_user_nul using IS_ERR 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 Change-Id: I1fabf2499b6bbee7b94a2f802fbcbd9270d901b3 Reviewed-on: https://review.whamcloud.com/44091 Reviewed-by: John L. Hammond Tested-by: jenkins Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/libcfs/module.c | 4 ++-- libcfs/libcfs/tracefile.c | 8 ++++---- lnet/lnet/router_proc.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 549a98c..f966e61 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -307,8 +307,8 @@ static int __proc_dobitmasks(void *data, 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/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 6bb451d..5db7394 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -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); - if (!str) - return -ENOMEM; + if (IS_ERR(str)) + return PTR_ERR(str); 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); - if (!str) - return -ENOMEM; + if (IS_ERR(str)) + return PTR_ERR(str); rc = cfs_trace_daemon_command(strim(str)); kfree(str); diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index 8f839d4..7edc4a8 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -829,8 +829,8 @@ static int __proc_lnet_portal_rotor(void *data, 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