Whamcloud - gitweb
LU-12615 mdt: check mdt_object 64/35764/2
authorHongchao Zhang <hongchao@whamcloud.com>
Sat, 13 Jul 2019 12:07:07 +0000 (08:07 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 21 Aug 2019 04:48:08 +0000 (04:48 +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.

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

index 5386503..25ab57a 100644 (file)
@@ -1380,9 +1380,11 @@ static int mdt_getattr(struct tgt_session_info *tsi)
         int rc, rc2;
         ENTRY;
 
         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 */
        LASSERT(lu_object_assert_exists(&obj->mot_obj));
 
        /* Special case for Data-on-MDT files to get data version */
@@ -1540,6 +1542,8 @@ static int mdt_swap_layouts(struct tgt_session_info *tsi)
                RETURN(-EOPNOTSUPP);
 
        info = tsi2mdt_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);
 
        if (info->mti_dlm_req != NULL)
                ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
@@ -2589,6 +2593,9 @@ static int mdt_sync(struct tgt_session_info *tsi)
        } else {
                struct mdt_thread_info *info = tsi2mdt_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);
                /* sync an object */
                rc = mdt_object_sync(tsi->tsi_env, tsi->tsi_exp,
                                     info->mti_object);
@@ -4284,6 +4291,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;
                          u64);
        enum tgt_handler_flags it_handler_flags = 0;
        struct ldlm_reply *rep;
+       bool check_mdt_object = false;
        int rc;
        ENTRY;
 
        int rc;
        ENTRY;
 
@@ -4300,12 +4308,14 @@ static int mdt_intent_opc(enum ldlm_intent_flags it_opc,
                it_handler = &mdt_intent_open;
                break;
        case IT_GETATTR:
                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 = HAS_REPLY;
                break;
        case IT_GETXATTR:
        case IT_LOOKUP:
                it_format = &RQF_LDLM_INTENT_GETATTR;
                it_handler = &mdt_intent_getattr;
                it_handler_flags = HAS_REPLY;
                break;
        case IT_GETXATTR:
+               check_mdt_object = true;
                it_format = &RQF_LDLM_INTENT_GETXATTR;
                it_handler = &mdt_intent_getxattr;
                it_handler_flags = HAS_BODY;
                it_format = &RQF_LDLM_INTENT_GETXATTR;
                it_handler = &mdt_intent_getxattr;
                it_handler_flags = HAS_BODY;
@@ -4351,6 +4361,9 @@ static int mdt_intent_opc(enum ldlm_intent_flags it_opc,
        if (rc < 0)
                RETURN(rc);
 
        if (rc < 0)
                RETURN(rc);
 
+       if (unlikely(info->mti_object == NULL && check_mdt_object))
+               RETURN(-EPROTO);
+
        if (it_handler_flags & IS_MUTABLE && mdt_rdonly(req->rq_export))
                RETURN(-EROFS);
 
        if (it_handler_flags & IS_MUTABLE && mdt_rdonly(req->rq_export))
                RETURN(-EROFS);
 
@@ -5114,6 +5127,9 @@ static int mdt_tgt_getxattr(struct tgt_session_info *tsi)
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
        int                      rc;
 
        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);
        rc = mdt_getxattr(info);
 
        mdt_thread_info_fini(info);