Whamcloud - gitweb
LU-12615 mdt: check mdt_object 69/35869/2
authorHongchao Zhang <hongchao@whamcloud.com>
Sat, 13 Jul 2019 12:07:07 +0000 (08:07 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 12 Sep 2019 03:47:55 +0000 (03:47 +0000)
In processing RPC of getattr, getxattr, swap_layouts and sync,
the mdt_object should be checked to verify there is a valid
RMF_MDT_BODY field and OBD_MD_FLID is set properly.

Lustre-change: https://review.whamcloud.com/35764
Lustre-commit: e5e0bdb7a5c2d47ceaa2d1c190806d1be4999129

Change-Id: Ibb6aaa5ec5eb4b7284f4d5567a618a908d66920c
Signed-off-by: Hongchao Zhang <hongchao@whamcloud.com>
Reported-by: Alibaba Cloud <yunye.ry@alibaba-inc.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Emoly Liu <emoly@whamcloud.com>
Signed-off-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/35869
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/mdt/mdt_handler.c

index 884e859..01e0c36 100644 (file)
@@ -1344,9 +1344,11 @@ static int mdt_getattr(struct tgt_session_info *tsi)
         int rc, rc2;
         ENTRY;
 
-        reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
-        LASSERT(reqbody);
-        LASSERT(obj != NULL);
+       if (unlikely(info->mti_object == NULL))
+               RETURN(-EPROTO);
+
+       reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
+       LASSERT(reqbody);
        LASSERT(lu_object_assert_exists(&obj->mot_obj));
 
        /* Special case for Data-on-MDT files to get data version */
@@ -1504,6 +1506,8 @@ static int mdt_swap_layouts(struct tgt_session_info *tsi)
                RETURN(-EOPNOTSUPP);
 
        info = tsi2mdt_info(tsi);
+       if (unlikely(info->mti_object == NULL))
+               RETURN(-EPROTO);
 
        if (info->mti_dlm_req != NULL)
                ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
@@ -2292,6 +2296,9 @@ static int mdt_sync(struct tgt_session_info *tsi)
        } else {
                struct mdt_thread_info *info = tsi2mdt_info(tsi);
 
+               if (unlikely(info->mti_object == NULL))
+                       RETURN(-EPROTO);
+
                /* sync an object */
                rc = mdt_object_sync(tsi->tsi_env, tsi->tsi_exp,
                                     info->mti_object);
@@ -3973,6 +3980,7 @@ static int mdt_intent_opc(enum ldlm_intent_flags it_opc,
                          u64);
        enum tgt_handler_flags it_handler_flags = 0;
        struct ldlm_reply *rep;
+       bool check_mdt_object = false;
        int rc;
        ENTRY;
 
@@ -3989,12 +3997,14 @@ static int mdt_intent_opc(enum ldlm_intent_flags it_opc,
                it_handler = &mdt_intent_open;
                break;
        case IT_GETATTR:
+               check_mdt_object = true;
        case IT_LOOKUP:
                it_format = &RQF_LDLM_INTENT_GETATTR;
                it_handler = &mdt_intent_getattr;
                it_handler_flags = HABEO_REFERO;
                break;
        case IT_GETXATTR:
+               check_mdt_object = true;
                it_format = &RQF_LDLM_INTENT_GETXATTR;
                it_handler = &mdt_intent_getxattr;
                it_handler_flags = HABEO_CORPUS;
@@ -4040,6 +4050,9 @@ static int mdt_intent_opc(enum ldlm_intent_flags it_opc,
        if (rc < 0)
                RETURN(rc);
 
+       if (unlikely(info->mti_object == NULL && check_mdt_object))
+               RETURN(-EPROTO);
+
        if (it_handler_flags & MUTABOR && mdt_rdonly(req->rq_export))
                RETURN(-EROFS);
 
@@ -4799,6 +4812,9 @@ static int mdt_tgt_getxattr(struct tgt_session_info *tsi)
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
        int                      rc;
 
+       if (unlikely(info->mti_object == NULL))
+               return -EPROTO;
+
        rc = mdt_getxattr(info);
 
        mdt_thread_info_fini(info);