From patchwork Thu Nov 3 14:06:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 14905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp554306wru; Thu, 3 Nov 2022 07:07:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44alAuiMh5r2fjVrskVh6YB2klx7d0eptjvkpTdocq8GGV1LnPRQr7uJK/zWytgUN7NRTo X-Received: by 2002:a63:83c6:0:b0:46e:f5ee:e27c with SMTP id h189-20020a6383c6000000b0046ef5eee27cmr25623450pge.603.1667484442738; Thu, 03 Nov 2022 07:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667484442; cv=none; d=google.com; s=arc-20160816; b=mzbzIf4w4Vs6MT6vBgiLK3gFEdlrtf+mrpPNMa+YwO4sUL9TflSRe/5Y3/bAoLmApK U+8ALUKAaRtX1LOLOiZGsg3y9zIIQqfuCMOhzhDmJp+x24hfQVPCVNUQ4ooaxjhoaPyn bcJbqax1jx6wN9c8N2M38OkpO8IgvS6wgF7Jt5/DJ5kJYEF4IHIb+5TdH/vjBAwyL7Vj 20ZDU4Ry8FxC4+G1fsVWoC4hVdsmkVRSZFuYfon2l+0QbCg+LiVZ/ozzgMzctyuW6SIu DExTmSbW/A9HnDKZevFvEebmXvNMG5uwzPExAP4j42KsCuhxdQucBH5Rq6yDcJYRnfFD JqGg== 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=Fxpd7kxoSr8KWDfsjl//BZAba+zNFtzbzoF5WTUFBKE=; b=0mPMdWirF8v12HowB8iDMMQCQBymgpvehlyBsc159C2TTUqlkhFXwxmJVAeHzvrZGT jpS2IkES/OSOP0Uuw0m44JMtm+hIV5nKJmPwjONUFrlmd/UiTac6fSwnseUWqnljxNof amVVKeGzUTTB5iEwSRngBUfn2xs1VKbQ6NjcdKIxHjzke9V7pE+AKFCitrJ6N9cUGfdW blaGQO61KhXlK3kZLOAcAL4Qj06g77fDnIjq5GrX8A9YtSRWtOgG5h+Sn7kpBly06mSM V/bW/pMYghhY0MRTXFPv7ET+RPa0fqQghW/LXLcL7vb1Tn5uDTxWPah2Cw52DA4MwLga fjXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0FgPSi+D; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=pL9+WARW; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i70-20020a638749000000b004701d0bbabcsi1024829pge.798.2022.11.03.07.07.08; Thu, 03 Nov 2022 07:07:22 -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=@suse.de header.s=susede2_rsa header.b=0FgPSi+D; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=pL9+WARW; 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 S230510AbiKCOFx (ORCPT + 99 others); Thu, 3 Nov 2022 10:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbiKCOFt (ORCPT ); Thu, 3 Nov 2022 10:05:49 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FCC212618; Thu, 3 Nov 2022 07:05:45 -0700 (PDT) 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 B344B1F45F; Thu, 3 Nov 2022 14:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667484344; 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=Fxpd7kxoSr8KWDfsjl//BZAba+zNFtzbzoF5WTUFBKE=; b=0FgPSi+DP3oQ7CgQ3OCCIhjphmWDt45Uyt4wN3v4IxYg7Jsfl8F2gbmjicvqTo+dqOQ7KK 1SGZeRB7+mWMDqgPJhMOh+v+j+0YsAu5PLDpQtahdQnMiHsPW+3uqy3kIvNOkAa1ZIhQaE kOUeprt4dUxR73R4iydOyefBkx7HUFk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667484344; 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=Fxpd7kxoSr8KWDfsjl//BZAba+zNFtzbzoF5WTUFBKE=; b=pL9+WARWuc7ceYqPLP5dHowmR3egROw1IXDBjtk2pniDt67T/ETqVA30cs6qE6faPw+9I5 5CTKHohVXmH92wCw== 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 5361713480; Thu, 3 Nov 2022 14:05:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 9B2UEbjKY2OIcQAAMHmgww (envelope-from ); Thu, 03 Nov 2022 14:05:44 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 2b58f16e; Thu, 3 Nov 2022 14:06:42 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: Xiubo Li , Ilya Dryomov , Jeff Layton Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= Subject: [RFC PATCH v2] ceph: allow encrypting a directory while not having Ax caps Date: Thu, 3 Nov 2022 14:06:40 +0000 Message-Id: <20221103140640.30850-1-lhenriques@suse.de> MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748484167092815276?= X-GMAIL-MSGID: =?utf-8?q?1748484167092815276?= If a client doesn't have Fx caps on a directory, it will get errors while trying encrypt it: ceph: handle_cap_grant: cap grant attempt to change fscrypt_auth on non-I_NEW inode (old len 0 new len 48) fscrypt (ceph, inode 1099511627812): Error -105 getting encryption context A simple way to reproduce this is to use two clients: client1 # mkdir /mnt/mydir client2 # ls /mnt/mydir client1 # fscrypt encrypt /mnt/mydir client1 # echo hello > /mnt/mydir/world This happens because, in __ceph_setattr(), we only initialize ci->fscrypt_auth if we have Ax and ceph_fill_inode() won't use the fscrypt_auth received if the inode state isn't I_NEW. Fix it by allowing ceph_fill_inode() to also set ci->fscrypt_auth if the inode doesn't have it set already. Signed-off-by: Luís Henriques --- fs/ceph/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index fb507d57cb26..c7831f801911 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1016,7 +1016,8 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page, __ceph_update_quota(ci, iinfo->max_bytes, iinfo->max_files); #ifdef CONFIG_FS_ENCRYPTION - if (iinfo->fscrypt_auth_len && (inode->i_state & I_NEW)) { + if (iinfo->fscrypt_auth_len && + ((inode->i_state & I_NEW) || (ci->fscrypt_auth_len == 0))) { kfree(ci->fscrypt_auth); ci->fscrypt_auth_len = iinfo->fscrypt_auth_len; ci->fscrypt_auth = iinfo->fscrypt_auth;