From nobody Mon Feb 9 11:47:26 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 654CB44BC9F for ; Fri, 6 Feb 2026 18:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402327; cv=none; b=sx7dWthPhA84d3+BClYKZD3JLV1qBBeimip4BrutkJBEUAg/7PLyMaZYbezTomPJl4VIicJIRRA2MblQB/ACYvsnD92Znu4MP/11OvirrWBG2qzCbEcn1MPYaGHUQ9/oQATAiee4YDMJzQUIPPCy5qfejLubvgNN+znq1IPsHys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402327; c=relaxed/simple; bh=9LsGDAhN6yaS4eVreOGRrVmOuVBkuDvHtHFMAJyoGyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X5D9Bcct9W7Xf/2G7HGzKX3axpv73ReXcUEvTza1mjNSeAg+/JfAxVL0aNgUSbF9C+WmF4+joZMU0WF/dI1wmx/lqEWANNumQmCliULeML/ceiCdV/j2SZWdar+3yo+nfVBHbcuBDT5hSI5VXC63FT2Jjx16A0zcCgDmyKDdu3Y= 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; arc=none smtp.client-ip=195.135.223.130 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 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 102F53E737; Fri, 6 Feb 2026 18:24:17 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 D5F513EA63; Fri, 6 Feb 2026 18:24:16 +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 uOKzM9AxhmkTCQAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 18:24:16 +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 Subject: [PATCH v6 35/43] btrfs: make btrfs_ref_to_path handle encrypted filenames Date: Fri, 6 Feb 2026 19:23:07 +0100 Message-ID: <20260206182336.1397715-36-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-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Score: -4.00 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Queue-Id: 102F53E737 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" From: Josef Bacik We use this helper for inode-resolve and path resolution in send, so update this helper to properly decrypt any encrypted names it finds. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5: https://lore.kernel.org/linux-btrfs/365d4f820f70b7cf69b1b9cae9b949a15c3= 350b0.1706116485.git.josef@toxicpanda.com/ * Adapted to btrfs_iget() now returning binode instead of vfs inode as before. * Adapted to crypt info being moved from vfs inode to FS specific inode. --- fs/btrfs/backref.c | 42 +++++++++++++++++++++++++++++++++++++---- fs/btrfs/fscrypt.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/fscrypt.h | 10 ++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 9bb406f7dd30..577c3ef87791 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -20,6 +20,7 @@ #include "extent-tree.h" #include "relocation.h" #include "tree-checker.h" +#include "fscrypt.h" =20 /* Just arbitrary numbers so we can be sure one of these happened. */ #define BACKREF_FOUND_SHARED 6 @@ -2107,6 +2108,39 @@ int btrfs_find_one_extref(struct btrfs_root *root, u= 64 inode_objectid, return ret; } =20 +static int copy_resolved_iref_to_buf(struct btrfs_root *fs_root, + struct extent_buffer *eb, char *dest, + u64 parent, unsigned long name_off, + u32 name_len, s64 *bytes_left) +{ + struct btrfs_fs_info *fs_info =3D fs_root->fs_info; + struct fscrypt_str fname =3D FSTR_INIT(NULL, 0); + int ret; + + /* No encryption, just copy the name in. */ + if (!btrfs_fs_incompat(fs_info, ENCRYPT)) { + *bytes_left -=3D name_len; + if (*bytes_left >=3D 0) + read_extent_buffer(eb, dest + *bytes_left, name_off, name_len); + return 0; + } + + ret =3D fscrypt_fname_alloc_buffer(BTRFS_NAME_LEN, &fname); + if (ret) + return ret; + + ret =3D btrfs_decrypt_name(fs_root, eb, name_off, name_len, parent, &fnam= e); + if (ret) + goto out; + + *bytes_left -=3D fname.len; + if (*bytes_left >=3D 0) + memcpy(dest + *bytes_left, fname.name, fname.len); +out: + fscrypt_fname_free_buffer(&fname); + return ret; +} + /* * this iterates to turn a name (from iref/extref) into a full filesystem = path. * Elements of the path are separated by '/' and the path is guaranteed to= be @@ -2138,10 +2172,10 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root,= struct btrfs_path *path, dest[bytes_left] =3D '\0'; =20 while (1) { - bytes_left -=3D name_len; - if (bytes_left >=3D 0) - read_extent_buffer(eb, dest + bytes_left, - name_off, name_len); + ret =3D copy_resolved_iref_to_buf(fs_root, eb, dest, parent, + name_off, name_len, &bytes_left); + if (ret) + break; if (eb !=3D eb_in) { if (!path->skip_locking) btrfs_tree_read_unlock(eb); diff --git a/fs/btrfs/fscrypt.c b/fs/btrfs/fscrypt.c index d1a4cbb990d4..bcb86cbaa171 100644 --- a/fs/btrfs/fscrypt.c +++ b/fs/btrfs/fscrypt.c @@ -385,6 +385,53 @@ int btrfs_fscrypt_bio_length(struct bio *bio, u64 map_= length) return map_length; } =20 +int btrfs_decrypt_name(struct btrfs_root *root, struct extent_buffer *eb, + unsigned long name_off, u32 name_len, + u64 parent_ino, struct fscrypt_str *name) +{ + struct btrfs_inode *inode; + struct inode *dir; + struct fscrypt_str iname =3D FSTR_INIT(NULL, 0); + int ret; + + ASSERT(name_len <=3D BTRFS_NAME_LEN); + + ret =3D fscrypt_fname_alloc_buffer(name_len, &iname); + if (ret) + return ret; + + inode =3D btrfs_iget(parent_ino, root); + if (IS_ERR(inode)) { + ret =3D PTR_ERR(inode); + goto out; + } + dir =3D &inode->vfs_inode; + + /* + * Directory isn't encrypted, the name isn't encrypted, we can just copy + * it into the buffer. + */ + if (!IS_ENCRYPTED(dir)) { + read_extent_buffer(eb, name->name, name_off, name_len); + name->len =3D name_len; + goto out_inode; + } + + read_extent_buffer(eb, iname.name, name_off, name_len); + + ret =3D fscrypt_prepare_readdir(dir); + if (ret) + goto out_inode; + + ASSERT(inode->i_crypt_info); + ret =3D fscrypt_fname_disk_to_usr(dir, 0, 0, &iname, name); +out_inode: + iput(dir); +out: + fscrypt_fname_free_buffer(&iname); + return ret; +} + const struct fscrypt_operations btrfs_fscrypt_ops =3D { .inode_info_offs =3D (int)offsetof(struct btrfs_inode, i_crypt_info) - (int)offsetof(struct btrfs_inode, vfs_inode), diff --git a/fs/btrfs/fscrypt.h b/fs/btrfs/fscrypt.h index 347b34f45715..4f49ed6176d4 100644 --- a/fs/btrfs/fscrypt.h +++ b/fs/btrfs/fscrypt.h @@ -32,6 +32,9 @@ bool btrfs_mergeable_encrypted_bio(struct bio *bio, struc= t inode *inode, struct fscrypt_extent_info *fi, u64 logical_offset); int btrfs_fscrypt_bio_length(struct bio *bio, u64 map_length); +int btrfs_decrypt_name(struct btrfs_root *root, struct extent_buffer *eb, + unsigned long name_off, u32 name_len, + u64 parent_ino, struct fscrypt_str *name); =20 #else static inline void btrfs_fscrypt_save_extent_info(struct btrfs_path *path, @@ -91,6 +94,13 @@ static inline u64 btrfs_fscrypt_bio_length(struct bio *b= io, u64 map_length) return map_length; } =20 +static inline int btrfs_decrypt_name(struct btrfs_root *root, struct exten= t_buffer *eb, + unsigned long name_off, u32 name_len, + u64 parent_ino, struct fscrypt_str *name) +{ + return -EINVAL; +} + #endif /* CONFIG_FS_ENCRYPTION */ =20 extern const struct fscrypt_operations btrfs_fscrypt_ops; --=20 2.51.0