Whamcloud - gitweb
LU-11385 odbclass: Handle gracefully if nsproxy is NULL 14/37314/2
authorSerguei Smirnov <ssmirnov@whamcloud.com>
Tue, 19 Nov 2019 22:18:17 +0000 (14:18 -0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 27 Jan 2020 23:12:51 +0000 (23:12 +0000)
Gracefully handle the case if current->nsproxy is NULL:
check for the condition and return an error, avoiding attempts
to dereference the pointer.

Lustre-change: https://review.whamcloud.com/36802
Lustre-commit: 15278c6d32a5a9a7a2b8ac9e08c8702383e0c2ff

Signed-off-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Change-Id: Ia102d2bacdb0e54b0339985396447e6d25465c56
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Signed-off-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/37314
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/include/lustre_compat.h
lustre/obdclass/genops.c
lustre/obdclass/llog.c

index 097fc42..534df7c 100644 (file)
@@ -432,9 +432,11 @@ static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
 #endif
 
 #ifdef HAVE_PID_NS_FOR_CHILDREN
-# define ll_task_pid_ns(task)  ((task)->nsproxy->pid_ns_for_children)
+# define ll_task_pid_ns(task) \
+        ((task)->nsproxy ? ((task)->nsproxy->pid_ns_for_children) : NULL)
 #else
-# define ll_task_pid_ns(task)  ((task)->nsproxy->pid_ns)
+# define ll_task_pid_ns(task) \
+        ((task)->nsproxy ? ((task)->nsproxy->pid_ns) : NULL)
 #endif
 
 #ifdef HAVE_FULL_NAME_HASH_3ARGS
index ab319bb..6489c23 100644 (file)
@@ -1317,7 +1317,7 @@ struct obd_import *class_new_import(struct obd_device *obd)
        init_waitqueue_head(&imp->imp_recovery_waitq);
        INIT_WORK(&imp->imp_zombie_work, obd_zombie_imp_cull);
 
-       if (curr_pid_ns->child_reaper)
+       if (curr_pid_ns && curr_pid_ns->child_reaper)
                imp->imp_sec_refpid = curr_pid_ns->child_reaper->pid;
        else
                imp->imp_sec_refpid = 1;
index 534b316..96ffd30 100644 (file)
@@ -739,7 +739,8 @@ static int llog_process_thread_daemonize(void *arg)
                 * used outside of the kernel itself, because it calls
                 * free_nsproxy() which is not exported by the kernel
                 * (defined in kernel/nsproxy.c) */
-               atomic_dec(&curr_ns->count);
+               if (curr_ns)
+                       atomic_dec(&curr_ns->count);
        }
        task_unlock(lpi->lpi_reftask);