Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2901305rwb; Mon, 7 Aug 2023 05:29:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0IrVu7ND28k0+xl9bQ9bPa/BzJ/toXCUfOGjkoZ8pBDQgEWKKBi41gXme8ebp1hCo2NAg X-Received: by 2002:a05:6a00:248c:b0:668:82fe:16f1 with SMTP id c12-20020a056a00248c00b0066882fe16f1mr11975075pfv.1.1691411376784; Mon, 07 Aug 2023 05:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691411376; cv=none; d=google.com; s=arc-20160816; b=nAyvdoyfkCktsMYczY5pvRbk6N5jKKC4tVH0vsxoJQpmyA6fvV+A7nFVLK4w5eZQCP xtx1e6idXkkcWBUObCLRW/IV00cvx0EU2hCZQPuCzD/lOYnT2+2qYdFUhyDN+17kBwc6 q7FqJDdfGvvnq3mYEI8SgDbGGSYb376SHy07gLxA88w3u1dceDp3S2PyvglXPTwF+qfE zw8RHj1ih907eZvSU35MJv43F2W2IA7ZodbJKRtbpHfNvL4NzHtUEGDlPWHpfa4zLWGc UjnPv4Loi6Sak1ijP0iPa0ziy11nuiMiFkCZEYNv/aVq6rkwcmtlQqU/d5Nj44IF5F+q KmJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=kzWjjr1YkRI8PC5b8h88z+oHcsBj7GLkdaZmjiCU1zM=; fh=qxh+wIqLlbHQVEewY25bM7+8dGrpmnwqIA4sVyewhK4=; b=cexDGqNEbF6nQj7Hi+pw5DkVpuBp1wgCC2tYw/Luo5yS3SPgqM2fdjs1xjx3Px68Jc 7H3XS9yXvvA8ARJhzDi3lBK2BwhUzTqLNr3dm8RUKjdjaRkPu17U7zvx3WdujhxvsG4D EouwpA1KNmjD0xHaB7gNH01pHiu3zH52RSNw6OJWkWIDzVUfMSjVPmYkT/chLJ3eaxkI H1zM/xIihHfyVuExErsGaWcEFrZZAYpDAPp5shDDhpmRaEj96IN9KbMbka68CGPM5mM7 /E/t7CIElTQohx1rfZsnk8MmKrSdscxHz2BbaotwtkQQtSP9OOMRP0HZUWHi+SaZ93QZ S2EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RVo5TqWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x30-20020a634a1e000000b005538c82b70esi2644269pga.101.2023.08.07.05.29.24; Mon, 07 Aug 2023 05:29:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RVo5TqWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233085AbjHGLl5 (ORCPT + 99 others); Mon, 7 Aug 2023 07:41:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbjHGLlh (ORCPT ); Mon, 7 Aug 2023 07:41:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B25435B6 for ; Mon, 7 Aug 2023 04:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691408169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kzWjjr1YkRI8PC5b8h88z+oHcsBj7GLkdaZmjiCU1zM=; b=RVo5TqWcYOWsbcuK1ErmEh5BQFvCO6/GDDQ7pG/aI0DphWRqKC1Dj3gATFyj7ivhDSOE1D yiCKEYU0tXYlROvlBS3j8yeGVauM+0eV0PsLzrWxSsKqbi7A6wVA/zUruUIP43c+s6tu2+ 0gjUoWTKwWwesvP260I0Uxui4RXGoss= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-442-s4quCZ5wNc6JSFLIdZLeuA-1; Mon, 07 Aug 2023 07:21:50 -0400 X-MC-Unique: s4quCZ5wNc6JSFLIdZLeuA-1 Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-268108bc0f9so4090112a91.1 for ; Mon, 07 Aug 2023 04:21:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407309; x=1692012109; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kzWjjr1YkRI8PC5b8h88z+oHcsBj7GLkdaZmjiCU1zM=; b=GUzG63oafbQVGnyKjMVwzHCOgEgXUgc1TDGSRB3HPa6mgofHpYwljrj/4JkNPvg99q YsvhLXKVU/KwcuthKybAodhxSAyIETNHtY9G2afg/RlzNvBw45SuzYyqgztfxwHvm4xq mj/vRzTRlnI0b0VRRNp2eGdAUAQ8QwXcw0QpImxss97KWDMX4qIsvxsm7vd5XVbkxR/h gUa4LHc14BYjR/G24vDPVPfokaq2VChD29dx6S7pl0QGD7njLwA5vnYjYBeBt/5RykYq 8IFubD1ZwH+uNA+rbzlTHG2ejerXhJQmRXXG9SOnJZDxP2iZ3beqEOZoyxb2yFhX8d63 7k8Q== X-Gm-Message-State: AOJu0YxSsufDDms8u6h/3Ict/mFdlSOuNDRW0GaT1Ar0wLHZ5n+ieXFC dUMPiKpYLpS7nJR8QTnlWjY9Kr7tMZtviZTyjJBUtVin72eTDMecD4GAy/UkqxuHL0NWRn5aULy H7zFUESXF+Xa3NKbSfjiLOmbS X-Received: by 2002:a17:90b:1b46:b0:269:44a3:bd1e with SMTP id nv6-20020a17090b1b4600b0026944a3bd1emr4508937pjb.40.1691407309021; Mon, 07 Aug 2023 04:21:49 -0700 (PDT) X-Received: by 2002:a17:90b:1b46:b0:269:44a3:bd1e with SMTP id nv6-20020a17090b1b4600b0026944a3bd1emr4508918pjb.40.1691407308654; Mon, 07 Aug 2023 04:21:48 -0700 (PDT) Received: from [10.72.112.77] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id b1-20020a17090a800100b00263f41a655esm5709045pjn.43.2023.08.07.04.21.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Aug 2023 04:21:48 -0700 (PDT) Message-ID: Date: Mon, 7 Aug 2023 19:21:42 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v9 03/12] ceph: handle idmapped mounts in create_request_message() Content-Language: en-US To: Aleksandr Mikhalitsyn Cc: brauner@kernel.org, stgraber@ubuntu.com, linux-fsdevel@vger.kernel.org, Jeff Layton , Ilya Dryomov , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230804084858.126104-1-aleksandr.mikhalitsyn@canonical.com> <20230804084858.126104-4-aleksandr.mikhalitsyn@canonical.com> <8446e5c9-7dd7-a1e9-e262-13811ee9e640@redhat.com> From: Xiubo Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/7/23 18:34, Aleksandr Mikhalitsyn wrote: > On Mon, Aug 7, 2023 at 12:28 PM Xiubo Li wrote: >> >> On 8/7/23 14:51, Aleksandr Mikhalitsyn wrote: >>> On Mon, Aug 7, 2023 at 3:25 AM Xiubo Li wrote: >>>> On 8/4/23 16:48, Alexander Mikhalitsyn wrote: >>>>> From: Christian Brauner >>>>> >>>>> Inode operations that create a new filesystem object such as ->mknod, >>>>> ->create, ->mkdir() and others don't take a {g,u}id argument explicitly. >>>>> Instead the caller's fs{g,u}id is used for the {g,u}id of the new >>>>> filesystem object. >>>>> >>>>> In order to ensure that the correct {g,u}id is used map the caller's >>>>> fs{g,u}id for creation requests. This doesn't require complex changes. >>>>> It suffices to pass in the relevant idmapping recorded in the request >>>>> message. If this request message was triggered from an inode operation >>>>> that creates filesystem objects it will have passed down the relevant >>>>> idmaping. If this is a request message that was triggered from an inode >>>>> operation that doens't need to take idmappings into account the initial >>>>> idmapping is passed down which is an identity mapping. >>>>> >>>>> This change uses a new cephfs protocol extension CEPHFS_FEATURE_HAS_OWNER_UIDGID >>>>> which adds two new fields (owner_{u,g}id) to the request head structure. >>>>> So, we need to ensure that MDS supports it otherwise we need to fail >>>>> any IO that comes through an idmapped mount because we can't process it >>>>> in a proper way. MDS server without such an extension will use caller_{u,g}id >>>>> fields to set a new inode owner UID/GID which is incorrect because caller_{u,g}id >>>>> values are unmapped. At the same time we can't map these fields with an >>>>> idmapping as it can break UID/GID-based permission checks logic on the >>>>> MDS side. This problem was described with a lot of details at [1], [2]. >>>>> >>>>> [1] https://lore.kernel.org/lkml/CAEivzxfw1fHO2TFA4dx3u23ZKK6Q+EThfzuibrhA3RKM=ZOYLg@mail.gmail.com/ >>>>> [2] https://lore.kernel.org/all/20220104140414.155198-3-brauner@kernel.org/ >>>>> >>>>> Link: https://github.com/ceph/ceph/pull/52575 >>>>> Link: https://tracker.ceph.com/issues/62217 >>>>> Cc: Xiubo Li >>>>> Cc: Jeff Layton >>>>> Cc: Ilya Dryomov >>>>> Cc: ceph-devel@vger.kernel.org >>>>> Co-Developed-by: Alexander Mikhalitsyn >>>>> Signed-off-by: Christian Brauner >>>>> Signed-off-by: Alexander Mikhalitsyn >>>>> --- >>>>> v7: >>>>> - reworked to use two new fields for owner UID/GID (https://github.com/ceph/ceph/pull/52575) >>>>> v8: >>>>> - properly handled case when old MDS used with new kernel client >>>>> --- >>>>> fs/ceph/mds_client.c | 47 +++++++++++++++++++++++++++++++++--- >>>>> fs/ceph/mds_client.h | 5 +++- >>>>> include/linux/ceph/ceph_fs.h | 5 +++- >>>>> 3 files changed, 52 insertions(+), 5 deletions(-) >>>>> >>>>> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c >>>>> index 8829f55103da..41e4bf3811c4 100644 >>>>> --- a/fs/ceph/mds_client.c >>>>> +++ b/fs/ceph/mds_client.c >>>>> @@ -2902,6 +2902,17 @@ static void encode_mclientrequest_tail(void **p, const struct ceph_mds_request * >>>>> } >>>>> } >>>>> >>>>> +static inline u16 mds_supported_head_version(struct ceph_mds_session *session) >>>>> +{ >>>>> + if (!test_bit(CEPHFS_FEATURE_32BITS_RETRY_FWD, &session->s_features)) >>>>> + return 1; >>>>> + >>>>> + if (!test_bit(CEPHFS_FEATURE_HAS_OWNER_UIDGID, &session->s_features)) >>>>> + return 2; >>>>> + >>>>> + return CEPH_MDS_REQUEST_HEAD_VERSION; >>>>> +} >>>>> + >>>>> static struct ceph_mds_request_head_legacy * >>>>> find_legacy_request_head(void *p, u64 features) >>>>> { >>>>> @@ -2923,6 +2934,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, >>>>> { >>>>> int mds = session->s_mds; >>>>> struct ceph_mds_client *mdsc = session->s_mdsc; >>>>> + struct ceph_client *cl = mdsc->fsc->client; >>>>> struct ceph_msg *msg; >>>>> struct ceph_mds_request_head_legacy *lhead; >>>>> const char *path1 = NULL; >>>>> @@ -2936,7 +2948,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, >>>>> void *p, *end; >>>>> int ret; >>>>> bool legacy = !(session->s_con.peer_features & CEPH_FEATURE_FS_BTIME); >>>>> - bool old_version = !test_bit(CEPHFS_FEATURE_32BITS_RETRY_FWD, &session->s_features); >>>>> + u16 request_head_version = mds_supported_head_version(session); >>>>> >>>>> ret = set_request_path_attr(mdsc, req->r_inode, req->r_dentry, >>>>> req->r_parent, req->r_path1, req->r_ino1.ino, >>>>> @@ -2977,8 +2989,10 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, >>>>> */ >>>>> if (legacy) >>>>> len = sizeof(struct ceph_mds_request_head_legacy); >>>>> - else if (old_version) >>>>> + else if (request_head_version == 1) >>>>> len = sizeof(struct ceph_mds_request_head_old); >>>>> + else if (request_head_version == 2) >>>>> + len = offsetofend(struct ceph_mds_request_head, ext_num_fwd); >>>>> else >>>>> len = sizeof(struct ceph_mds_request_head); >>>>> >>>>> @@ -3028,6 +3042,16 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, >>>>> lhead = find_legacy_request_head(msg->front.iov_base, >>>>> session->s_con.peer_features); >>>>> >>>>> + if ((req->r_mnt_idmap != &nop_mnt_idmap) && >>>>> + !test_bit(CEPHFS_FEATURE_HAS_OWNER_UIDGID, &session->s_features)) { >>>>> + pr_err_ratelimited_client(cl, >>>>> + "idmapped mount is used and CEPHFS_FEATURE_HAS_OWNER_UIDGID" >>>>> + " is not supported by MDS. Fail request with -EIO.\n"); >>>>> + >>>>> + ret = -EIO; >>>>> + goto out_err; >>>>> + } >>>>> + >>>>> /* >>>>> * The ceph_mds_request_head_legacy didn't contain a version field, and >>>>> * one was added when we moved the message version from 3->4. >>>>> @@ -3035,17 +3059,34 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, >>>>> if (legacy) { >>>>> msg->hdr.version = cpu_to_le16(3); >>>>> p = msg->front.iov_base + sizeof(*lhead); >>>>> - } else if (old_version) { >>>>> + } else if (request_head_version == 1) { >>>>> struct ceph_mds_request_head_old *ohead = msg->front.iov_base; >>>>> >>>>> msg->hdr.version = cpu_to_le16(4); >>>>> ohead->version = cpu_to_le16(1); >>>>> p = msg->front.iov_base + sizeof(*ohead); >>>>> + } else if (request_head_version == 2) { >>>>> + struct ceph_mds_request_head *nhead = msg->front.iov_base; >>>>> + >>>>> + msg->hdr.version = cpu_to_le16(6); >>>>> + nhead->version = cpu_to_le16(2); >>>>> + >>>>> + p = msg->front.iov_base + offsetofend(struct ceph_mds_request_head, ext_num_fwd); >>>>> } else { >>>>> struct ceph_mds_request_head *nhead = msg->front.iov_base; >>>>> + kuid_t owner_fsuid; >>>>> + kgid_t owner_fsgid; >>>>> >>>>> msg->hdr.version = cpu_to_le16(6); >>>>> nhead->version = cpu_to_le16(CEPH_MDS_REQUEST_HEAD_VERSION); >>>>> + nhead->struct_len = sizeof(struct ceph_mds_request_head); >>>>> + >>>>> + owner_fsuid = from_vfsuid(req->r_mnt_idmap, &init_user_ns, >>>>> + VFSUIDT_INIT(req->r_cred->fsuid)); >>>>> + owner_fsgid = from_vfsgid(req->r_mnt_idmap, &init_user_ns, >>>>> + VFSGIDT_INIT(req->r_cred->fsgid)); >>>>> + nhead->owner_uid = cpu_to_le32(from_kuid(&init_user_ns, owner_fsuid)); >>>>> + nhead->owner_gid = cpu_to_le32(from_kgid(&init_user_ns, owner_fsgid)); >>>>> p = msg->front.iov_base + sizeof(*nhead); >>>>> } >>>>> >>>>> diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h >>>>> index e3bbf3ba8ee8..8f683e8203bd 100644 >>>>> --- a/fs/ceph/mds_client.h >>>>> +++ b/fs/ceph/mds_client.h >>>>> @@ -33,8 +33,10 @@ enum ceph_feature_type { >>>>> CEPHFS_FEATURE_NOTIFY_SESSION_STATE, >>>>> CEPHFS_FEATURE_OP_GETVXATTR, >>>>> CEPHFS_FEATURE_32BITS_RETRY_FWD, >>>>> + CEPHFS_FEATURE_NEW_SNAPREALM_INFO, >>>>> + CEPHFS_FEATURE_HAS_OWNER_UIDGID, >>>>> >>>>> - CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_32BITS_RETRY_FWD, >>>>> + CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_HAS_OWNER_UIDGID, >>>>> }; >>>>> >>>>> #define CEPHFS_FEATURES_CLIENT_SUPPORTED { \ >>>>> @@ -49,6 +51,7 @@ enum ceph_feature_type { >>>>> CEPHFS_FEATURE_NOTIFY_SESSION_STATE, \ >>>>> CEPHFS_FEATURE_OP_GETVXATTR, \ >>>>> CEPHFS_FEATURE_32BITS_RETRY_FWD, \ >>>>> + CEPHFS_FEATURE_HAS_OWNER_UIDGID, \ >>>>> } >>>>> >>>>> /* >>>>> diff --git a/include/linux/ceph/ceph_fs.h b/include/linux/ceph/ceph_fs.h >>>>> index 5f2301ee88bc..b91699b08f26 100644 >>>>> --- a/include/linux/ceph/ceph_fs.h >>>>> +++ b/include/linux/ceph/ceph_fs.h >>>>> @@ -499,7 +499,7 @@ struct ceph_mds_request_head_legacy { >>>>> union ceph_mds_request_args args; >>>>> } __attribute__ ((packed)); >>>>> >>>>> -#define CEPH_MDS_REQUEST_HEAD_VERSION 2 >>>>> +#define CEPH_MDS_REQUEST_HEAD_VERSION 3 >>>>> >>>>> struct ceph_mds_request_head_old { >>>>> __le16 version; /* struct version */ >>>>> @@ -530,6 +530,9 @@ struct ceph_mds_request_head { >>>>> >>>>> __le32 ext_num_retry; /* new count retry attempts */ >>>>> __le32 ext_num_fwd; /* new count fwd attempts */ >>>>> + >>>>> + __le32 struct_len; /* to store size of struct ceph_mds_request_head */ >>>>> + __le32 owner_uid, owner_gid; /* used for OPs which create inodes */ >>>> Let's also initialize them to -1 for all the other requests as we do in >>>> your PR. >>> They are always initialized already. As you can see from the code we >>> don't have any extra conditions >>> on filling these fields. We always fill them with an appropriate >>> UID/GID. If mount is not idmapped then it's just == caller_uid/gid, >>> if mount idmapped then it's idmapped caller_uid/gid. >> Then in kclient all the request will always initialized the >> 'owner_{uid/gid}' with 'caller_{uid/gid}'. While in userspace libcephfs >> it will only set them for 'create/mknod/mkdir/symlink` instead. >> >> I'd prefer to make them consistent, which is what I am still focusing >> on, to make them easier to read and comparing when troubles hooting. > Dear Xiubo, > > Sure, I will do it. > > Couldn't you please review all the rest of the patches before I fix > this particular thing? > It will allow me to fix and send -v10 with all required fixes > incorporated in it. I have gone through them all and they LGTM. Thanks - Xiubo > Kind regards, > Alex > >> Thanks >> >> - Xiubo >> >>> Kind regards, >>> Alex >>> >>>> Thanks >>>> >>>> - Xiubo >>>> >>>> >>>> >>>>> } __attribute__ ((packed)); >>>>> >>>>> /* cap/lease release record */