From nobody Mon Feb 9 10:28:14 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3C4C428476 for ; Fri, 6 Feb 2026 18:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402253; cv=none; b=Qdaqv+zHaBX1RA4JCRNDh/WpuhF+fOn3RWsZJDibKxLosWN5HIJTByXMxEsG3PSapGgs7cgFEn2YrPg4aJdAPDOJJ9z6rYaoiD5TOAbWLH/hlyZUJoJD+YPcPbEBgpgjONqqBVSvzyPr6My06OlNdFv/LoNTXNj3s10xqWodGpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402253; c=relaxed/simple; bh=EapV8U1miyXO0gY5JnhdhB+GrtVyUlRXkbekHb4fOa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pB3P9hkW91xT7OPU3rDQZO5KOjQhmDxOQgNdN+iEZ9XVvevF6mlpxUap8N3MyHhWA1C5sf5gtw2zA/uNvYKVIxPSQg2EgbMwukfXi5jXFVsjzC1pEhOumwYeNvapson6UWGeDw6yFY2t4+FCQDy0FrdJHJRCh3TXH+rK95um48k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=Rz+XSR9A; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=SXFLBIAh; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="Rz+XSR9A"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="SXFLBIAh" Received: from imap1.dmz-prg2.suse.org (unknown [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 DD2BA5BD25; Fri, 6 Feb 2026 18:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1770402238; 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=aDxiEePKaHFlI5tO/p1XE2bOmMKz7ygZnuualgpXxeQ=; b=Rz+XSR9A/QjymWWwWstf+F0zAhUm09SGimogvLcNSFX/iG8NnFanC906Wew1e68KMfd+Mr xre3I8UKzAWhXufqXU4E+pY6azfp2uncYq1gNEjJFQRQzjYy9vatjIsk2oP78vfH5q7rcC 5Tymo5cIIZPncxDwaEjJ6QBLTWH2P1A= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1770402237; 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=aDxiEePKaHFlI5tO/p1XE2bOmMKz7ygZnuualgpXxeQ=; b=SXFLBIAhJ1jmnSvHBqXvDbAQjJYkHn7YmMuE/Xr4gAqElaT9hb0p+FWSdvyMCqANkIg8Vg qD5pr2sMLyAG7QVfUTYEIGENGM2us4Lczxhxv7CX+1jhOnC6YmVSPhNdLLprBwRBGVBAj1 414N/rMCK6lUAdMteaZOKHNpBKRYCQ4= 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 AE23E3EA63; Fri, 6 Feb 2026 18:23:57 +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 kN3qKb0xhmkTCQAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 18:23:57 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Jens Axboe , David Sterba Cc: linux-block@vger.kernel.org, Daniel Vacek , linux-fscrypt@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Omar Sandoval , Sweet Tea Dorminy Subject: [PATCH v6 07/43] fscrypt: expose fscrypt_nokey_name Date: Fri, 6 Feb 2026 19:22:39 +0100 Message-ID: <20260206182336.1397715-8-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260206182336.1397715-1-neelx@suse.com> References: <20260206182336.1397715-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[14]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" From: Omar Sandoval btrfs stores its data structures, including filenames in directories, in its own buffer implementation, struct extent_buffer, composed of several non-contiguous pages. We could copy filenames into a temporary buffer and use fscrypt_match_name() against that buffer, such extensive memcpying would be expensive. Instead, exposing fscrypt_nokey_name as in this change allows btrfs to recapitulate fscrypt_match_name() using methods on struct extent_buffer instead of dealing with a raw byte array. Signed-off-by: Omar Sandoval Signed-off-by: Sweet Tea Dorminy Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5: https://lore.kernel.org/linux-btrfs/132b64edf1e6b705995fb1a6dc2f194527f= 6be75.1706116485.git.josef@toxicpanda.com/ * No changes since. --- fs/crypto/fname.c | 36 ------------------------------------ include/linux/fscrypt.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index a9a4432d12ba..1e5e503686dd 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -27,42 +27,6 @@ */ #define FSCRYPT_FNAME_MIN_MSG_LEN 16 =20 -/* - * struct fscrypt_nokey_name - identifier for directory entry when key is = absent - * - * When userspace lists an encrypted directory without access to the key, = the - * filesystem must present a unique "no-key name" for each filename that a= llows - * it to find the directory entry again if requested. Naively, that would= just - * mean using the ciphertext filenames. However, since the ciphertext fil= enames - * can contain illegal characters ('\0' and '/'), they must be encoded in = some - * way. We use base64url. But that can cause names to exceed NAME_MAX (2= 55 - * bytes), so we also need to use a strong hash to abbreviate long names. - * - * The filesystem may also need another kind of hash, the "dirhash", to qu= ickly - * find the directory entry. Since filesystems normally compute the dirha= sh - * over the on-disk filename (i.e. the ciphertext), it's not computable fr= om - * no-key names that abbreviate the ciphertext using the strong hash to fi= t in - * NAME_MAX. It's also not computable if it's a keyed hash taken over the - * plaintext (but it may still be available in the on-disk directory entry= ); - * casefolded directories use this type of dirhash. At least in these cas= es, - * each no-key name must include the name's dirhash too. - * - * To meet all these requirements, we base64url-encode the following - * variable-length structure. It contains the dirhash, or 0's if the file= system - * didn't provide one; up to 149 bytes of the ciphertext name; and for - * ciphertexts longer than 149 bytes, also the SHA-256 of the remaining by= tes. - * - * This ensures that each no-key name contains everything needed to find t= he - * directory entry again, contains only legal characters, doesn't exceed - * NAME_MAX, is unambiguous unless there's a SHA-256 collision, and that w= e only - * take the performance hit of SHA-256 on very long filenames (which are r= are). - */ -struct fscrypt_nokey_name { - u32 dirhash[2]; - u8 bytes[149]; - u8 sha256[SHA256_DIGEST_SIZE]; -}; /* 189 bytes =3D> 252 bytes base64url-encoded, which is <=3D NAME_MAX (= 255) */ - /* * Decoded size of max-size no-key name, i.e. a name that was abbreviated = using * the strong hash and thus includes the 'sha256' field. This isn't simply diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index e3bb9e3756e1..5b4fc75c257c 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -56,6 +56,42 @@ struct fscrypt_name { #define fname_name(p) ((p)->disk_name.name) #define fname_len(p) ((p)->disk_name.len) =20 +/* + * struct fscrypt_nokey_name - identifier for directory entry when key is = absent + * + * When userspace lists an encrypted directory without access to the key, = the + * filesystem must present a unique "no-key name" for each filename that a= llows + * it to find the directory entry again if requested. Naively, that would= just + * mean using the ciphertext filenames. However, since the ciphertext fil= enames + * can contain illegal characters ('\0' and '/'), they must be encoded in = some + * way. We use base64url. But that can cause names to exceed NAME_MAX (2= 55 + * bytes), so we also need to use a strong hash to abbreviate long names. + * + * The filesystem may also need another kind of hash, the "dirhash", to qu= ickly + * find the directory entry. Since filesystems normally compute the dirha= sh + * over the on-disk filename (i.e. the ciphertext), it's not computable fr= om + * no-key names that abbreviate the ciphertext using the strong hash to fi= t in + * NAME_MAX. It's also not computable if it's a keyed hash taken over the + * plaintext (but it may still be available in the on-disk directory entry= ); + * casefolded directories use this type of dirhash. At least in these cas= es, + * each no-key name must include the name's dirhash too. + * + * To meet all these requirements, we base64url-encode the following + * variable-length structure. It contains the dirhash, or 0's if the file= system + * didn't provide one; up to 149 bytes of the ciphertext name; and for + * ciphertexts longer than 149 bytes, also the SHA-256 of the remaining by= tes. + * + * This ensures that each no-key name contains everything needed to find t= he + * directory entry again, contains only legal characters, doesn't exceed + * NAME_MAX, is unambiguous unless there's a SHA-256 collision, and that w= e only + * take the performance hit of SHA-256 on very long filenames (which are r= are). + */ +struct fscrypt_nokey_name { + u32 dirhash[2]; + u8 bytes[149]; + u8 sha256[32]; +}; /* 189 bytes =3D> 252 bytes base64url-encoded, which is <=3D NAME_MAX (= 255) */ + /* Maximum value for the third parameter of fscrypt_operations.set_context= (). */ #define FSCRYPT_SET_CONTEXT_MAX_SIZE 40 =20 --=20 2.51.0