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 6BF0819DF4F; Thu, 6 Jun 2024 14:18:09 +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=1717683489; cv=none; b=l1MY1d1MqLj2HTrMEV6JelUxNDDGceGyi2o6BpefYNImP+ebvAtaY4aF51+8fAfi7HnwFp4hIIcKb0EtFyHNON0TU3T9LSq1eBza18N0CY3oDLoBPigLYFLNxaf6WyXQUrA1NgE25GkI9dP8lsB7PnDJ8boXvZ/9WgZ7btbMBW0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683489; c=relaxed/simple; bh=pSwlInxndPqVn5+NBz1QBCgkSFETt9DmfeeiOZ2ZMus=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YjlEJ51daWFy8EZ0XXky8T0Xxnn30PKpI2pGebyqVFX4/JqkvcMF/imbZ4X9z2aNqRpZXPckTzIfuLgHAMpBZ4g+rfCFplwvSs6L13r+EhdML6kmRLu+l4Ke1PeBu5I6xwxOjo/4dCqhF5FEhMq1D5MNIdaEC1NgpFjAHKX65xg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ApS5wU5s; 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="ApS5wU5s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B93AC32782; Thu, 6 Jun 2024 14:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717683489; bh=pSwlInxndPqVn5+NBz1QBCgkSFETt9DmfeeiOZ2ZMus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ApS5wU5sk2yCDCA1LxDDsDM8Cuk7twz/TnCLo3mnppf7Hqas1NcSfP2bs2ydpwRhy 7iHdETrK/cC+zNjN4wkmjfZAc1niXLYC8aXrzPdX7U5VlkRoFMyi2Le2g6qkPe2J8O MQIghrew1RV62AxQNDMSGlnGW1XAr7eXvJlrR0Ys= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhiguo Niu , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.6 432/744] f2fs: compress: fix to relocate check condition in f2fs_{release,reserve}_compress_blocks() Date: Thu, 6 Jun 2024 16:01:44 +0200 Message-ID: <20240606131746.326540280@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606131732.440653204@linuxfoundation.org> References: <20240606131732.440653204@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 7c5dffb3d90c5921b91981cc663e02757d90526e ] Compress flag should be checked after inode lock held to avoid racing w/ f2fs_setflags_common(), fix it. Fixes: 4c8ff7095bef ("f2fs: support data compression") Reported-by: Zhiguo Niu Closes: https://lore.kernel.org/linux-f2fs-devel/CAHJ8P3LdZXLc2rqeYjvymgYHr2+YLuJ0sLG9DdsJZmwO7deuhw@mail.gmail.com Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 7f631a617ee99..0350f36d043d6 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3488,9 +3488,6 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) if (!f2fs_sb_has_compression(sbi)) return -EOPNOTSUPP; - if (!f2fs_compressed_file(inode)) - return -EINVAL; - if (f2fs_readonly(sbi->sb)) return -EROFS; @@ -3509,7 +3506,8 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) goto out; } - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + if (!f2fs_compressed_file(inode) || + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { ret = -EINVAL; goto out; } @@ -3672,9 +3670,6 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) if (!f2fs_sb_has_compression(sbi)) return -EOPNOTSUPP; - if (!f2fs_compressed_file(inode)) - return -EINVAL; - if (f2fs_readonly(sbi->sb)) return -EROFS; @@ -3686,7 +3681,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) inode_lock(inode); - if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { + if (!f2fs_compressed_file(inode) || + !is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { ret = -EINVAL; goto unlock_inode; } -- 2.43.0