From: Sanan Hasanov <sanan.hasanou@gmail.com>
To: "Martin K. Petersen" <mkp@kernel.org>
Cc: Sanan Hasanov <sanan.hasanov@ucf.edu>,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+fa495e1497c48a6ed885@syzkaller.appspotmail.com
Subject: [PATCH v4 1/4] scsi: target: rd: Fix oversized sg table array allocation
Date: Thu, 8 Oct 2026 20:35:31 -0400 [thread overview]
Message-ID: <20261009003537.62265-2-sanan.hasanou@gmail.com> (raw)
In-Reply-To: <20261009003537.62265-1-sanan.hasanou@gmail.com>
From: Sanan Hasanov <sanan.hasanov@ucf.edu>
The rd_pages= device parameter is taken from configfs without an upper
bound. rd_build_device_space() uses it to size the sg table array, so a
large value such as INT_MAX makes it attempt a kzalloc() of roughly
64 MiB, which is above the page allocator's maximum order and triggers:
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0x294/0x874
Call trace:
__alloc_frozen_pages_noprof+0x294/0x874 (P)
___kmalloc_large_node+0x64/0xd0
__kmalloc_noprof+0x24/0x54
rd_configure_device+0x74/0xdc
target_configure_device+0xa0/0x1c4
target_dev_enable_store+0x4c/0x5c
configfs_write_iter+0xec/0x124
A ramdisk is backed page-by-page by system memory, so a page count
larger than totalram_pages() can never be satisfied. Reject it with
-EINVAL before allocating anything. NULLIO devices allocate no backing
pages and are not affected.
The array needs 64 bytes per 2048 pages, so even a valid page count
exceeds the 4 MiB maximum order once the ramdisk is larger than 512 GiB.
Allocate the sg table arrays with kvzalloc_objs() so that large arrays
fall back to vmalloc.
Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Reported-by: syzbot+fa495e1497c48a6ed885@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fa495e1497c48a6ed885
Signed-off-by: Sanan Hasanov <sanan.hasanov@ucf.edu>
---
drivers/target/target_core_rd.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 092d9fe0d..97c63b122 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -14,6 +14,7 @@
#include <linux/string.h>
#include <linux/parser.h>
#include <linux/highmem.h>
+#include <linux/mm.h>
#include <linux/timer.h>
#include <linux/scatterlist.h>
#include <linux/slab.h>
@@ -81,7 +82,7 @@ static u32 rd_release_sgl_table(struct rd_dev *rd_dev, struct rd_dev_sg_table *s
kfree(sg);
}
- kfree(sg_table);
+ kvfree(sg_table);
return page_count;
}
@@ -188,10 +189,16 @@ static int rd_build_device_space(struct rd_dev *rd_dev)
if (rd_dev->rd_flags & RDF_NULLIO)
return 0;
+ if (rd_dev->rd_page_count > totalram_pages()) {
+ pr_err("Page count: %u exceeds total RAM pages: %lu for Ramdisk device\n",
+ rd_dev->rd_page_count, totalram_pages());
+ return -EINVAL;
+ }
+
total_sg_needed = rd_dev->rd_page_count;
sg_tables = (total_sg_needed / max_sg_per_table) + 1;
- sg_table = kzalloc_objs(*sg_table, sg_tables);
+ sg_table = kvzalloc_objs(*sg_table, sg_tables);
if (!sg_table)
return -ENOMEM;
@@ -248,7 +255,7 @@ static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block
total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1;
sg_tables = (total_sg_needed / max_sg_per_table) + 1;
- sg_table = kzalloc_objs(*sg_table, sg_tables);
+ sg_table = kvzalloc_objs(*sg_table, sg_tables);
if (!sg_table)
return -ENOMEM;
--
2.48.1
next prev parent reply other threads:[~2026-10-09 0:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 0:35 [PATCH v4 0/4] scsi: target: rd: Fix oversized ramdisk allocations Sanan Hasanov
2026-10-09 0:35 ` Sanan Hasanov [this message]
2026-10-09 0:35 ` [PATCH v4 2/4] scsi: target: rd: Release protection space on allocation failure Sanan Hasanov
2026-10-09 0:35 ` [PATCH v4 3/4] scsi: target: rd: Don't invoke the OOM killer for ramdisk pages Sanan Hasanov
2026-10-09 0:35 ` [PATCH v4 4/4] scsi: target: rd: Avoid 32-bit overflow in protection space size Sanan Hasanov
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=20261009003537.62265-2-sanan.hasanou@gmail.com \
--to=sanan.hasanou@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=sanan.hasanov@ucf.edu \
--cc=syzbot+fa495e1497c48a6ed885@syzkaller.appspotmail.com \
--cc=target-devel@vger.kernel.org \
/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®