From nobody Mon Feb 9 16:17:25 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 2FBF343DA53 for ; Fri, 6 Feb 2026 18:25:36 +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=1770402336; cv=none; b=SibU+CndFDPbF26ewYREKPC/UQm+7ThIK0TEGXu6xwImSnxHFKYasf3ziIvz/lET5m/ROsmOTy7q9rTOw9BUIBDhxA/GFmFMRgJo1t8POnPEf/ECM40NIuTY+k61RHJOMVmR3a9vWXeJqZlvWYCw/MRlsiVnyJkuDWx/m8/WNPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402336; c=relaxed/simple; bh=HDKQWiuOFYGyr6lPE2282Odn8MY1GFwXoZFWSi5il2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=drnC5x+XzM/irEj3YH5D478kCWCwGKpgTs8Gem22ZMxMNtcda3ujEJ+Q+1JgEuFLvFv7OhaFIwzdEfIhepWDQCknwTVUsn5ZyGAXV/OEnoJGwMHhN6Aak9HWRZrDW8vhGeZlslMWXW6dk6oBs1YRpOX+CiR9z1zEe/7b+sBLxW0= 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 565393E760; Fri, 6 Feb 2026 18:24:18 +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 2A5E23EA63; Fri, 6 Feb 2026 18:24:18 +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 2L3dCdIxhmkTCQAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 18:24:18 +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 38/43] btrfs: load the inode context before sending writes Date: Fri, 6 Feb 2026 19:23:10 +0100 Message-ID: <20260206182336.1397715-39-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: 565393E760 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 For send we will read the pages and copy them into our buffer. Use the fscrypt_inode_open helper to make sure the key is loaded properly before trying to read from the inode so the contents are properly decrypted. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5: https://lore.kernel.org/linux-btrfs/a307def01bf28c3ed99398868a142180c60= 88527.1706116485.git.josef@toxicpanda.com/ * btrfs_iget() returns binode now. --- fs/btrfs/send.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index faaade4c35dc..bf9a99a9d24d 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -5331,6 +5331,38 @@ static int put_file_data(struct send_ctx *sctx, u64 = offset, u32 len) return ret; } =20 +static int load_fscrypt_context(struct send_ctx *sctx) +{ + struct btrfs_root *root =3D sctx->send_root; + struct name_cache_entry *nce; + struct btrfs_inode *dir; + int ret; + + if (!btrfs_fs_incompat(root->fs_info, ENCRYPT)) + return 0; + + /* + * If we're encrypted we need to load the parent inode in order to make + * sure the encryption context is loaded. We have to do this even if + * we're not encrypted, as we need to make sure that we don't violate + * the rule about encrypted children with non-encrypted parents, which + * is enforced by __fscrypt_file_open. + */ + nce =3D name_cache_search(sctx, sctx->cur_ino, sctx->cur_inode_gen); + if (!nce) { + ASSERT(nce); + return -EINVAL; + } + + dir =3D btrfs_iget(nce->parent_ino, root); + if (IS_ERR(dir)) + return PTR_ERR(dir); + + ret =3D __fscrypt_file_open(&dir->vfs_inode, sctx->cur_inode); + iput(&dir->vfs_inode); + return ret; +} + /* * Read some bytes from the current inode/file and send a write command to * user space. @@ -5348,6 +5380,10 @@ static int send_write(struct send_ctx *sctx, u64 off= set, u32 len) if (ret < 0) return ret; =20 + ret =3D load_fscrypt_context(sctx); + if (ret < 0) + return ret; + TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); ret =3D put_file_data(sctx, offset, len); --=20 2.51.0