Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2101645pxb; Fri, 25 Mar 2022 11:06:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpObEgV2ZmbGKaccHQewPpysJKlIy8kMfhGsvfps9p+dMbIFG3aMtsyJDn4r+wwJweYTtH X-Received: by 2002:a17:90a:1a:b0:1c6:c1ee:c3fb with SMTP id 26-20020a17090a001a00b001c6c1eec3fbmr26543837pja.50.1648231601088; Fri, 25 Mar 2022 11:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648231601; cv=none; d=google.com; s=arc-20160816; b=V3JH7j7bsD6xVYUMp1fUJG3CpiK8/bIC7ZWSKJ2BUPYlzU4YSKlkCuY2Ce5PhYzfDO R3UBgWVWb+2rqhIIIsZ2/UdnQ+80t2vT2AraBrGrTw2V29rfeHQm1iZM7gNFlZNGDNEx 4kCd25NpglQm96zSqLR9Lnoxr9DDhMi90hJUp7XiY5+tvQ7S/bTNeDRjnC02xrSWnkUV ImtiuoHUMMxuuqt9MgBDV0Jcj66aLRuW1yb8dueRMwFFQYdkvfD5I4/ibf4IVwKgtjDV 6UXNHLRBhsTIYbBeYdrKsed7W6FALjiUYEln7TnCA1VCuiah9AjPU2nxWDugwJj+lrhV 6sJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=e40raet6Mp+9NU0NnhM0RrW3g7g20UNRoWpII1q7/mY=; b=RM1iQFH41WB5KmbRNR/dJx7UY408u1xNhvCKHq+8YJ82CHIPDp6bAFQ5UbJgJAxOP0 iXoZSLACE+jfi9XiuywKMhLxCt9XhVj2ev/+Q6KXxZmDuOJ0rhBapf4Q/RWsOA5khKYt C+MNZqPgUDgyTD70yZvQ4/+4Kz8SvgWCmmH3Zat9eaK0JKsmxcPo+eRjOYbn2LocDW5X 5d3mQvnpxx6su+L6GGTWGXxOER3vms/2gKJmpln8mudjoRz8mItpsXZiZW7dUHfWMTo0 rDYAXdFr5R0rpiwAzaVDPzxK/r6D4VNldVuFffVnMu4jr1gpkwiuuVzpSf1rLQAoWClS CF9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ofyi97hb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x26-20020a656aba000000b003816043f0d0si3233461pgu.709.2022.03.25.11.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:06:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ofyi97hb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2CC413CA1E; Fri, 25 Mar 2022 10:40:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239368AbiCWQ5b (ORCPT + 99 others); Wed, 23 Mar 2022 12:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236920AbiCWQ53 (ORCPT ); Wed, 23 Mar 2022 12:57:29 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F5A46E4E1; Wed, 23 Mar 2022 09:55:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id DAA26CE1F8E; Wed, 23 Mar 2022 16:55:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F3FC340F2; Wed, 23 Mar 2022 16:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648054554; bh=81nfjiQFeTPRAGOqW0aoil91fkoUvymS7z9RcUla0K0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ofyi97hboKxpE/pTa+ftOp/+oZCRyHADhyI8FcijbBV3/CvCk42BCVN059vz4KwUa gE1wn43OEVpNIw242WOqUiRZn9ABQiK1kbuqyqmLBAR24Eo3kzWEEB2gkvr1NaM86f 4Qz8Vep6KzvW5c7Ll1nh994LjHqnNvGoD2Rx9ZG49BRt/rUViVf5R2eP1/7xA/TLEF jWDOXFUxVpSqjxwG18ZOpYjc/EhVMW64CSS0phvAxOuqmnFnJXamy8hvud33+ZR1hO pviv9ZN4azZ84nG9xsOKfZd0NfDcJ4Jq1YkaN5+4gJDv4Lf0TarZ6rR22T8YRRh195 IIfAg8Us2S/gg== Message-ID: <9a3dab30b8657351ab6a73de533b7e3f2a41f72a.camel@kernel.org> Subject: Re: [RFC PATCH v11 08/51] ceph: add support for fscrypt_auth/fscrypt_file to cap messages From: Jeff Layton To: idryomov@gmail.com, xiubli@redhat.com Cc: ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, lhenriques@suse.de Date: Wed, 23 Mar 2022 12:55:52 -0400 In-Reply-To: <20220322141316.41325-9-jlayton@kernel.org> References: <20220322141316.41325-1-jlayton@kernel.org> <20220322141316.41325-9-jlayton@kernel.org> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 Tue, 2022-03-22 at 10:12 -0400, Jeff Layton wrote: > Add support for new version 12 cap messages that carry the new > fscrypt_auth and fscrypt_file fields from the inode. > > Signed-off-by: Jeff Layton > --- > fs/ceph/caps.c | 76 +++++++++++++++++++++++++++++++++++++++++--------- > 1 file changed, 63 insertions(+), 13 deletions(-) > > diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c > index 7d8ef67a1032..b0b7688331b4 100644 > --- a/fs/ceph/caps.c > +++ b/fs/ceph/caps.c > @@ -13,6 +13,7 @@ > #include "super.h" > #include "mds_client.h" > #include "cache.h" > +#include "crypto.h" > #include > #include > > @@ -1214,15 +1215,12 @@ struct cap_msg_args { > umode_t mode; > bool inline_data; > bool wake; > + u32 fscrypt_auth_len; > + u32 fscrypt_file_len; > + u8 fscrypt_auth[sizeof(struct ceph_fscrypt_auth)]; // for context > + u8 fscrypt_file[sizeof(u64)]; // for size > }; > > -/* > - * cap struct size + flock buffer size + inline version + inline data size + > - * osd_epoch_barrier + oldest_flush_tid > - */ > -#define CAP_MSG_SIZE (sizeof(struct ceph_mds_caps) + \ > - 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4) > - > /* Marshal up the cap msg to the MDS */ > static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg) > { > @@ -1238,7 +1236,7 @@ static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg) > arg->size, arg->max_size, arg->xattr_version, > arg->xattr_buf ? (int)arg->xattr_buf->vec.iov_len : 0); > > - msg->hdr.version = cpu_to_le16(10); > + msg->hdr.version = cpu_to_le16(12); > msg->hdr.tid = cpu_to_le64(arg->flush_tid); > > fc = msg->front.iov_base; > @@ -1309,6 +1307,21 @@ static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg) > > /* Advisory flags (version 10) */ > ceph_encode_32(&p, arg->flags); > + > + /* dirstats (version 11) - these are r/o on the client */ > + ceph_encode_64(&p, 0); > + ceph_encode_64(&p, 0); > + > +#if IS_ENABLED(CONFIG_FS_ENCRYPTION) > + /* fscrypt_auth and fscrypt_file (version 12) */ > + ceph_encode_32(&p, arg->fscrypt_auth_len); > + ceph_encode_copy(&p, arg->fscrypt_auth, arg->fscrypt_auth_len); > + ceph_encode_32(&p, arg->fscrypt_file_len); > + ceph_encode_copy(&p, arg->fscrypt_file, arg->fscrypt_file_len); > +#else /* CONFIG_FS_ENCRYPTION */ > + ceph_encode_32(&p, 0); > + ceph_encode_32(&p, 0); > +#endif /* CONFIG_FS_ENCRYPTION */ > } > > /* > @@ -1430,8 +1443,37 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap, > } > } > arg->flags = flags; > +#if IS_ENABLED(CONFIG_FS_ENCRYPTION) > + if (ci->fscrypt_auth_len && > + WARN_ON_ONCE(ci->fscrypt_auth_len != sizeof(struct ceph_fscrypt_auth))) { The above WARN_ON_ONCE is too strict, and causes the client to reject v1 fscrypt contexts (as well as throw the warning). That should be a ">" instead. I've fixed this in my tree and pushed the fix into wip-fscrypt. > + /* Don't set this if it isn't right size */ > + arg->fscrypt_auth_len = 0; > + } else { > + arg->fscrypt_auth_len = ci->fscrypt_auth_len; > + memcpy(arg->fscrypt_auth, ci->fscrypt_auth, > + min_t(size_t, ci->fscrypt_auth_len, sizeof(arg->fscrypt_auth))); > + } > + /* FIXME: use this to track "real" size */ > + arg->fscrypt_file_len = 0; > +#endif /* CONFIG_FS_ENCRYPTION */ > } > > +#define CAP_MSG_FIXED_FIELDS (sizeof(struct ceph_mds_caps) + \ > + 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4) > + > +#if IS_ENABLED(CONFIG_FS_ENCRYPTION) > +static inline int cap_msg_size(struct cap_msg_args *arg) > +{ > + return CAP_MSG_FIXED_FIELDS + arg->fscrypt_auth_len + > + arg->fscrypt_file_len; > +} > +#else > +static inline int cap_msg_size(struct cap_msg_args *arg) > +{ > + return CAP_MSG_FIXED_FIELDS; > +} > +#endif /* CONFIG_FS_ENCRYPTION */ > + > /* > * Send a cap msg on the given inode. > * > @@ -1442,7 +1484,7 @@ static void __send_cap(struct cap_msg_args *arg, struct ceph_inode_info *ci) > struct ceph_msg *msg; > struct inode *inode = &ci->vfs_inode; > > - msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, CAP_MSG_SIZE, GFP_NOFS, false); > + msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, cap_msg_size(arg), GFP_NOFS, false); > if (!msg) { > pr_err("error allocating cap msg: ino (%llx.%llx) flushing %s tid %llu, requeuing cap.\n", > ceph_vinop(inode), ceph_cap_string(arg->dirty), > @@ -1468,10 +1510,6 @@ static inline int __send_flush_snap(struct inode *inode, > struct cap_msg_args arg; > struct ceph_msg *msg; > > - msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, CAP_MSG_SIZE, GFP_NOFS, false); > - if (!msg) > - return -ENOMEM; > - > arg.session = session; > arg.ino = ceph_vino(inode).ino; > arg.cid = 0; > @@ -1509,6 +1547,18 @@ static inline int __send_flush_snap(struct inode *inode, > arg.flags = 0; > arg.wake = false; > > + /* > + * No fscrypt_auth changes from a capsnap. It will need > + * to update fscrypt_file on size changes (TODO). > + */ > + arg.fscrypt_auth_len = 0; > + arg.fscrypt_file_len = 0; > + > + msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, cap_msg_size(&arg), > + GFP_NOFS, false); > + if (!msg) > + return -ENOMEM; > + > encode_cap_msg(msg, &arg); > ceph_con_send(&arg.session->s_con, msg); > return 0; -- Jeff Layton