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 v3 2/3] scsi: target: rd: Release protection space on allocation failure
Date: Thu, 8 Oct 2026 19:54:08 -0400 [thread overview]
Message-ID: <20261008235411.56641-3-sanan.hasanou@gmail.com> (raw)
In-Reply-To: <20261008235411.56641-1-sanan.hasanou@gmail.com>
From: Sanan Hasanov <sanan.hasanov@ucf.edu>
When rd_allocate_sgl_table() fails, rd_build_prot_space() returns the
error but leaves the partially populated sg_prot_array in place.
pi_prot_type_store() then restores the previous protection type without
calling ->free_prot(), so the pages and scatterlists allocated so far
stay attached to the device. If the user writes pi_prot_type again,
rd_build_prot_space() overwrites sg_prot_array and the earlier
allocation is leaked.
Release the protection space before returning the error, as
rd_configure_device() already does for the data space.
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 | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 97c63b122..b73bdd733 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -263,8 +263,10 @@ static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block
rd_dev->sg_prot_count = sg_tables;
rc = rd_allocate_sgl_table(rd_dev, sg_table, total_sg_needed, 0xff);
- if (rc)
+ if (rc) {
+ rd_release_prot_space(rd_dev);
return rc;
+ }
pr_debug("CORE_RD[%u] - Built Ramdisk Device ID: %u prot space of"
" %u pages in %u tables\n", rd_dev->rd_host->rd_host_id,
--
2.48.1
next prev parent reply other threads:[~2026-10-08 23:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 23:54 [PATCH v3 0/3] scsi: target: rd: Fix oversized ramdisk allocations Sanan Hasanov
2026-10-08 23:54 ` [PATCH v3 1/3] scsi: target: rd: Fix oversized sg table array allocation Sanan Hasanov
2026-10-08 23:54 ` Sanan Hasanov [this message]
2026-10-08 23:54 ` [PATCH v3 3/3] scsi: target: rd: Don't invoke the OOM killer for ramdisk pages 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=20261008235411.56641-3-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®