From: Kriish Sharma <kriish.sharma2006@gmail.com>
To: agruenba@redhat.com
Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
linux-kernel-mentees@lists.linux.dev,
Kriish Sharma <kriish.sharma2006@gmail.com>,
syzbot+7567dc5c8aa8f68bde74@syzkaller.appspotmail.com
Subject: [PATCH] gfs2: add bounds check for rd_length in compute_bitstructs()
Date: Thu, 18 Sep 2025 20:48:30 +0000 [thread overview]
Message-ID: <20250918204830.229918-1-kriish.sharma2006@gmail.com> (raw)
compute_bitstructs() allocates an array of gfs2_bitmap structures
using kcalloc(). The function only checked for length == 0 but did not
guard against excessively large length values.
If rd_length is too large, the multiplication inside
kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS) can exceed
KMALLOC_MAX_SIZE. This leads to the allocator calculating an order
greater than MAX_ORDER when calling get_order(), which is invalid.
As a result, __alloc_pages() warns about the bad request.
This patch adds an explicit check that rd_length is not only non-zero
but also within the maximum safe limit for kmalloc_array():
length <= KMALLOC_MAX_SIZE / sizeof(struct gfs2_bitmap)
This ensures that get_order() is only ever called with a valid size,
resulting in an allocation order within MAX_ORDER
Fixes: b9158815de52 ("Merge tag 'char-misc-6.9-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc")
Reported-by: syzbot+7567dc5c8aa8f68bde74@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7567dc5c8aa8f68bde74
Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
---
fs/gfs2/rgrp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 26d6c1eea559..a879e8030568 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -760,7 +760,7 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd)
u32 bytes_left, bytes;
int x;
- if (!length)
+ if (!length || length > KMALLOC_MAX_SIZE / sizeof(struct gfs2_bitmap))
return -EINVAL;
rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS);
--
2.34.1
next reply other threads:[~2025-09-18 20:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 20:48 Kriish Sharma [this message]
2025-09-22 11:34 ` [PATCH] gfs2: add bounds check for rd_length in compute_bitstructs() Andreas Gruenbacher
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=20250918204830.229918-1-kriish.sharma2006@gmail.com \
--to=kriish.sharma2006@gmail.com \
--cc=agruenba@redhat.com \
--cc=david.hunter.linux@gmail.com \
--cc=gfs2@lists.linux.dev \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=syzbot+7567dc5c8aa8f68bde74@syzkaller.appspotmail.com \
/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