From f8e915bc0946772ab9c92a8e3c37211716cbd395 Mon Sep 17 00:00:00 2001 From: Alexander Boyko Date: Mon, 14 Oct 2019 03:31:35 -0400 Subject: [PATCH] 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. Lustre-change: https://review.whamcloud.com/36443 Lustre-commit: 2a620f07e23b3b044f429f049bcc5ffa96f6d844 Cray-bug-id: LUS-7676 Signed-off-by: Alexander Boyko Change-Id: Ifad95c1177258b6f71effe5fa815f68c8426c516 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 Reviewed-on: https://review.whamcloud.com/37305 Tested-by: jenkins Tested-by: Maloo --- lustre/include/lu_object.h | 13 +++++++++++++ lustre/ldlm/ldlm_lib.c | 2 ++ lustre/mdd/mdd_object.c | 7 +------ lustre/mdt/mdt_internal.h | 7 +------ lustre/mgs/mgs_internal.h | 13 +------------ lustre/ofd/ofd_internal.h | 7 +------ lustre/osp/osp_internal.h | 10 +--------- lustre/quota/lquota_internal.h | 10 +--------- lustre/quota/qmt_internal.h | 10 +--------- lustre/quota/qsd_internal.h | 10 +--------- 10 files changed, 23 insertions(+), 66 deletions(-) diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 2be6292..c75d311 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1262,6 +1262,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; +} + #ifdef HAVE_SERVER_SUPPORT struct lu_env *lu_env_find(void); int lu_env_add(struct lu_env *env); diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 97d6a953..43ea9de 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -2180,6 +2180,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 2e7afc6..fd26e5f 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 862f136..45c7e8a 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 d4de273..ebb80a4 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 e4733ac..224eece 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -402,12 +402,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 64ef6e3..2c10cb9 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -432,15 +432,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 705490b..dc0ddd8 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 1ac3367..4590046 100644 --- a/lustre/quota/qmt_internal.h +++ b/lustre/quota/qmt_internal.h @@ -205,15 +205,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 a4f6734..5508e62 100644 --- a/lustre/quota/qsd_internal.h +++ b/lustre/quota/qsd_internal.h @@ -265,15 +265,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 */ -- 1.8.3.1