Whamcloud - gitweb
LU-12853 ptlrpc: zero session enviroment 43/36443/2
authorAlexander Boyko <c17825@cray.com>
Mon, 14 Oct 2019 07:31:35 +0000 (03:31 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 6 Dec 2019 01:03:26 +0000 (01:03 +0000)
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 <c17825@cray.com>
Change-Id: Ifad95c1177258b6f71effe5fa815f68c8426c516
Reviewed-on: https://review.whamcloud.com/36443
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexander Zarochentsev <c17826@cray.com>
Reviewed-by: Alexey Lyashkov <c17817@cray.com>
Reviewed-by: Andriy Skulysh <c17819@cray.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Andrew Perepechko <c17827@cray.com>
Reviewed-by: Mike Pershin <mpershin@whamcloud.com>
Reviewed-by: Sergey Cheremencev <c17829@cray.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lu_object.h
lustre/ldlm/ldlm_lib.c
lustre/mdd/mdd_object.c
lustre/mdt/mdt_internal.h
lustre/mgs/mgs_internal.h
lustre/ofd/ofd_internal.h
lustre/osp/osp_internal.h
lustre/quota/lquota_internal.h
lustre/quota/qmt_internal.h
lustre/quota/qsd_internal.h

index 8a9635e..80fa26f 100644 (file)
@@ -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);
index 30d2fd5..be812e7 100644 (file)
@@ -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;
index 0d83356..a9d2a51 100644 (file)
@@ -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)
index be7b459..2973f75 100644 (file)
@@ -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 {
index 8f19130..b7314a5 100644 (file)
@@ -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;
index f6474b2..7a9a152 100644 (file)
@@ -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,
index f9b474a..e65284c 100644 (file)
@@ -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 {
index 009eb5c..f8f8340 100644 (file)
@@ -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)
index e88e9b8..a3ab56f 100644 (file)
@@ -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 */
index bebce66..7a015f2 100644 (file)
@@ -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 */