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 56C2C14198E; Thu, 13 Jun 2024 12:38:24 +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=1718282304; cv=none; b=bhP36qpX2lzbTs50MlimKp6PHmop74+zLPr/P/d22CC+UbUv7okjDWrnMLmWi5rqwo/cM5AZhZT4KroNv15F9k52PMyTFLc5MN4st0IIGLUPTx7PHJaTJBIO3ht6H0stfNCZHZ5S98gKrJuoxCR4eS39jfuHo0uJbnRuAFG338s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718282304; c=relaxed/simple; bh=ZQVXsEOXsfHdwCvMmsO8gqDEEbHBRUjCFCg6uTYNo+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HgLyMhxcqOIn75uq6QTAS7K6M0v7CpT4tLx7co8elaTlA6AuYtJR4l+x4DKFSk31oLe5Dshf7CTD3syqEV8TLBYhtuYggAU9PnwI1KBGIJ+khbVQZ2DlE91RQ20Zz23SqBg/jNqJkDlt36aDejfKNyvut84cyNP2DbIotXIJS5k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NzcXLyJc; 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="NzcXLyJc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9F4DC2BBFC; Thu, 13 Jun 2024 12:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718282304; bh=ZQVXsEOXsfHdwCvMmsO8gqDEEbHBRUjCFCg6uTYNo+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NzcXLyJcSRcJFaeIo8Ez0PAosftvdikAbryqpn7s8Yjz8/WRlh7dmtHOcpuyh4JcZ gFh3EnKl+93hulZBJuXPrb5XS82IAlEqmSofxnEpKJ/bHPvaGHyH5ZmnpYWZ1Kq3VN nCShPqeLcnbIfM+YUWOp+wpW4xJzgPWQTCqeItx4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.15 232/402] f2fs: compress: fix to cover {reserve,release}_compress_blocks() w/ cp_rwsem lock Date: Thu, 13 Jun 2024 13:33:09 +0200 Message-ID: <20240613113311.195042951@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113302.116811394@linuxfoundation.org> References: <20240613113302.116811394@linuxfoundation.org> User-Agent: quilt/0.67 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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 0a4ed2d97cb6d044196cc3e726b6699222b41019 ] It needs to cover {reserve,release}_compress_blocks() w/ cp_rwsem lock to avoid racing with checkpoint, otherwise, filesystem metadata including blkaddr in dnode, inode fields and .total_valid_block_count may be corrupted after SPO case. Fixes: ef8d563f184e ("f2fs: introduce F2FS_IOC_RELEASE_COMPRESS_BLOCKS") Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f10156aecf425..30b015fbec6a5 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3490,9 +3490,12 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) struct dnode_of_data dn; pgoff_t end_offset, count; + f2fs_lock_op(sbi); + set_new_dnode(&dn, inode, NULL, NULL, 0); ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); if (ret) { + f2fs_unlock_op(sbi); if (ret == -ENOENT) { page_idx = f2fs_get_next_page_offset(&dn, page_idx); @@ -3510,6 +3513,8 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) f2fs_put_dnode(&dn); + f2fs_unlock_op(sbi); + if (ret < 0) break; @@ -3652,9 +3657,12 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) struct dnode_of_data dn; pgoff_t end_offset, count; + f2fs_lock_op(sbi); + set_new_dnode(&dn, inode, NULL, NULL, 0); ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); if (ret) { + f2fs_unlock_op(sbi); if (ret == -ENOENT) { page_idx = f2fs_get_next_page_offset(&dn, page_idx); @@ -3672,6 +3680,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) f2fs_put_dnode(&dn); + f2fs_unlock_op(sbi); + if (ret < 0) break; -- 2.43.0