Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp451617pxb; Mon, 16 Aug 2021 09:05:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8Tc3vHHfzhWnAsNSjpkKXRgWQYaf+1XJVHiFsfSjJoggWfPT+rI5PEupm2ndkDQ1ljXFD X-Received: by 2002:a17:906:5909:: with SMTP id h9mr16537232ejq.329.1629129935942; Mon, 16 Aug 2021 09:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629129935; cv=none; d=google.com; s=arc-20160816; b=h9WDSmtca3qX0bZJTcfve8Mey/0SfBhkU0VvsOklgxnLOiEw4Fu0FH1CVZ2q4w55l7 B6CPdUniN2xzv9QiJB5gTQBuqkS5vGecZmTZfEvBcX62AlCtyyzywmX4NFfPiPMz3D1X EOlL/9yOzvNl6bUB9TOLD6W2dx0P2uZeb+tvV3f1uK03ylE/nFEgVOyB63GJMQracso5 mo2kPYl6wW2VhU1RgMJm0Wwp9XlqykJUCpadqrZ/gQbEyxx/zIyPMc71tw6/KMVSkP7j kNxErXBUS81mOMHfp/GgvXKJOuXf4oi3x9YGAXC2la86CRrPDolPBi4JtGkJDAsMys0A BvBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from:dkim-signature:dkim-signature; bh=Xnbr3kLFAwo6VGy0q66BBpHfF5zxjt9NJjmOzi584V0=; b=DpYMMt229Ct2cNAIrdGrzGtqpwv0Z4BtKoyonWatKY4HLRe17yx17AmzJaz2eQiu+O JSjITjVHNyooFwgLxUwMXeCViCBdUioy2U52RW6VYferhxGlUm7P0wcll+bdYmkUJXkz LVVb+rAx79OquKoiYvpodw56NpXaealWeGASiaUBcOmW7Nfn9iEXTeppgMcGoUKForgM b4YEu3++FY/oK2GOJKTncruQnMKpQMjTvdYIsYMO4KCKn1edZ7+q0yJSy7hYkduxlBZy slWVNUvcJ885f+wi1KwuuWaAROJkyQx/8UnRyaWEGxCQUiujq4wqkuUB1DQsr2w+zRv5 Jkvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=SrPVkVqQ; dkim=neutral (no key) header.i=@suse.de header.b=W9IUy+Mv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si11870348ejx.341.2021.08.16.09.05.11; Mon, 16 Aug 2021 09:05:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=SrPVkVqQ; dkim=neutral (no key) header.i=@suse.de header.b=W9IUy+Mv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbhHPQD4 (ORCPT + 99 others); Mon, 16 Aug 2021 12:03:56 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:43688 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbhHPQDz (ORCPT ); Mon, 16 Aug 2021 12:03:55 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5C7031FF94; Mon, 16 Aug 2021 16:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629129803; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Xnbr3kLFAwo6VGy0q66BBpHfF5zxjt9NJjmOzi584V0=; b=SrPVkVqQ78CqhcgZALIPRkUwJpBGaiE6dxtVxR22S6C4KF6n5bvliH6pqZfO0WAVwqiKbO OoGY6eOvUa4EdSr1KKv/Dvm4Ry57tTEwvfuYie3lS6N3RQEx8fuALK613ywghrQXckESlS nVd2w66is1f9gpe8qGqQ7Te+3aXPynY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629129803; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Xnbr3kLFAwo6VGy0q66BBpHfF5zxjt9NJjmOzi584V0=; b=W9IUy+MvZcCguQcIfJRYWunpGZIt0/SNPLHGTlUAwAIbDnqBfX3CRZeHBJvdmnoeT/QTBY ZACH7iz51YSqSsAw== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 16F7513301; Mon, 16 Aug 2021 16:03:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id B3eLAkuMGmFNXQAAGKfGzw (envelope-from ); Mon, 16 Aug 2021 16:03:23 +0000 Received: from localhost (brahms [local]) by brahms (OpenSMTPD) with ESMTPA id 7a432a69; Mon, 16 Aug 2021 16:03:22 +0000 (UTC) From: Luis Henriques To: Jeff Layton Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [fscrypt][RFC PATCH] ceph: don't allow changing layout on encrypted files/directories References: <87pmudtsho.fsf@suse.de> <1b55600eb096ac806ccd43c93aa0230a8cc46283.camel@kernel.org> Date: Mon, 16 Aug 2021 17:03:22 +0100 In-Reply-To: <1b55600eb096ac806ccd43c93aa0230a8cc46283.camel@kernel.org> (Jeff Layton's message of "Mon, 16 Aug 2021 10:01:26 -0400") Message-ID: <87lf51tm0l.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jeff Layton writes: > On Mon, 2021-08-16 at 14:43 +0100, Luis Henriques wrote: >> Jeff Layton writes: >> >> > On Fri, 2021-08-13 at 14:03 +0100, Luis Henriques wrote: >> > > Encryption is currently only supported on files/directories with layouts >> > > where stripe_count=1. Forbid changing layouts when encryption is involved. >> > > >> > > Signed-off-by: Luis Henriques >> > > --- >> > > Hi! >> > > >> > > While continuing looking into fscrypt, I realized we're not yet forbidding >> > > different layouts on encrypted files. This patch tries to do just that. >> > > >> > > Regarding the setxattr, I've also made a change [1] to the MDS code so that it >> > > also prevents layouts to be changed. This should make the changes to >> > > ceph_sync_setxattr() redundant, but in practice it doesn't because if we encrypt >> > > a directory and immediately after that we change that directory layout, the MDS >> > > wouldn't yet have received the fscrypt_auth for that inode. So... yeah, an >> > > alternative would be to propagate the fscrypt context immediately after >> > > encrypting a directory. >> > > >> > > [1] https://github.com/luis-henrix/ceph/commit/601488ae798ecfa5ec81677d1ced02f7dd42aa10 >> > > >> > > Cheers, >> > > -- >> > > Luis >> > > >> > > fs/ceph/ioctl.c | 4 ++++ >> > > fs/ceph/xattr.c | 6 ++++++ >> > > 2 files changed, 10 insertions(+) >> > > >> > > diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c >> > > index 477ecc667aee..42abfc564301 100644 >> > > --- a/fs/ceph/ioctl.c >> > > +++ b/fs/ceph/ioctl.c >> > > @@ -294,6 +294,10 @@ static long ceph_set_encryption_policy(struct file *file, unsigned long arg) >> > > struct inode *inode = file_inode(file); >> > > struct ceph_inode_info *ci = ceph_inode(inode); >> > > >> > > + /* encrypted directories can't have striped layout */ >> > > + if (ci->i_layout.stripe_count > 1) >> > > + return -EOPNOTSUPP; >> > > + >> > >> > Yes, I've been needing to add that for a while. I'm not sure EOPNOTSUPP >> > is the right error code though. Maybe EINVAL instead? >> > >> >> Right, I had that initially and changed it after a long indecision. But >> yeah, I've no strong opinion either way. >> > > It's a judgement call, really... > >> > >> > > ret = vet_mds_for_fscrypt(file); >> > > if (ret) >> > > return ret; >> > > diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c >> > > index b175b3029dc0..7921cb34900c 100644 >> > > --- a/fs/ceph/xattr.c >> > > +++ b/fs/ceph/xattr.c >> > > @@ -1051,6 +1051,12 @@ static int ceph_sync_setxattr(struct inode *inode, const char *name, >> > > int op = CEPH_MDS_OP_SETXATTR; >> > > int err; >> > > >> > > + /* encrypted directories/files can't have their layout changed */ >> > > + if (IS_ENCRYPTED(inode) && >> > > + (!strncmp(name, "ceph.file.layout", 16) || >> > > + !strncmp(name, "ceph.dir.layout", 15))) >> > > + return -EOPNOTSUPP; >> > > + >> > >> > Yuck. >> >> Agreed! >> >> > What might be nicer is to just make ceph_vxattrcb_layout* return an >> > error when the inode is encrypted? You can return negative error codes >> > from the ->getxattr_cb ops, and that's probably the better place to >> > check for this. >> >> I'm not sure I understand your suggestion. This is on the SETXATTR path, >> so we'll need to block attempts to send this operation to the MDS. >> > > Doh! You're correct -- I was thinking about getxattr, but setxattr > doesn't have the same ops vectors. We could add a new option to vet > setxattr requests locally, but that might not be sufficient actually... > >> An alternative would be to do this (return an error) on the MDS side, but >> this would mean that we should also send the fscrypt fields to the MDS >> because it may may not know yet that the inode is encrypted. Which could >> be the correct thing to do BTW. Although I don't think client B could >> concurrently change the layout of a directory that client A just set as >> encrypted without client A sending that information to the MDS first... >> > > Now that I think about it some more, we probably need to let the MDS vet > these requests. Sure, and that's what I tried to do with the MDS patch in [1]. I'm not confident that's safe enough, although I _think_ the case you describe: client A client B mkdir XYZ lookup inode XYZ setxattr (set layout) encrypt XYZ should be protected with the right caps + MDS locks. But I'll go look closer because I *know* I am still missing something. [1] https://github.com/luis-henrix/ceph/commit/601488ae798ecfa5ec81677d1ced02f7dd42aa10 Cheers, -- Luis > It's possible that we'd do a lookup of the inode and > then call setxattr on it concurrently with another client making the > inode encrypted. > > We could ensure that we have As caps here to try to prevent that, but it > hardly seems worthwhile. These are not commonly changed. It seems best > to just let the MDS gather the appropriate locks and handle it there. > > -- > Jeff Layton >