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

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

index 31794a7..73562da 100644 (file)
@@ -377,9 +377,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 1fa7197..d472ba3 100644 (file)
@@ -1267,7 +1267,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 c1fa40b..28aa947 100644 (file)
@@ -748,7 +748,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);