From 15278c6d32a5a9a7a2b8ac9e08c8702383e0c2ff Mon Sep 17 00:00:00 2001 From: Serguei Smirnov Date: Tue, 19 Nov 2019 14:18:17 -0800 Subject: [PATCH] LU-11385 odbclass: Handle gracefully if nsproxy is NULL 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 Change-Id: Ia102d2bacdb0e54b0339985396447e6d25465c56 Reviewed-on: https://review.whamcloud.com/36802 Reviewed-by: James Simmons Reviewed-by: Sebastien Buisson Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/lustre_compat.h | 6 ++++-- lustre/obdclass/genops.c | 2 +- lustre/obdclass/llog.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lustre/include/lustre_compat.h b/lustre/include/lustre_compat.h index 31794a7..73562da 100644 --- a/lustre/include/lustre_compat.h +++ b/lustre/include/lustre_compat.h @@ -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 diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 1fa7197..d472ba3 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -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; diff --git a/lustre/obdclass/llog.c b/lustre/obdclass/llog.c index c1fa40b..28aa947 100644 --- a/lustre/obdclass/llog.c +++ b/lustre/obdclass/llog.c @@ -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); -- 1.8.3.1