From nobody Mon Feb 9 16:17:24 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 A83DD44A710 for ; Fri, 6 Feb 2026 18:25:11 +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=1770402311; cv=none; b=oor7LolbUSAfn35anvtRQiE5c64cJfe4dWsyEZ2h57KiPec+PIqZxLzXNJKWrtA40CgK4/mzBuZOqyqu/5Tuq4dF6GCaQAZKCQIXlf3MtYmXEi5SmGLQ4VmQxgW6g9K1myNYQevNfXfEPuiYkAtVEoUPqnv/uXJo5C+ptn4Ysqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402311; c=relaxed/simple; bh=jxsfwWOkFu6y3aSWsnhI7vrlS53sGNFWe3N9q0oyctE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mGxGY6vVejbT13ZWk/fFYwybfQPiwz0/e77H283wpllq1TA4A1oif5Vv+ZneI8QRq868fsN4PU4nGow+gYpcDfOY1n6SkoVx6dud1vfwhF+VC2V7+TnCHcsUZg4uT6qjMp2ZJya6/9ToE5yZDsGA2YVMgM/I2m45YXaKIQEba3Q= 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.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 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 E5CDF5BD03; Fri, 6 Feb 2026 18:24:17 +0000 (UTC) Authentication-Results: smtp-out2.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 B97A53EA63; Fri, 6 Feb 2026 18:24:17 +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 gEDCLNExhmkTCQAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 18:24:17 +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 37/43] btrfs: decrypt file names for send Date: Fri, 6 Feb 2026 19:23:09 +0100 Message-ID: <20260206182336.1397715-38-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-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: E5CDF5BD03 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spam-Level: Content-Type: text/plain; charset="utf-8" From: Josef Bacik In send we're going to be looking up file names from back references and putting them into the send stream. If we are encrypted use the helper for decrypting names and copy the decrypted name into the buffer. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5: https://lore.kernel.org/linux-btrfs/fd8b1d5f395a890dbdf8281a52fbaaa920c= 7b726.1706116485.git.josef@toxicpanda.com/ * Simplified the error return logic in fs_path_add_from_encrypted(). --- fs/btrfs/send.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index b77f96ae2fea..faaade4c35dc 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -32,6 +32,7 @@ #include "ioctl.h" #include "verity.h" #include "lru_cache.h" +#include "fscrypt.h" =20 /* * Maximum number of references an extent can have in order for us to atte= mpt to @@ -579,13 +580,39 @@ static inline int fs_path_add_path(struct fs_path *p,= const struct fs_path *p2) return fs_path_add(p, p2->start, fs_path_len(p2)); } =20 -static int fs_path_add_from_extent_buffer(struct fs_path *p, +static int fs_path_add_from_encrypted(struct btrfs_root *root, + struct fs_path *p, + struct extent_buffer *eb, + unsigned long off, int len, + u64 parent_ino) +{ + struct fscrypt_str fname =3D FSTR_INIT(NULL, 0); + int ret; + + ret =3D fscrypt_fname_alloc_buffer(BTRFS_NAME_LEN, &fname); + if (ret) + return ret; + + ret =3D btrfs_decrypt_name(root, eb, off, len, parent_ino, &fname); + if (!ret) + ret =3D fs_path_add(p, fname.name, fname.len); + + fscrypt_fname_free_buffer(&fname); + return ret; +} + +static int fs_path_add_from_extent_buffer(struct btrfs_root *root, + struct fs_path *p, struct extent_buffer *eb, - unsigned long off, int len) + unsigned long off, int len, + u64 parent_ino) { int ret; char *prepared; =20 + if (root && btrfs_fs_incompat(root->fs_info, ENCRYPT)) + return fs_path_add_from_encrypted(root, p, eb, off, len, parent_ino); + ret =3D fs_path_prepare_for_add(p, len, &prepared); if (ret < 0) return ret; @@ -1062,8 +1089,7 @@ static int iterate_inode_ref(struct btrfs_root *root,= struct btrfs_path *path, } p->start =3D start; } else { - ret =3D fs_path_add_from_extent_buffer(p, eb, name_off, - name_len); + ret =3D fs_path_add_from_extent_buffer(root, p, eb, name_off, name_len,= dir); if (ret < 0) goto out; } @@ -1759,7 +1785,7 @@ static int read_symlink_unencrypted(struct btrfs_root= *root, u64 ino, struct fs_ off =3D btrfs_file_extent_inline_start(ei); len =3D btrfs_file_extent_ram_bytes(path->nodes[0], ei); =20 - return fs_path_add_from_extent_buffer(dest, path->nodes[0], off, len); + return fs_path_add_from_extent_buffer(NULL, dest, path->nodes[0], off, le= n, 0); } =20 static int read_symlink_encrypted(struct btrfs_root *root, u64 ino, struct= fs_path *dest) @@ -2034,18 +2060,19 @@ static int get_first_ref(struct btrfs_root *root, u= 64 ino, iref =3D btrfs_item_ptr(path->nodes[0], path->slots[0], struct btrfs_inode_ref); len =3D btrfs_inode_ref_name_len(path->nodes[0], iref); - ret =3D fs_path_add_from_extent_buffer(name, path->nodes[0], - (unsigned long)(iref + 1), - len); parent_dir =3D found_key.offset; + ret =3D fs_path_add_from_extent_buffer(root, name, path->nodes[0], + (unsigned long)(iref + 1), + len, parent_dir); } else { struct btrfs_inode_extref *extref; extref =3D btrfs_item_ptr(path->nodes[0], path->slots[0], struct btrfs_inode_extref); len =3D btrfs_inode_extref_name_len(path->nodes[0], extref); - ret =3D fs_path_add_from_extent_buffer(name, path->nodes[0], - (unsigned long)&extref->name, len); parent_dir =3D btrfs_inode_extref_parent(path->nodes[0], extref); + ret =3D fs_path_add_from_extent_buffer(root, name, path->nodes[0], + (unsigned long)&extref->name, len, + parent_dir); } if (ret < 0) return ret; --=20 2.51.0