mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Edward Adam Davis <eadavis@qq.com>
To: syzbot+1ad8bac5af24d01e2cbd@syzkaller.appspotmail.com
Cc: adilger.kernel@dilger.ca, jack@suse.cz,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	ojaswin@linux.ibm.com, syzkaller-bugs@googlegroups.com,
	tytso@mit.edu
Subject: [PATCH] ext4: fix divide error in ext4_mb_regular_allocator
Date: Wed, 14 Aug 2024 10:12:00 +0800	[thread overview]
Message-ID: <tencent_42D9D2CB066909BF6EDDAEDB8C8067F3C606@qq.com> (raw)
In-Reply-To: <000000000000b1b164061f96213d@google.com>

Before determining that the goal length is a multiple of the stripe size,
check CR_GOAL_LEN_FAST and CR_BEST_AVAIL_LEN first.

Fixes: 1f6bc02f1848 ("ext4: fallback to complex scan if aligned scan doesn't work")
Reported-and-tested-by: syzbot+1ad8bac5af24d01e2cbd@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1ad8bac5af24d01e2cbd
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 fs/ext4/mballoc.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 9dda9cd68ab2..451f92cde461 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2928,13 +2928,12 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 			if (cr == CR_POWER2_ALIGNED)
 				ext4_mb_simple_scan_group(ac, &e4b);
 			else {
-				bool is_stripe_aligned = sbi->s_stripe &&
+				bool is_stripe_aligned = (cr == CR_GOAL_LEN_FAST ||
+					cr == CR_BEST_AVAIL_LEN) && sbi->s_stripe &&
 					!(ac->ac_g_ex.fe_len %
 					  EXT4_B2C(sbi, sbi->s_stripe));
 
-				if ((cr == CR_GOAL_LEN_FAST ||
-				     cr == CR_BEST_AVAIL_LEN) &&
-				    is_stripe_aligned)
+				if (is_stripe_aligned)
 					ext4_mb_scan_aligned(ac, &e4b);
 
 				if (ac->ac_status == AC_STATUS_CONTINUE)
-- 
2.43.0


  parent reply	other threads:[~2024-08-14  2:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 20:05 [syzbot] [ext4?] " syzbot
2024-08-14  0:35 ` Edward Adam Davis
2024-08-14  1:52   ` syzbot
2024-08-14  2:12 ` Edward Adam Davis [this message]
2024-08-14  4:56   ` [PATCH] ext4: fix " Ojaswin Mujoo
2024-08-15 22:16     ` Ojaswin Mujoo
2024-08-15 23:05       ` [syzbot] [ext4?] " syzbot

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=tencent_42D9D2CB066909BF6EDDAEDB8C8067F3C606@qq.com \
    --to=eadavis@qq.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=syzbot+1ad8bac5af24d01e2cbd@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --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

all inboxes | Powered by JetHome®