From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B74672D7DEF; Tue, 31 Mar 2026 17:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774976856; cv=none; b=ujxyzd8RyX76IQT9aXGTy46CDQkW35J5HNMNYCLzqD2JinFGtQQcIz5KeCRtzMKJvf8PYdYlVld93kJiUEKhcsi+Az3htupIhFiFyBv6wTE/Wg4Ukl7eEqppI6tRiS89/xcGkHfXjZ6cLePdjNw/op83MQrmAAldNbSkaWKjXes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774976856; c=relaxed/simple; bh=BD8sDFt3SKL/fGJm6ub5AQT1O62OWQnyU8qXnfSBWEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pirYlHNWulO4cdGm3NbftS8AM9jQHt7h1V3/S7dOlZ4eLhXrVzQuIBSejYS2W4KH9fXSbC6nqcWCj1BRF8rMQdg4muejKeTTgp3gu4QyZT3BIY09wWsYeJyZkP7tEq5Vk144bvyNHdsefbohBGAEMY6AF0W+L5aiRP9+2mtlo6M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JIHCkUPG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JIHCkUPG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C9B7C19423; Tue, 31 Mar 2026 17:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774976856; bh=BD8sDFt3SKL/fGJm6ub5AQT1O62OWQnyU8qXnfSBWEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JIHCkUPG2FXF7TOuYd2FsAHssV0DG929MeDcZH3zvoqKSCfRf4Vz9p/zdL711RlCu n1F8cAzEfk1DbSF7XuWN/S+b1j1wxVV+e5pHpYQcoZNcf4AI9Q5YV2QKhMULi8Osvw 30nWGYmWJSm+hyidGT0ACkGcqCIZOiFuzb11h8qY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Anthony Durrer , Simon Weber , Eric Biggers , Theodore Tso , stable@kernel.org Subject: [PATCH 6.18 254/309] ext4: fix journal credit check when setting fscrypt context Date: Tue, 31 Mar 2026 18:22:37 +0200 Message-ID: <20260331161802.923372205@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331161753.468533260@linuxfoundation.org> References: <20260331161753.468533260@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Simon Weber commit b1d682f1990c19fb1d5b97d13266210457092bcd upstream. Fix an issue arising when ext4 features has_journal, ea_inode, and encrypt are activated simultaneously, leading to ENOSPC when creating an encrypted file. Fix by passing XATTR_CREATE flag to xattr_set_handle function if a handle is specified, i.e., when the function is called in the control flow of creating a new inode. This aligns the number of jbd2 credits set_handle checks for with the number allocated for creating a new inode. ext4_set_context must not be called with a non-null handle (fs_data) if fscrypt context xattr is not guaranteed to not exist yet. The only other usage of this function currently is when handling the ioctl FS_IOC_SET_ENCRYPTION_POLICY, which calls it with fs_data=NULL. Fixes: c1a5d5f6ab21eb7e ("ext4: improve journal credit handling in set xattr paths") Co-developed-by: Anthony Durrer Signed-off-by: Anthony Durrer Signed-off-by: Simon Weber Reviewed-by: Eric Biggers Link: https://patch.msgid.link/20260207100148.724275-4-simon.weber.39@gmail.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/crypto.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -163,10 +163,17 @@ static int ext4_set_context(struct inode */ if (handle) { + /* + * Since the inode is new it is ok to pass the + * XATTR_CREATE flag. This is necessary to match the + * remaining journal credits check in the set_handle + * function with the credits allocated for the new + * inode. + */ res = ext4_xattr_set_handle(handle, inode, EXT4_XATTR_INDEX_ENCRYPTION, EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, - ctx, len, 0); + ctx, len, XATTR_CREATE); if (!res) { ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT); ext4_clear_inode_state(inode,