Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1608884pxm; Thu, 24 Feb 2022 06:23:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFds6IamN45b6sfEQ9W/jGebLjzJv4Ygf/7f5hbvNqqJj3slX9vP92Wr7JTK1hrKLOBtJs X-Received: by 2002:a17:90b:1b0f:b0:1b9:f5ac:ae53 with SMTP id nu15-20020a17090b1b0f00b001b9f5acae53mr3013818pjb.71.1645712622681; Thu, 24 Feb 2022 06:23:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645712622; cv=none; d=google.com; s=arc-20160816; b=dTvt1Jd44mY0BJXhHLHj1jP6EYAZk7MGAiyTzQ7AgDLpuoEUQiMDRAewa7QqYAnhho +oxMu44QCI4NrgmR13yLil5R8tM14aa20I8BFUrgmo8ZWuLek7szyVhk1Gq0IMz5D03L mLEC+LedcylyPl5/E5WI8YvDBw2r6csUn1qO57GsRKI37F2BS+eWWCh+9frpqBroJeaQ RT32SO9PdDsVgE/Q77WggpPAwfkko+93/hJk75gwzevrzVCrhBXfPWokljpHQG93WYk0 amOreGRBvkxlMo14a6SLqWJ33dm9h44psoolUxJySDz77HDAShwQGNvRiI33WKdUNezi I5Lg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=oJU8mNCuvdPjtG+kxUCL1MNwiSJQCMqrnSDUyRWAPys=; b=zE9YHJ1PveWVnfiNXN5CvT7tobzHmorLsgqfer8mQay/iVF/RUBeyJs+j+1xrKk093 FYmC02g/8R6C7ZjNhruqDKZ4IYFa7CNFcTF0tTCKh7BinOaoTnksY7l/Cbs7SK06Q0Bu VJlx61eG/Aa+xjzg7+XtG28lwzOigBhJsojXxdUp7Erpp5qwgAR7jkzRHOPlVff72r5M U+CyY2e0uzf2tpYDN56bh2B76Dbx04O51gPrsks4Vdf/ATC9dA68mIn6Une0O/aIqAdA fWIwCmPRqEA3q/v5wdnksf7t3iPDJxhy7BhUgkg7dx3IiiOJpdzaDB3+cBZSiaTs8eiO cmMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fbrLd3uY; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e19si2372840pfv.288.2022.02.24.06.23.22; Thu, 24 Feb 2022 06:23:42 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=fbrLd3uY; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233943AbiBXLWF (ORCPT + 99 others); Thu, 24 Feb 2022 06:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbiBXLWE (ORCPT ); Thu, 24 Feb 2022 06:22:04 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4259B1CE; Thu, 24 Feb 2022 03:21:31 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 F23651F37F; Thu, 24 Feb 2022 11:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1645701690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oJU8mNCuvdPjtG+kxUCL1MNwiSJQCMqrnSDUyRWAPys=; b=fbrLd3uYGGuF/+gtgOTc42jy43SBVwMaRLN9Jyjq5Q7kJTFS2NCF/eGWTFihYz3ZuVAO/W 2Xu155AIWIa5aQE2Yn3kqLHhqurbQ+J8vibQwWSMCIjzpjO7ODhCKl7S5JRnMnSDIvcz3I KEd7y3uTKgMSv9d0SiU2rdws2TYqFRI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1645701690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oJU8mNCuvdPjtG+kxUCL1MNwiSJQCMqrnSDUyRWAPys=; b=pimrS9guo0/mLaKBn4sTcUW5Kr+erSaQ5pN956+PIe12zIFsX+NuJKBHZAHm8mzWD0gQgZ YGrZG6YXWfuNI4BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 82DF6139F3; Thu, 24 Feb 2022 11:21:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IsL4HDlqF2IHWAAAMHmgww (envelope-from ); Thu, 24 Feb 2022 11:21:29 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id b5956cca; Thu, 24 Feb 2022 11:21:43 +0000 (UTC) From: =?UTF-8?q?Lu=C3=ADs=20Henriques?= To: Jeff Layton , Xiubo Li , Ilya Dryomov Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Lu=C3=ADs=20Henriques?= Subject: [RFC PATCH] ceph: add support for encrypted snapshot names Date: Thu, 24 Feb 2022 11:21:42 +0000 Message-Id: <20220224112142.18052-1-lhenriques@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,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=ham 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 Since filenames in encrypted directories are already encrypted and shown as a base64-encoded string when the directory is locked, snapshot names should show a similar behaviour. Signed-off-by: Luís Henriques --- fs/ceph/dir.c | 15 +++++++++++++++ fs/ceph/inode.c | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) Support on the MDS for names that'll be > MAX_NAME when base64 encoded is still TBD. I thought it would be something easy to do, but snapshots don't seem to make use of the CDir/CDentry (which is where alternate_name is stored on the MDS). I'm still looking into this, but I may need some help there :-( Cheers, -- Luís diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index a449f4a07c07..20ae600ee7cd 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -1065,6 +1065,13 @@ static int ceph_mkdir(struct user_namespace *mnt_userns, struct inode *dir, op = CEPH_MDS_OP_MKSNAP; dout("mksnap dir %p snap '%pd' dn %p\n", dir, dentry, dentry); + /* XXX missing support for alternate_name in snapshots */ + if (IS_ENCRYPTED(dir) && (dentry->d_name.len >= 189)) { + dout("encrypted snapshot name too long: %pd len: %d\n", + dentry, dentry->d_name.len); + err = -ENAMETOOLONG; + goto out; + } } else if (ceph_snap(dir) == CEPH_NOSNAP) { dout("mkdir dir %p dn %p mode 0%ho\n", dir, dentry, mode); op = CEPH_MDS_OP_MKDIR; @@ -1109,6 +1116,14 @@ static int ceph_mkdir(struct user_namespace *mnt_userns, struct inode *dir, !req->r_reply_info.head->is_target && !req->r_reply_info.head->is_dentry) err = ceph_handle_notrace_create(dir, dentry); + + /* + * If we have created a snapshot we need to clear the cache, otherwise + * snapshot will show encrypted filenames in readdir. + */ + if (ceph_snap(dir) == CEPH_SNAPDIR) + d_drop(dentry); + out_req: ceph_mdsc_put_request(req); out: diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 8b0832271fdf..080824610b73 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -182,6 +182,13 @@ struct inode *ceph_get_snapdir(struct inode *parent) ci->i_rbytes = 0; ci->i_btime = ceph_inode(parent)->i_btime; + /* if encrypted, just borough fscrypt_auth from parent */ + if (IS_ENCRYPTED(parent)) { + struct ceph_inode_info *pci = ceph_inode(parent); + inode->i_flags |= S_ENCRYPTED; + ci->fscrypt_auth_len = pci->fscrypt_auth_len; + ci->fscrypt_auth = pci->fscrypt_auth; + } if (inode->i_state & I_NEW) { inode->i_op = &ceph_snapdir_iops; inode->i_fop = &ceph_snapdir_fops; @@ -632,7 +639,8 @@ void ceph_free_inode(struct inode *inode) kfree(ci->i_symlink); #ifdef CONFIG_FS_ENCRYPTION - kfree(ci->fscrypt_auth); + if (ceph_snap(inode) != CEPH_SNAPDIR) + kfree(ci->fscrypt_auth); #endif fscrypt_free_inode(inode); kmem_cache_free(ceph_inode_cachep, ci);