From patchwork Wed Dec 13 23:40:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492109 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DTcCefQy"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0keUagkY"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DTcCefQy"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0keUagkY" Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0938B1FC8; Wed, 13 Dec 2023 15:40:44 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1ED091F78D; Wed, 13 Dec 2023 23:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9VmviNzu9Vwca8703AouDgcma1pNK0L4pW+RXROQG0=; b=DTcCefQyx55pwmL2mGR0MioA8apjC56cyXfk2vmBVnRWw8plloJ0H4aRv8Zg7A1QvuGiLg E0Fn5HfJ+IryBDFwP0A9mNQ9lhHGYUS8fMTMYKi+B4dihu2p5WGw3i7zhs7mJnUDOzAzvs 5jZ2h+QV2B/BPn9bN4XYiaFv7DxDIso= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9VmviNzu9Vwca8703AouDgcma1pNK0L4pW+RXROQG0=; b=0keUagkY9BeVDBral8DE309qVmkAahULA87OHFvpChAXnthK972UkaI1+BHl+zBK7/+UC0 fVmasfbAKqkKkFAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9VmviNzu9Vwca8703AouDgcma1pNK0L4pW+RXROQG0=; b=DTcCefQyx55pwmL2mGR0MioA8apjC56cyXfk2vmBVnRWw8plloJ0H4aRv8Zg7A1QvuGiLg E0Fn5HfJ+IryBDFwP0A9mNQ9lhHGYUS8fMTMYKi+B4dihu2p5WGw3i7zhs7mJnUDOzAzvs 5jZ2h+QV2B/BPn9bN4XYiaFv7DxDIso= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510841; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9VmviNzu9Vwca8703AouDgcma1pNK0L4pW+RXROQG0=; b=0keUagkY9BeVDBral8DE309qVmkAahULA87OHFvpChAXnthK972UkaI1+BHl+zBK7/+UC0 fVmasfbAKqkKkFAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CF3271377F; Wed, 13 Dec 2023 23:40:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iYN9LPhAemVhPgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:40 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 1/8] dcache: Add helper to disable d_revalidate for a specific dentry Date: Wed, 13 Dec 2023 18:40:24 -0500 Message-ID: <20231213234031.1081-2-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -0.30 X-Spam-Flag: NO Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -0.30 X-Spamd-Result: default: False [-0.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.998]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] Case-insensitive wants d_compare/d_hash for every dentry in the filesystem, while fscrypt needs d_revalidate only for DCACHE_NOKEY_NAME. This means we currently can't use sb->s_d_op to set case-insensitive hooks in fscrypt+case-insensitive filesystems without paying the cost to call d_revalidate for every dentry in the filesystem. In preparation to doing exactly that, add a way to disable d_revalidate later. Suggested-by: Al Viro Signed-off-by: Gabriel Krisman Bertazi --- fs/dcache.c | 10 ++++++++++ include/linux/dcache.h | 1 + 2 files changed, 11 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index c82ae731df9a..1f5464cd3bd1 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1911,6 +1911,16 @@ struct dentry *d_alloc_name(struct dentry *parent, const char *name) } EXPORT_SYMBOL(d_alloc_name); +void d_set_always_valid(struct dentry *dentry) +{ + if (!(dentry->d_flags & DCACHE_OP_REVALIDATE)) + return; + + spin_lock(&dentry->d_lock); + dentry->d_flags &= ~DCACHE_OP_REVALIDATE; + spin_unlock(&dentry->d_lock); +} + void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op) { WARN_ON_ONCE(dentry->d_op); diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 3da2f0545d5d..d2ce151b2d8e 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -225,6 +225,7 @@ extern struct dentry * d_instantiate_anon(struct dentry *, struct inode *); extern void __d_drop(struct dentry *dentry); extern void d_drop(struct dentry *dentry); extern void d_delete(struct dentry *); +extern void d_set_always_valid(struct dentry *dentry); extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op); /* allocate/de-allocate */ From patchwork Wed Dec 13 23:40:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492108 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1378B19B3; Wed, 13 Dec 2023 15:40:45 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D089822310; Wed, 13 Dec 2023 23:40:42 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8D7FA1377F; Wed, 13 Dec 2023 23:40:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 44ZFG/pAemVlPgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:42 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 2/8] fscrypt: Drop d_revalidate if key is available Date: Wed, 13 Dec 2023 18:40:25 -0500 Message-ID: <20231213234031.1081-3-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: D089822310 X-Spam-Flag: NO fscrypt dentries are always valid once the key is available. Since the key cannot be removed without evicting the dentry, we don't need to keep retrying to revalidate it. Signed-off-by: Gabriel Krisman Bertazi --- fs/crypto/fname.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index 7b3fc189593a..0457ba2d7d76 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -591,8 +591,15 @@ int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) * reverting to no-key names without evicting the directory's inode * -- which implies eviction of the dentries in the directory. */ - if (!(dentry->d_flags & DCACHE_NOKEY_NAME)) + if (!(dentry->d_flags & DCACHE_NOKEY_NAME)) { + /* + * If fscrypt is the only feature requiring + * revalidation for this dentry, we can just disable it. + */ + if (dentry->d_op->d_revalidate == &fscrypt_d_revalidate) + d_set_always_valid(dentry); return 1; + } /* * No-key name; valid if the directory's key is still unavailable. From patchwork Wed Dec 13 23:40:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492114 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="HuZn8w5O"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="exaASb07"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="HuZn8w5O"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="exaASb07" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28FDF30FE; Wed, 13 Dec 2023 15:41:00 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6615D22311; Wed, 13 Dec 2023 23:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sp7vIsMdgWL9TiTqEXZpY2g0TTohq+YTCZxjglEPwgw=; b=HuZn8w5OOUZo4mUeGyGKLHtyXrPLxXSjWKJxLu+c6ka69Qg2LA8Dgyngez0fjLbzXvGzJ0 nZ8BpdceSmf/cOhdOymHO2IF73WocYTgFHsgKPREuVRleaovHKQ6LxVyG06k3/MJ2tMxg+ LDOjukPdpHbXzPl5z+Xs42yqcz+eIo4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sp7vIsMdgWL9TiTqEXZpY2g0TTohq+YTCZxjglEPwgw=; b=exaASb07Q048vHK7bOAGm7Qzy3s8zM6Z2ELt0jL2mNpuwjK6MOWxJr2lmhPoBPJiW/oE7s bwgaoOCgFHjNShCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sp7vIsMdgWL9TiTqEXZpY2g0TTohq+YTCZxjglEPwgw=; b=HuZn8w5OOUZo4mUeGyGKLHtyXrPLxXSjWKJxLu+c6ka69Qg2LA8Dgyngez0fjLbzXvGzJ0 nZ8BpdceSmf/cOhdOymHO2IF73WocYTgFHsgKPREuVRleaovHKQ6LxVyG06k3/MJ2tMxg+ LDOjukPdpHbXzPl5z+Xs42yqcz+eIo4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sp7vIsMdgWL9TiTqEXZpY2g0TTohq+YTCZxjglEPwgw=; b=exaASb07Q048vHK7bOAGm7Qzy3s8zM6Z2ELt0jL2mNpuwjK6MOWxJr2lmhPoBPJiW/oE7s bwgaoOCgFHjNShCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2D8481377F; Wed, 13 Dec 2023 23:40:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id aKANBfxAemVnPgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:44 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 3/8] libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops Date: Wed, 13 Dec 2023 18:40:26 -0500 Message-ID: <20231213234031.1081-4-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -0.30 X-Spam-Flag: NO Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -0.30 X-Spamd-Result: default: False [-0.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[20.86%] In preparation to get case-insensitive dentry operations from sb->s_d_op again, use the same structure for case-insensitive filesystems with and without fscrypt. This means that on a casefolded filesystem without fscrypt, we end up having to call fscrypt_d_revalidate once per dentry, which does the function call extra cost. We could avoid it by calling d_set_always_valid in generic_set_encrypted_ci_d_ops, but this entire function will go away in the following patches, and it is not worth the extra complexity. Also, since the first fscrypt_d_revalidate will call d_set_always_valid for us, we'll only have only pay the cost once, and not per-lookup. Signed-off-by: Gabriel Krisman Bertazi --- fs/libfs.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index e9440d55073c..52c944173e57 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1768,6 +1768,9 @@ static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) static const struct dentry_operations generic_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, +#if defined(CONFIG_FS_ENCRYPTION) + .d_revalidate = fscrypt_d_revalidate, +#endif }; #endif @@ -1777,14 +1780,6 @@ static const struct dentry_operations generic_encrypted_dentry_ops = { }; #endif -#if defined(CONFIG_FS_ENCRYPTION) && IS_ENABLED(CONFIG_UNICODE) -static const struct dentry_operations generic_encrypted_ci_dentry_ops = { - .d_hash = generic_ci_d_hash, - .d_compare = generic_ci_d_compare, - .d_revalidate = fscrypt_d_revalidate, -}; -#endif - /** * generic_set_encrypted_ci_d_ops - helper for setting d_ops for given dentry * @dentry: dentry to set ops on @@ -1801,38 +1796,21 @@ static const struct dentry_operations generic_encrypted_ci_dentry_ops = { * Encryption works differently in that the only dentry operation it needs is * d_revalidate, which it only needs on dentries that have the no-key name flag. * The no-key flag can't be set "later", so we don't have to worry about that. - * - * Finally, to maximize compatibility with overlayfs (which isn't compatible - * with certain dentry operations) and to avoid taking an unnecessary - * performance hit, we use custom dentry_operations for each possible - * combination rather than always installing all operations. */ void generic_set_encrypted_ci_d_ops(struct dentry *dentry) { -#ifdef CONFIG_FS_ENCRYPTION - bool needs_encrypt_ops = dentry->d_flags & DCACHE_NOKEY_NAME; -#endif #if IS_ENABLED(CONFIG_UNICODE) - bool needs_ci_ops = dentry->d_sb->s_encoding; -#endif -#if defined(CONFIG_FS_ENCRYPTION) && IS_ENABLED(CONFIG_UNICODE) - if (needs_encrypt_ops && needs_ci_ops) { - d_set_d_op(dentry, &generic_encrypted_ci_dentry_ops); + if (dentry->d_sb->s_encoding) { + d_set_d_op(dentry, &generic_ci_dentry_ops); return; } #endif #ifdef CONFIG_FS_ENCRYPTION - if (needs_encrypt_ops) { + if (dentry->d_flags & DCACHE_NOKEY_NAME) { d_set_d_op(dentry, &generic_encrypted_dentry_ops); return; } #endif -#if IS_ENABLED(CONFIG_UNICODE) - if (needs_ci_ops) { - d_set_d_op(dentry, &generic_ci_dentry_ops); - return; - } -#endif } EXPORT_SYMBOL(generic_set_encrypted_ci_d_ops); From patchwork Wed Dec 13 23:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492113 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="aySwLGq5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="dD//Th6/"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="aySwLGq5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="dD//Th6/" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9C673248; Wed, 13 Dec 2023 15:41:00 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 005011FD84; Wed, 13 Dec 2023 23:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510846; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDxGCPqxcv+EGbtznoocxBQDbnIDFuyfDLE0ZhmlKns=; b=aySwLGq5JcjHCtbu1XYMI8xbwV1vIWPidIaoyTRV9EaPfVJp5SGgOOvd5yOvoMq3UsL1hQ ppce/t1WR2Dr58Fv0NCss8aFxiBk8HMb6PRQqY24ugpWQrOM4tPxrMmSKRhvmB2eCqTDlC i3UcMN4r1S2Cx2k4dMazBN34th9yACs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510846; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDxGCPqxcv+EGbtznoocxBQDbnIDFuyfDLE0ZhmlKns=; b=dD//Th6/Zj4msP9PIJkP4il3qWy6su9Qw5vYeqwfSLw9y2yPwYjyV1FxGhFwzGoVNLDgaJ hlRylM2j3tRpr5Bg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510846; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDxGCPqxcv+EGbtznoocxBQDbnIDFuyfDLE0ZhmlKns=; b=aySwLGq5JcjHCtbu1XYMI8xbwV1vIWPidIaoyTRV9EaPfVJp5SGgOOvd5yOvoMq3UsL1hQ ppce/t1WR2Dr58Fv0NCss8aFxiBk8HMb6PRQqY24ugpWQrOM4tPxrMmSKRhvmB2eCqTDlC i3UcMN4r1S2Cx2k4dMazBN34th9yACs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510846; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDxGCPqxcv+EGbtznoocxBQDbnIDFuyfDLE0ZhmlKns=; b=dD//Th6/Zj4msP9PIJkP4il3qWy6su9Qw5vYeqwfSLw9y2yPwYjyV1FxGhFwzGoVNLDgaJ hlRylM2j3tRpr5Bg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B1C8F1377F; Wed, 13 Dec 2023 23:40:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wiJRJf1AemVrPgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:45 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 4/8] libfs: Expose generic_ci_dentry_ops outside of libfs Date: Wed, 13 Dec 2023 18:40:27 -0500 Message-ID: <20231213234031.1081-5-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -0.30 X-Spam-Flag: NO Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -0.30 X-Spamd-Result: default: False [-0.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[11.92%] In preparation to allow filesystems to set this through sb->s_d_op, expose the symbol directly to the filesystems. Signed-off-by: Gabriel Krisman Bertazi --- fs/libfs.c | 2 +- include/linux/fs.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index 52c944173e57..b8ecada3a5b2 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1765,7 +1765,7 @@ static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) return 0; } -static const struct dentry_operations generic_ci_dentry_ops = { +const struct dentry_operations generic_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, #if defined(CONFIG_FS_ENCRYPTION) diff --git a/include/linux/fs.h b/include/linux/fs.h index 98b7a7a8c42e..887a27d07f96 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3202,6 +3202,7 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); +extern const struct dentry_operations generic_ci_dentry_ops; int may_setattr(struct mnt_idmap *idmap, struct inode *inode, unsigned int ia_valid); From patchwork Wed Dec 13 23:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492112 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="UOsbgugB"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="5fvQTkmq"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="UCAEF+An"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="34wK+jkJ" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C58AE325C; Wed, 13 Dec 2023 15:41:02 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E25CC22312; Wed, 13 Dec 2023 23:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510853; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rlZvRBMqCyrEtAxBxHPRZ94VEJ+Zn/S8eQ7sbujlGwE=; b=UOsbgugBCZtVKnclS2O/aqmo9oL6ImGHo45lHB7QVvebqa14ynLYf1AcwhrAed7G5M7WWo NQkdEFH6JWMiWnb2DvrDWwmGt+tsTZQNFGqADVgVS96zmbT86Mt7w8HO7j2LCUNo1SwXU1 Axv0/yEp/3OQaYo5K2YrJfttJbrC/h0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510853; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rlZvRBMqCyrEtAxBxHPRZ94VEJ+Zn/S8eQ7sbujlGwE=; b=5fvQTkmqXGxT3r9NpTgri90gZ1JVcaEVnVdUkzuSAE2b0b/zjnJ4gDsmD7i/iPQC2lblEv Y1CSwhVk4CE+PXBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702510851; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rlZvRBMqCyrEtAxBxHPRZ94VEJ+Zn/S8eQ7sbujlGwE=; b=UCAEF+AnInGYwBfo6nS2UmsPaBOkAZ2aZflq32ojoWzgyWuYc/xnSpdVu7BE5x6gv4yAhq FT40+zCxpiX2t5wAJx5NsZisf5W9l/+KmwSFIj/bIPBm9QvxyUA+4yRDFoURQ3WgCP86yR ZHcYDa/ddKDQmKYvK9L4yN1nlOjstbs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702510851; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rlZvRBMqCyrEtAxBxHPRZ94VEJ+Zn/S8eQ7sbujlGwE=; b=34wK+jkJ0gvVnN/94Bq1LWXNsjUlD9Ucp+j+PVDSW3+7jo6fMLAp0Z6mOXS0457LcjNLL8 0rCOU0O+J/ZXhYAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 96A751377F; Wed, 13 Dec 2023 23:40:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0LefHANBemVtPgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:51 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 5/8] ext4: Set the case-insensitive dentry operations through ->s_d_op Date: Wed, 13 Dec 2023 18:40:28 -0500 Message-ID: <20231213234031.1081-6-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -0.30 X-Spam-Flag: NO Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -0.30 X-Spamd-Result: default: False [-0.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.998]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[linux.org.uk:email,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[19.49%] All dentries in a case-insensitive filesystem have the same set of dentry operations. Therefore, we should let VFS propagate them from sb->s_d_op d_alloc instead of setting at lookup time. This was already the case before commit bb9cd9106b22 ("fscrypt: Have filesystems handle their d_ops"), but it was changed to set at lookup-time to facilitate the integration with fscrypt. But it's a problem because dentries that don't get created through ->lookup() won't have any visibility of the operations. Let's revert to the previous implementation. Suggested-by: Al Viro Signed-off-by: Gabriel Krisman Bertazi --- fs/ext4/namei.c | 6 +++++- fs/ext4/super.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index d252935f9c8a..3c1208d5d85b 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1762,7 +1762,11 @@ static struct buffer_head *ext4_lookup_entry(struct inode *dir, struct buffer_head *bh; err = ext4_fname_prepare_lookup(dir, dentry, &fname); - generic_set_encrypted_ci_d_ops(dentry); + + /* Case-insensitive volumes set dentry ops through sb->s_d_op. */ + if (!dir->i_sb->s_encoding) + generic_set_encrypted_ci_d_ops(dentry); + if (err == -ENOENT) return NULL; if (err) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index c5fcf377ab1f..5ac1c9df9956 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5493,6 +5493,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) goto failed_mount4; } + if (sb->s_encoding) + sb->s_d_op = &generic_ci_dentry_ops; + sb->s_root = d_make_root(root); if (!sb->s_root) { ext4_msg(sb, KERN_ERR, "get root dentry failed"); From patchwork Wed Dec 13 23:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492111 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF7FA326C; Wed, 13 Dec 2023 15:41:02 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7F4B322315; Wed, 13 Dec 2023 23:40:53 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4532B1377F; Wed, 13 Dec 2023 23:40:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 7iDFCgVBemVzPgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:53 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 6/8] f2fs: Set the case-insensitive dentry operations through ->s_d_op Date: Wed, 13 Dec 2023 18:40:29 -0500 Message-ID: <20231213234031.1081-7-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 7F4B322315 X-Spam-Flag: NO All dentries in a case-insensitive filesystem have the same set of dentry operations. Therefore, we should let VFS propagate them from sb->s_d_op d_alloc instead of setting at lookup time. This was already the case before commit bb9cd9106b22 ("fscrypt: Have filesystems handle their d_ops"), but it was changed to set at lookup-time to facilitate the integration with fscrypt. But it's a problem because dentries that don't get created through ->lookup() won't have any visibility of the operations. Let's revert to the previous implementation. Suggested-by: Al Viro Signed-off-by: Gabriel Krisman Bertazi --- fs/f2fs/namei.c | 6 +++++- fs/f2fs/super.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index d0053b0284d8..4053846e2cd3 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -532,7 +532,11 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, } err = f2fs_prepare_lookup(dir, dentry, &fname); - generic_set_encrypted_ci_d_ops(dentry); + + /* Case-insensitive volumes set dentry ops through sb->s_d_op. */ + if (!dir->i_sb->s_encoding) + generic_set_encrypted_ci_d_ops(dentry); + if (err == -ENOENT) goto out_splice; if (err) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 033af907c3b1..0a199eb5b01e 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4663,6 +4663,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) goto free_node_inode; } + if (sb->s_encoding) + sb->s_d_op = &generic_ci_dentry_ops; + sb->s_root = d_make_root(root); /* allocate root dentry */ if (!sb->s_root) { err = -ENOMEM; From patchwork Wed Dec 13 23:40:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492115 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3658F1BE3; Wed, 13 Dec 2023 15:41:03 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 115201F792; Wed, 13 Dec 2023 23:40:55 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CC26A1377F; Wed, 13 Dec 2023 23:40:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id g8DAKwZBemV6PgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:40:54 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 7/8] libfs: Don't support setting casefold operations during lookup Date: Wed, 13 Dec 2023 18:40:30 -0500 Message-ID: <20231213234031.1081-8-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Queue-Id: 115201F792 X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] No filesystems depend on it anymore, and it is generally a bad idea. Since all dentries should have the same set of dentry operations in case-insensitive filesystems, it should be configured through ->s_d_op. Signed-off-by: Gabriel Krisman Bertazi --- fs/libfs.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index b8ecada3a5b2..41c02c003265 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1784,27 +1784,12 @@ static const struct dentry_operations generic_encrypted_dentry_ops = { * generic_set_encrypted_ci_d_ops - helper for setting d_ops for given dentry * @dentry: dentry to set ops on * - * Casefolded directories need d_hash and d_compare set, so that the dentries - * contained in them are handled case-insensitively. Note that these operations - * are needed on the parent directory rather than on the dentries in it, and - * while the casefolding flag can be toggled on and off on an empty directory, - * dentry_operations can't be changed later. As a result, if the filesystem has - * casefolding support enabled at all, we have to give all dentries the - * casefolding operations even if their inode doesn't have the casefolding flag - * currently (and thus the casefolding ops would be no-ops for now). - * * Encryption works differently in that the only dentry operation it needs is * d_revalidate, which it only needs on dentries that have the no-key name flag. * The no-key flag can't be set "later", so we don't have to worry about that. */ void generic_set_encrypted_ci_d_ops(struct dentry *dentry) { -#if IS_ENABLED(CONFIG_UNICODE) - if (dentry->d_sb->s_encoding) { - d_set_d_op(dentry, &generic_ci_dentry_ops); - return; - } -#endif #ifdef CONFIG_FS_ENCRYPTION if (dentry->d_flags & DCACHE_NOKEY_NAME) { d_set_d_op(dentry, &generic_encrypted_dentry_ops); From patchwork Wed Dec 13 23:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13492116 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 583C9324D; Wed, 13 Dec 2023 15:41:02 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9C2B21FD80; Wed, 13 Dec 2023 23:41:00 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 62F5D1377F; Wed, 13 Dec 2023 23:41:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id tZokEgxBemV9PgAAD6G6ig (envelope-from ); Wed, 13 Dec 2023 23:41:00 +0000 From: Gabriel Krisman Bertazi To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org, tytso@mit.edu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH 8/8] fscrypt: Move d_revalidate configuration back into fscrypt Date: Wed, 13 Dec 2023 18:40:31 -0500 Message-ID: <20231213234031.1081-9-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213234031.1081-1-krisman@suse.de> References: <20231213234031.1081-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 9C2B21FD80 X-Spam-Flag: NO This partially reverts commit bb9cd9106b22 ("fscrypt: Have filesystems handle their d_ops"), which moved this handler out of fscrypt and into the filesystems, in preparation to support casefold and fscrypt combinations. Now that we set casefolding operations through ->s_d_op, move this back into fscrypt, where it belongs, but take care to handle filesystems that set their own sb->s_d_op. Signed-off-by: Gabriel Krisman Bertazi --- fs/crypto/hooks.c | 8 ++++++++ fs/ext4/namei.c | 5 ----- fs/f2fs/namei.c | 5 ----- fs/libfs.c | 19 ------------------- fs/ubifs/dir.c | 1 - include/linux/fs.h | 1 - include/linux/fscrypt.h | 10 +++++----- 7 files changed, 13 insertions(+), 36 deletions(-) diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c index 52504dd478d3..166837d5af29 100644 --- a/fs/crypto/hooks.c +++ b/fs/crypto/hooks.c @@ -94,6 +94,10 @@ int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry, } EXPORT_SYMBOL_GPL(__fscrypt_prepare_rename); +static const struct dentry_operations fscrypt_dentry_ops = { + .d_revalidate = fscrypt_d_revalidate, +}; + int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry, struct fscrypt_name *fname) { @@ -106,6 +110,10 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry, spin_lock(&dentry->d_lock); dentry->d_flags |= DCACHE_NOKEY_NAME; spin_unlock(&dentry->d_lock); + + /* Give preference to the filesystem hooks, if any. */ + if (!dentry->d_op) + d_set_d_op(dentry, &fscrypt_dentry_ops); } return err; } diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 3c1208d5d85b..3f0b853a371e 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1762,11 +1762,6 @@ static struct buffer_head *ext4_lookup_entry(struct inode *dir, struct buffer_head *bh; err = ext4_fname_prepare_lookup(dir, dentry, &fname); - - /* Case-insensitive volumes set dentry ops through sb->s_d_op. */ - if (!dir->i_sb->s_encoding) - generic_set_encrypted_ci_d_ops(dentry); - if (err == -ENOENT) return NULL; if (err) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 4053846e2cd3..b40c6c393bd6 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -532,11 +532,6 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, } err = f2fs_prepare_lookup(dir, dentry, &fname); - - /* Case-insensitive volumes set dentry ops through sb->s_d_op. */ - if (!dir->i_sb->s_encoding) - generic_set_encrypted_ci_d_ops(dentry); - if (err == -ENOENT) goto out_splice; if (err) diff --git a/fs/libfs.c b/fs/libfs.c index 41c02c003265..4fed170dfe49 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1780,25 +1780,6 @@ static const struct dentry_operations generic_encrypted_dentry_ops = { }; #endif -/** - * generic_set_encrypted_ci_d_ops - helper for setting d_ops for given dentry - * @dentry: dentry to set ops on - * - * Encryption works differently in that the only dentry operation it needs is - * d_revalidate, which it only needs on dentries that have the no-key name flag. - * The no-key flag can't be set "later", so we don't have to worry about that. - */ -void generic_set_encrypted_ci_d_ops(struct dentry *dentry) -{ -#ifdef CONFIG_FS_ENCRYPTION - if (dentry->d_flags & DCACHE_NOKEY_NAME) { - d_set_d_op(dentry, &generic_encrypted_dentry_ops); - return; - } -#endif -} -EXPORT_SYMBOL(generic_set_encrypted_ci_d_ops); - /** * inode_maybe_inc_iversion - increments i_version * @inode: inode with the i_version that should be updated diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 3b13c648d490..51b9a10a9851 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -205,7 +205,6 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry, dbg_gen("'%pd' in dir ino %lu", dentry, dir->i_ino); err = fscrypt_prepare_lookup(dir, dentry, &nm); - generic_set_encrypted_ci_d_ops(dentry); if (err == -ENOENT) return d_splice_alias(NULL, dentry); if (err) diff --git a/include/linux/fs.h b/include/linux/fs.h index 887a27d07f96..e5ae21f9f637 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3201,7 +3201,6 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); -extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); extern const struct dentry_operations generic_ci_dentry_ops; int may_setattr(struct mnt_idmap *idmap, struct inode *inode, diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 12f9e455d569..97a11280c2bd 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -961,11 +961,11 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir, * key is available, then the lookup is assumed to be by plaintext name; * otherwise, it is assumed to be by no-key name. * - * This will set DCACHE_NOKEY_NAME on the dentry if the lookup is by no-key - * name. In this case the filesystem must assign the dentry a dentry_operations - * which contains fscrypt_d_revalidate (or contains a d_revalidate method that - * calls fscrypt_d_revalidate), so that the dentry will be invalidated if the - * directory's encryption key is later added. + * This also optionally installs a custom ->d_revalidate() method which will + * invalidate the dentry if it was created without the key and the key is later + * added. If the filesystem provides its own ->d_op hooks, they will be used + * instead, but then the filesystem must make sure to call fscrypt_d_revalidate + * in its d_revalidate hook, to check if fscrypt considers the dentry stale. * * Return: 0 on success; -ENOENT if the directory's key is unavailable but the * filename isn't a valid no-key name, so a negative dentry should be created;