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 4/4] scsi: target: rd: Avoid 32-bit overflow in protection space size
Date: Thu, 8 Oct 2026 20:35:34 -0400 [thread overview]
Message-ID: <20261009003537.62265-5-sanan.hasanou@gmail.com> (raw)
In-Reply-To: <20261009003537.62265-1-sanan.hasanou@gmail.com>
From: Sanan Hasanov <sanan.hasanov@ucf.edu>
rd_build_prot_space() computes the number of protection pages as
rd_page_count * prot_length / block_size. rd_page_count is a u32 and
prot_length an int, so the multiplication is done in 32 bits and wraps
once rd_page_count reaches 2^29 with 8-byte protection information,
that is for a 2 TiB ramdisk. The protection sg tables are then
allocated much smaller than the device needs. A command whose
protection data starts inside the allocated range but extends past its
end makes sbc_dif_copy_prot() walk off the last scatterlist and
dereference the NULL returned by sg_next().
Do the multiplication in 64 bits. The quotient still fits in a u32
because prot_length is smaller than block_size.
Fixes: d7e8eb5d9216 ("target/rd: Add support for protection SGL setup + release")
Signed-off-by: Sanan Hasanov <sanan.hasanov@ucf.edu>
---
drivers/target/target_core_rd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 2613342be..d7752fd34 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -253,7 +253,8 @@ static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block
* (prot_length/block_size) + pad
* PGSZ canceled each other.
*/
- total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1;
+ total_sg_needed = div_u64((u64)rd_dev->rd_page_count * prot_length,
+ block_size) + 1;
sg_tables = (total_sg_needed / max_sg_per_table) + 1;
sg_table = kvzalloc_objs(*sg_table, sg_tables);
--
2.48.1
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 ` [PATCH v4 1/4] scsi: target: rd: Fix oversized sg table array allocation Sanan Hasanov
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 ` Sanan Hasanov [this message]
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-5-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®