From nobody Mon Feb 9 14:32:59 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 CC264425CCF for ; Fri, 6 Feb 2026 18:24:05 +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=1770402249; cv=none; b=FCwdH4BTOSad3uAtQHFM+u7e/xzqmSuGVUWm8t91KxaOgDx1HE+8+QblnFkaGjrHR3onT7U/8WA6ESWBrlCM7HRqJA/UhmK0ffljFicXCQUvngrpKDriv/x+gS45d5K71ljgxNf0I4u/P7BHTmc9w1dbImbqkacfYmmRZfk6n3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402249; c=relaxed/simple; bh=V3qkz5KR+/fbjcLmGLO6jWlKLTc0sUhs1UdnMQPC+Mc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xkc+NKTuB/4rdZoz55HxM+o10fNF5q0QinDQSV/vMOCsW0Bnm65hnDpfDox784hjwxXUdPtcpoO/xkJR3axuKX1CaiwESfSNVJupxz77aIB+UZ8i3d/1EHdo/D9z/Vuo20Ysa2xt1LyKr3JV1inqorLPrnZ30LrkNiuL7pZ6Ra8= 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 8E7693E743; Fri, 6 Feb 2026 18:23:55 +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 638BB3EA63; Fri, 6 Feb 2026 18:23:55 +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 wM/aF7sxhmkTCQAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 18:23:55 +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 03/43] fscrypt: add a __fscrypt_file_open helper Date: Fri, 6 Feb 2026 19:22:35 +0100 Message-ID: <20260206182336.1397715-4-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: 8E7693E743 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 We have fscrypt_file_open() which is meant to be called on files being opened so that their key is loaded when we start reading data from them. However for btrfs send we are opening the inode directly without a filp, so we need a different helper to make sure we can load the fscrypt context for the inode before reading its contents. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5: https://lore.kernel.org/linux-btrfs/4a372419c3fe6ad425e1b124c342a054e9d= 6db23.1706116485.git.josef@toxicpanda.com/ * Adapted to fscrypt changes. --- fs/crypto/hooks.c | 38 ++++++++++++++++++++++++++++++++------ include/linux/fscrypt.h | 8 ++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c index b97de0d1430f..17eb2e844f30 100644 --- a/fs/crypto/hooks.c +++ b/fs/crypto/hooks.c @@ -9,6 +9,37 @@ =20 #include "fscrypt_private.h" =20 +/** + * __fscrypt_file_open() - prepare for filesystem-internal access to a + * possibly-encrypted regular file + * @dir: the inode for the directory via which the file is being accessed + * @inode: the inode being "opened" + * + * This is like fscrypt_file_open(), but instead of taking the 'struct fil= e' + * being opened it takes the parent directory explicitly. This is intende= d for + * use cases such as "send/receive" which involve the filesystem accessing= file + * contents without setting up a 'struct file'. + * + * Return: 0 on success, -ENOKEY if the key is missing, or another -errno = code + */ +int __fscrypt_file_open(struct inode *dir, struct inode *inode) +{ + int err; + + err =3D fscrypt_require_key(inode); + if (err) + return err; + + if (!fscrypt_has_permitted_context(dir, inode)) { + fscrypt_warn(inode, + "Inconsistent encryption context (parent directory: %lu)", + dir->i_ino); + return -EPERM; + } + return 0; +} +EXPORT_SYMBOL_GPL(__fscrypt_file_open); + /** * fscrypt_file_open() - prepare to open a possibly-encrypted regular file * @inode: the inode being opened @@ -60,12 +91,7 @@ int fscrypt_file_open(struct inode *inode, struct file *= filp) rcu_read_unlock(); =20 dentry_parent =3D dget_parent(dentry); - if (!fscrypt_has_permitted_context(d_inode(dentry_parent), inode)) { - fscrypt_warn(inode, - "Inconsistent encryption context (parent directory: %lu)", - d_inode(dentry_parent)->i_ino); - err =3D -EPERM; - } + err =3D __fscrypt_file_open(d_inode(dentry_parent), inode); dput(dentry_parent); return err; } diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 5a17e4975b06..dba5ca122775 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -471,6 +471,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pg= off_t lblk, =20 /* hooks.c */ int fscrypt_file_open(struct inode *inode, struct file *filp); +int __fscrypt_file_open(struct inode *dir, struct inode *inode); int __fscrypt_prepare_link(struct inode *inode, struct inode *dir, struct dentry *dentry); int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_den= try, @@ -818,6 +819,13 @@ static inline int fscrypt_file_open(struct inode *inod= e, struct file *filp) return 0; } =20 +static inline int __fscrypt_file_open(struct inode *dir, struct inode *ino= de) +{ + if (IS_ENCRYPTED(inode)) + return -EOPNOTSUPP; + return 0; +} + static inline int __fscrypt_prepare_link(struct inode *inode, struct inode= *dir, struct dentry *dentry) { --=20 2.51.0