From: Alexander Boyko Date: Mon, 14 Oct 2019 07:31:35 +0000 (-0400) Subject: LU-12853 ptlrpc: zero session enviroment X-Git-Tag: 2.13.51~163 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2a620f07e23b3b044f429f049bcc5ffa96f6d844 LU-12853 ptlrpc: zero session enviroment handle_recovery_req() set le_ses for request processing, and doesn't zero it after. This leads to accessing freed memory at keys_fill() later. The patch also adds a cleanup for xxx_env_info, makes them equal and combines to a single function. Cray-bug-id: LUS-7676 Signed-off-by: Alexander Boyko Change-Id: Ifad95c1177258b6f71effe5fa815f68c8426c516 Reviewed-on: https://review.whamcloud.com/36443 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alexander Zarochentsev Reviewed-by: Alexey Lyashkov Reviewed-by: Andriy Skulysh Reviewed-by: Alex Zhuravlev Reviewed-by: Andrew Perepechko Reviewed-by: Mike Pershin Reviewed-by: Sergey Cheremencev Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 8a9635e..80fa26f 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1260,6 +1260,19 @@ void lu_env_fini (struct lu_env *env); int lu_env_refill(struct lu_env *env); int lu_env_refill_by_tags(struct lu_env *env, __u32 ctags, __u32 stags); +static inline void* lu_env_info(const struct lu_env *env, + const struct lu_context_key *key) +{ + void *info; + info = lu_context_key_get(&env->le_ctx, key); + if (!info) { + if (!lu_env_refill((struct lu_env *)env)) + info = lu_context_key_get(&env->le_ctx, key); + } + LASSERT(info); + return info; +} + struct lu_env *lu_env_find(void); int lu_env_add(struct lu_env *env); void lu_env_remove(struct lu_env *env); diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 30d2fd5..be812e7 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -2268,6 +2268,8 @@ static void handle_recovery_req(struct ptlrpc_thread *thread, (void)handler(req); lu_context_exit(&thread->t_env->le_ctx); + req->rq_svc_thread->t_env->le_ses = NULL; + /* don't reset timer for final stage */ if (!exp_finished(req->rq_export)) { time_t to = obd_timeout; diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 0d83356..a9d2a51 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -243,12 +243,7 @@ int mdd_la_get(const struct lu_env *env, struct mdd_object *obj, struct mdd_thread_info *mdd_env_info(const struct lu_env *env) { - struct mdd_thread_info *info; - - lu_env_refill((struct lu_env *)env); - info = lu_context_key_get(&env->le_ctx, &mdd_thread_key); - LASSERT(info != NULL); - return info; + return lu_env_info(env, &mdd_thread_key); } struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len) diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index be7b459..2973f75 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -519,12 +519,7 @@ extern struct lu_context_key mdt_thread_key; static inline struct mdt_thread_info *mdt_th_info(const struct lu_env *env) { - struct mdt_thread_info *mti; - - lu_env_refill((void *)env); - mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - LASSERT(mti); - return mti; + return lu_env_info(env, &mdt_thread_key); } struct cdt_req_progress { diff --git a/lustre/mgs/mgs_internal.h b/lustre/mgs/mgs_internal.h index 8f19130..b7314a5 100644 --- a/lustre/mgs/mgs_internal.h +++ b/lustre/mgs/mgs_internal.h @@ -316,18 +316,7 @@ extern struct lu_context_key mgs_thread_key; static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env) { - struct mgs_thread_info *info; - int rc; - - info = lu_context_key_get(&env->le_ctx, &mgs_thread_key); - if (info == NULL) { - rc = lu_env_refill((struct lu_env *)env); - if (rc != 0) - return ERR_PTR(rc); - info = lu_context_key_get(&env->le_ctx, &mgs_thread_key); - } - LASSERT(info != NULL); - return info; + return lu_env_info(env, &mgs_thread_key); } extern const struct lu_device_operations mgs_lu_ops; diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index f6474b2..7a9a152 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -407,12 +407,7 @@ int ofd_intent_policy(const struct lu_env *env, struct ldlm_namespace *ns, static inline struct ofd_thread_info *ofd_info(const struct lu_env *env) { - struct ofd_thread_info *info; - - lu_env_refill((void *)env); - info = lu_context_key_get(&env->le_ctx, &ofd_thread_key); - LASSERT(info); - return info; + return lu_env_info(env, &ofd_thread_key); } static inline struct ofd_thread_info *ofd_info_init(const struct lu_env *env, diff --git a/lustre/osp/osp_internal.h b/lustre/osp/osp_internal.h index f9b474a..e65284c 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -431,15 +431,7 @@ extern struct lu_context_key osp_thread_key; static inline struct osp_thread_info *osp_env_info(const struct lu_env *env) { - struct osp_thread_info *info; - - info = lu_context_key_get(&env->le_ctx, &osp_thread_key); - if (info == NULL) { - lu_env_refill((struct lu_env *)env); - info = lu_context_key_get(&env->le_ctx, &osp_thread_key); - } - LASSERT(info); - return info; + return lu_env_info(env, &osp_thread_key); } struct osp_txn_info { diff --git a/lustre/quota/lquota_internal.h b/lustre/quota/lquota_internal.h index 009eb5c..f8f8340 100644 --- a/lustre/quota/lquota_internal.h +++ b/lustre/quota/lquota_internal.h @@ -334,15 +334,7 @@ extern struct lu_context_key lquota_thread_key; static inline struct lquota_thread_info *lquota_info(const struct lu_env *env) { - struct lquota_thread_info *info; - - info = lu_context_key_get(&env->le_ctx, &lquota_thread_key); - if (info == NULL) { - lu_env_refill((struct lu_env *)env); - info = lu_context_key_get(&env->le_ctx, &lquota_thread_key); - } - LASSERT(info); - return info; + return lu_env_info(env, &lquota_thread_key); } #define req_is_acq(flags) ((flags & QUOTA_DQACQ_FL_ACQ) != 0) diff --git a/lustre/quota/qmt_internal.h b/lustre/quota/qmt_internal.h index e88e9b8..a3ab56f 100644 --- a/lustre/quota/qmt_internal.h +++ b/lustre/quota/qmt_internal.h @@ -202,15 +202,7 @@ extern struct lu_context_key qmt_thread_key; static inline struct qmt_thread_info *qmt_info(const struct lu_env *env) { - struct qmt_thread_info *info; - - info = lu_context_key_get(&env->le_ctx, &qmt_thread_key); - if (info == NULL) { - lu_env_refill((struct lu_env *)env); - info = lu_context_key_get(&env->le_ctx, &qmt_thread_key); - } - LASSERT(info); - return info; + return lu_env_info(env, &qmt_thread_key); } /* helper routine to convert a lu_device into a qmt_device */ diff --git a/lustre/quota/qsd_internal.h b/lustre/quota/qsd_internal.h index bebce66..7a015f2 100644 --- a/lustre/quota/qsd_internal.h +++ b/lustre/quota/qsd_internal.h @@ -262,15 +262,7 @@ extern struct lu_context_key qsd_thread_key; static inline struct qsd_thread_info *qsd_info(const struct lu_env *env) { - struct qsd_thread_info *info; - - info = lu_context_key_get(&env->le_ctx, &qsd_thread_key); - if (info == NULL) { - lu_env_refill((struct lu_env *)env); - info = lu_context_key_get(&env->le_ctx, &qsd_thread_key); - } - LASSERT(info); - return info; + return lu_env_info(env, &qsd_thread_key); } /* helper function to check whether a given quota type is enabled */