Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2062107rwb; Thu, 27 Jul 2023 01:07:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlEdOyrBklCUpHUZqHyK3MTCV9EI9j99BfPFvr672TJx0vmvCgAwmtolmXW4QM99Uwy6oY4G X-Received: by 2002:a05:6a20:6a27:b0:126:a5e3:3927 with SMTP id p39-20020a056a206a2700b00126a5e33927mr4294469pzk.8.1690445266737; Thu, 27 Jul 2023 01:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690445266; cv=none; d=google.com; s=arc-20160816; b=etgxyiK2plTf7BdgaBW0v9OMPppZTg9pdIQLYgJSoCsgST9DTrzucSN31VTt61a3+1 sLhDl/vYAHVGT9b0zxB/xEMN4eLSdi3SwFdPkHni44Q5VhMqYsHdIeFhiZE9nRfjfPeG c2MrdAgsFjmLM7g1vc1OD3aMF60J185QnNFsiSqR0Y7cjYgjLVeteafaOlaZ3bZM3hNo DXn3/hwkcCVBgOfDtheURPhMKigi4kfhHajJW8auv+jwLn2ONVJnuGnMUVNEHQukjzmm FMIyIdaz+p/E1vAZqxx7roaenwGcJhuh9qD0vk88Rg/cgoUyCZPaHIZaqyn6P2hS/BBV 8Wug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=RKMCuKHuWbZ4j6RU2sqbTQzBCOCRVev47qJw1PwY77A=; fh=19xaUHGIjZDMkughacWs5D3tv+5Avs0HQCkiigtpxhM=; b=0JupRWhZ2r/ec393z6vi56J5YxTgvFxhthCi2jAowO0SUhn7zcMVfhCKxY9dg4utFC 1jrwCDwKjMcHviFxqbixRBSmgneFYmsyis5eZebVcoz/T/asxYje7/Qz9kPJtqN33wBe +FHqnAnq9mDCGzCtcmPeBkBaV+5iP01JMk2CUg7lgwwLmLOioxPvLvwjbB+uFWIUcsIa yImiS2e91XVMclE4FYqNhRV1AB0lNidiNTEZXKMxcilsZDhfZmCAJPxDFiJ8RBPi2bxm FvUIxlUeY0llUA+3D7iN4eoePBzhvIBt7bGvSINULXMDuVBKeGqQJNjeUvKrPpySiIxa OgGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=fk+4zGp5; 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=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cr14-20020a056a000f0e00b0068630737dd8si1050834pfb.105.2023.07.27.01.07.34; Thu, 27 Jul 2023 01:07:46 -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=@canonical.com header.s=20210705 header.b=fk+4zGp5; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231386AbjG0Hmb (ORCPT + 99 others); Thu, 27 Jul 2023 03:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232852AbjG0HmH (ORCPT ); Thu, 27 Jul 2023 03:42:07 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ECF37D99 for ; Thu, 27 Jul 2023 00:35:58 -0700 (PDT) Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 04CF4413C2 for ; Thu, 27 Jul 2023 07:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1690443320; bh=RKMCuKHuWbZ4j6RU2sqbTQzBCOCRVev47qJw1PwY77A=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fk+4zGp5psUPlUD8D/T6E8iXYt3LD6Fee9S2unm+l0Z0gwGrjUNO/8e08ihHP9h15 +04yWu0zMjpEtgagxyxaWddjIeQt8suVchJNLCKrOhgLhZDuyQDCrrWKSO/eaybT40 4rFYktXFQjaB+3279Kwc3SEbIGCGLPPAmUOrm1AxC8wJbfVVQbcM2soQUP1ZsEhFxk F964iZHZBnXbJ2kdrCPg1JTUi55KkMe6bj6DElg4b2AGdrlpnDTRrByKZ1U37sb/6J GWH519ykpWHh4nClAtSD07qHh8kSo46pKFadtscJC415cFAIB+Hx4FKLwZkRA3tm+k Te6x39oDx713g== Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-5844e92ee6bso7070227b3.3 for ; Thu, 27 Jul 2023 00:35:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690443318; x=1691048118; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RKMCuKHuWbZ4j6RU2sqbTQzBCOCRVev47qJw1PwY77A=; b=dTmEptJpevd4gA3xJJ5KYJcrjhpzJIoslJXVFG6MnqrKjtyrrLsfesCl7pSgHy+7FY bq0+KzZ37lwRBv4tv60IVWl8x5P1Z8EaC6b7xAr3sG1iZ3Umu6SaUdTLrL5eJvMYs0b6 d/uBbyTEScBAhjktzX8RpTbJ3+NmcYp/8I3YaFPwjO5l7hWG0hrxVZQpk6TesekGC820 Gwh/UaRuKX3fH0i2uKaEcj4UUsKjMsOTLukTsvzNO0XHMfA+tjfB3Yz9k/F8lLxtPYxE DfkVzOo6oP9DmJ7wixd2epBYh/bMUAfIavlZdTRHPoyzwu08ieeUCz8ENlqk7l6PeumS ElxA== X-Gm-Message-State: ABy/qLaxJUaiwBoqVNVAQZCFwxQOJoPXjN0mTxlig7FhFgJyP77lmirg CFTv/2UOS8iomHMyxU++A9PUkTUuFuY//jKxtrAAALyybajeIeSHUl5APoAGvlaHkENw7rW2RhD eJJfOCuN6nTWe4NHHRpw7IyQCI3Nrx/s43Tzby6r+WXWOdvW4/QFm0D/8MX6G7WeZYHA6 X-Received: by 2002:a25:d2cf:0:b0:d11:254a:aa71 with SMTP id j198-20020a25d2cf000000b00d11254aaa71mr3956784ybg.44.1690443318636; Thu, 27 Jul 2023 00:35:18 -0700 (PDT) X-Received: by 2002:a25:d2cf:0:b0:d11:254a:aa71 with SMTP id j198-20020a25d2cf000000b00d11254aaa71mr3956776ybg.44.1690443318423; Thu, 27 Jul 2023 00:35:18 -0700 (PDT) MIME-Version: 1.0 References: <20230726141026.307690-1-aleksandr.mikhalitsyn@canonical.com> <20230726141026.307690-4-aleksandr.mikhalitsyn@canonical.com> In-Reply-To: <20230726141026.307690-4-aleksandr.mikhalitsyn@canonical.com> From: Aleksandr Mikhalitsyn Date: Thu, 27 Jul 2023 09:35:07 +0200 Message-ID: Subject: Re: [PATCH v7 03/11] ceph: handle idmapped mounts in create_request_message() To: xiubli@redhat.com 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, Jul 26, 2023 at 4:10=E2=80=AFPM Alexander Mikhalitsyn wrote: > Oops, have just noticed. Author of this commit should be Christian Brauner. It's because I've squashed this commit into the previous one (which was the commit that updated struct ceph_mds_request_head). I'll fix that next time. > 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+EThfzuibrh= A3RKM=3DZOYLg@mail.gmail.com/ > [2] https://lore.kernel.org/all/20220104140414.155198-3-brauner@kernel.or= g/ > > 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://githu= b.com/ceph/ceph/pull/52575) > --- > fs/ceph/mds_client.c | 20 ++++++++++++++++++++ > fs/ceph/mds_client.h | 5 ++++- > include/linux/ceph/ceph_fs.h | 4 +++- > 3 files changed, 27 insertions(+), 2 deletions(-) > > diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c > index c641ab046e98..ac095a95f3d0 100644 > --- a/fs/ceph/mds_client.c > +++ b/fs/ceph/mds_client.c > @@ -2923,6 +2923,7 @@ static struct ceph_msg *create_request_message(stru= ct ceph_mds_session *session, > { > int mds =3D session->s_mds; > struct ceph_mds_client *mdsc =3D session->s_mdsc; > + struct ceph_client *cl =3D mdsc->fsc->client; > struct ceph_msg *msg; > struct ceph_mds_request_head_legacy *lhead; > const char *path1 =3D NULL; > @@ -3028,6 +3029,16 @@ static struct ceph_msg *create_request_message(str= uct ceph_mds_session *session, > lhead =3D find_legacy_request_head(msg->front.iov_base, > session->s_con.peer_features); > > + if ((req->r_mnt_idmap !=3D &nop_mnt_idmap) && > + !test_bit(CEPHFS_FEATURE_HAS_OWNER_UIDGID, &session->s_featur= es)) { > + pr_err_ratelimited_client(cl, > + "idmapped mount is used and CEPHFS_FEATURE_HAS_OW= NER_UIDGID" > + " is not supported by MDS. Fail request with -EIO= .\n"); > + > + ret =3D -EIO; > + goto out_err; > + } > + > /* > * The ceph_mds_request_head_legacy didn't contain a version fiel= d, and > * one was added when we moved the message version from 3->4. > @@ -3043,10 +3054,19 @@ static struct ceph_msg *create_request_message(st= ruct ceph_mds_session *session, > p =3D msg->front.iov_base + sizeof(*ohead); > } else { > struct ceph_mds_request_head *nhead =3D msg->front.iov_ba= se; > + kuid_t owner_fsuid; > + kgid_t owner_fsgid; > > msg->hdr.version =3D cpu_to_le16(6); > nhead->version =3D cpu_to_le16(CEPH_MDS_REQUEST_HEAD_VERS= ION); > p =3D msg->front.iov_base + sizeof(*nhead); > + > + owner_fsuid =3D from_vfsuid(req->r_mnt_idmap, &init_user_= ns, > + VFSUIDT_INIT(req->r_cred->fsuid= )); > + owner_fsgid =3D from_vfsgid(req->r_mnt_idmap, &init_user_= ns, > + VFSGIDT_INIT(req->r_cred->fsgid= )); > + nhead->owner_uid =3D cpu_to_le32(from_kuid(&init_user_ns,= owner_fsuid)); > + nhead->owner_gid =3D cpu_to_le32(from_kgid(&init_user_ns,= owner_fsgid)); > } > > end =3D msg->front.iov_base + msg->front.iov_len; > 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 =3D CEPHFS_FEATURE_32BITS_RETRY_FWD, > + CEPHFS_FEATURE_MAX =3D 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..6eb83a51341c 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,8 @@ struct ceph_mds_request_head { > > __le32 ext_num_retry; /* new count retry attempts */ > __le32 ext_num_fwd; /* new count fwd attempts */ > + > + __le32 owner_uid, owner_gid; /* used for OPs which create inode= s */ > } __attribute__ ((packed)); > > /* cap/lease release record */ > -- > 2.34.1 >