linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ritesh Harjani <riteshh@linux.ibm.com>
To: linux-ext4@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>, "Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Harshad Shirwadkar <harshadshirwadkar@gmail.com>,
	linux-fsdevel@vger.kernel.org,
	Ritesh Harjani <riteshh@linux.ibm.com>
Subject: [PATCHv2 8/9] ext4: Add strict range checks while freeing blocks
Date: Wed, 16 Feb 2022 12:32:50 +0530	[thread overview]
Message-ID: <ddd9143d064774e32d6364a99667817c6e8bfdc0.1644992610.git.riteshh@linux.ibm.com> (raw)
In-Reply-To: <cover.1644992609.git.riteshh@linux.ibm.com>

Currently ext4_mb_clear_bb() & ext4_group_add_blocks() only checks
whether the given block ranges (which is to be freed) belongs to any FS
metadata blocks or not, of the block's respective block group.
But to detect any FS error early, it is better to add more strict
checkings in those functions which checks whether the given blocks
belongs to any critical FS metadata or not within system-zone.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/mballoc.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index bb3cfcd545ce..0a95bdb1e07b 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -5930,13 +5930,7 @@ static void ext4_mb_clear_bb(handle_t *handle, struct inode *inode,
 		goto error_return;
 	}
 
-	if (in_range(ext4_block_bitmap(sb, gdp), block, count) ||
-	    in_range(ext4_inode_bitmap(sb, gdp), block, count) ||
-	    in_range(block, ext4_inode_table(sb, gdp),
-		     sbi->s_itb_per_group) ||
-	    in_range(block + count - 1, ext4_inode_table(sb, gdp),
-		     sbi->s_itb_per_group)) {
-
+	if (!ext4_inode_block_valid(inode, block, count)) {
 		ext4_error(sb, "Freeing blocks in system zone - "
 			   "Block = %llu, count = %lu", block, count);
 		/* err = 0. ext4_std_error should be a no op */
@@ -6007,7 +6001,7 @@ static void ext4_mb_clear_bb(handle_t *handle, struct inode *inode,
 						 NULL);
 			if (err && err != -EOPNOTSUPP)
 				ext4_msg(sb, KERN_WARNING, "discard request in"
-					 " group:%d block:%d count:%lu failed"
+					 " group:%u block:%d count:%lu failed"
 					 " with %d", block_group, bit, count,
 					 err);
 		} else
@@ -6220,11 +6214,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
 		goto error_return;
 	}
 
-	if (in_range(ext4_block_bitmap(sb, desc), block, count) ||
-	    in_range(ext4_inode_bitmap(sb, desc), block, count) ||
-	    in_range(block, ext4_inode_table(sb, desc), sbi->s_itb_per_group) ||
-	    in_range(block + count - 1, ext4_inode_table(sb, desc),
-		     sbi->s_itb_per_group)) {
+	if (!ext4_sb_block_valid(sb, NULL, block, count)) {
 		ext4_error(sb, "Adding blocks in system zones - "
 			   "Block = %llu, count = %lu",
 			   block, count);
-- 
2.31.1


  parent reply	other threads:[~2022-02-16  7:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16  7:02 [PATCHv2 0/9] ext4: fast_commit fixes, stricter block checking & cleanups Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 1/9] ext4: Correct cluster len and clusters changed accounting in ext4_mb_mark_bb Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 2/9] ext4: Fixes ext4_mb_mark_bb() with flex_bg with fast_commit Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 3/9] ext4: Refactor ext4_free_blocks() to pull out ext4_mb_clear_bb() Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 4/9] ext4: Use in_range() for range checking in ext4_fc_replay_check_excluded Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 5/9] ext4: Rename ext4_set_bits to mb_set_bits Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 6/9] ext4: No need to test for block bitmap bits in ext4_mb_mark_bb() Ritesh Harjani
2022-02-16  7:02 ` [PATCHv2 7/9] ext4: Add ext4_sb_block_valid() refactored out of ext4_inode_block_valid() Ritesh Harjani
2022-02-16  7:02 ` Ritesh Harjani [this message]
2022-02-16  7:02 ` [PATCHv2 9/9] ext4: Add extra check in ext4_mb_mark_bb() to prevent against possible corruption Ritesh Harjani
2022-03-03  0:41 ` [PATCHv2 0/9] ext4: fast_commit fixes, stricter block checking & cleanups Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ddd9143d064774e32d6364a99667817c6e8bfdc0.1644992610.git.riteshh@linux.ibm.com \
    --to=riteshh@linux.ibm.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=harshadshirwadkar@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).