linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: Make sanity check in mballoc more strict
@ 2019-03-28 16:41 Jan Kara
  2019-04-06 22:35 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2019-03-28 16:41 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Jan Kara

Sanity check in mb_find_extent() only checked that returned extent does
not extend past blocksize * 8, however it should not extend past
EXT4_CLUSTERS_PER_GROUP(sb). This can happen when clusters_per_group <
blocksize * 8 and the tail of the bitmap is not properly filled by 1s
which happened e.g. when ancient kernels have grown the filesystem.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/mballoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

As a background: We have a customer who has filesystems (created & apparently
resized by 3.0 or older kernels) and which make current kernels eventually barf
with errors but e2fsck says everything is fine.  This patch makes mballoc code
detect issues earlier. I'll send appropriate e2fsck patch shortly.

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 6fb76d408093..8ef5f12bbee2 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1539,7 +1539,7 @@ static int mb_find_extent(struct ext4_buddy *e4b, int block,
 		ex->fe_len += 1 << order;
 	}
 
-	if (ex->fe_start + ex->fe_len > (1 << (e4b->bd_blkbits + 3))) {
+	if (ex->fe_start + ex->fe_len > EXT4_CLUSTERS_PER_GROUP(e4b->bd_sb)) {
 		/* Should never happen! (but apparently sometimes does?!?) */
 		WARN_ON(1);
 		ext4_error(e4b->bd_sb, "corruption or bug in mb_find_extent "
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: Make sanity check in mballoc more strict
  2019-03-28 16:41 [PATCH] ext4: Make sanity check in mballoc more strict Jan Kara
@ 2019-04-06 22:35 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2019-04-06 22:35 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4

On Thu, Mar 28, 2019 at 05:41:17PM +0100, Jan Kara wrote:
> Sanity check in mb_find_extent() only checked that returned extent does
> not extend past blocksize * 8, however it should not extend past
> EXT4_CLUSTERS_PER_GROUP(sb). This can happen when clusters_per_group <
> blocksize * 8 and the tail of the bitmap is not properly filled by 1s
> which happened e.g. when ancient kernels have grown the filesystem.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-07  2:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-28 16:41 [PATCH] ext4: Make sanity check in mballoc more strict Jan Kara
2019-04-06 22:35 ` Theodore Ts'o

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).