Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sanan Hasanov" <sanan.hasanou@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scsi: target: rd: Don't invoke the OOM killer for ramdisk pages
Date: Thu, 08 Oct 2026 22:47:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-164639@kernel.org> (raw)
In-Reply-To: <20261008223712.49827-3-sanan.hasanou@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] target: rd: memory leak in rd_build_prot_space() on allocation failure
--

commit 08e2848928f98cb3a6b575947cf8d271014c318f
Author: Sanan Hasanov <sanan.hasanov@ucf.edu>
Subject: scsi: target: rd: Don't invoke the OOM killer for ramdisk pages

This commit replaces the default memory allocation flags for ramdisk backing
pages with GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN to avoid invoking
the OOM killer. The pages are requested via alloc_pages() in
rd_allocate_sgl_table().

> diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
> index 97c63b12266fb..46698300e2063 100644
> --- a/drivers/target/target_core_rd.c
> +++ b/drivers/target/target_core_rd.c
> @@ -150,7 +150,8 @@ static int rd_allocate_sgl_table(struct rd_dev *rd_dev, struct rd_dev_sg_table *
>  						- 1;
>  
>  		for (j = 0; j < sg_per_table; j++) {
> -			pg = alloc_pages(GFP_KERNEL, 0);
> +			pg = alloc_pages(GFP_KERNEL | __GFP_RETRY_MAYFAIL |
> +					 __GFP_NOWARN, 0);
>  			if (!pg) {

[Severity: Medium]
Can this new failure path cause a regression by leaking memory in
rd_build_prot_space()?

Since this allocation uses __GFP_RETRY_MAYFAIL, it can now fail and return
-ENOMEM. When this occurs, rd_build_prot_space() propagates the error
without cleaning up the partially populated array:

drivers/target/target_core_rd.c:rd_build_prot_space() {
    ...
	rd_dev->sg_prot_array = sg_table;
	rd_dev->sg_prot_count = sg_tables;

	rc = rd_allocate_sgl_table(rd_dev, sg_table, total_sg_needed, 0xff);
	if (rc)
		return rc;
    ...
}

This propagates the error up to the configfs handler:

drivers/target/target_core_configfs.c:pi_prot_type_store() {
    ...
		ret = dev->transport->init_prot(dev);
		if (ret) {
			da->pi_prot_type = old_prot;
			da->pi_prot_verify = (bool) da->pi_prot_type;
			return ret;
		}
    ...
}

The configfs handler restores state and returns without explicitly calling
dev->transport->free_prot(dev) to clean up the backend.

This leaves the partially populated scatterlists and pages permanently
dangling in rd_dev->sg_prot_array. If the user retries enabling the
protection type, rd_build_prot_space() unconditionally overwrites the
rd_dev->sg_prot_array pointer with a new allocation, permanently leaking
the previously allocated memory resources.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008223712.49827-1-sanan.hasanou@gmail.com?part=2

      reply	other threads:[~2026-10-08 22:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 22:37 [PATCH v2 0/2] scsi: target: rd: Fix oversized ramdisk allocations Sanan Hasanov
2026-10-08 22:37 ` [PATCH v2 1/2] scsi: target: rd: Fix oversized sg table array allocation Sanan Hasanov
2026-10-08 22:50   ` sashiko-bot
2026-10-08 22:37 ` [PATCH v2 2/2] scsi: target: rd: Don't invoke the OOM killer for ramdisk pages Sanan Hasanov
2026-10-08 22:47   ` sashiko-bot [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=sashiko-outbox-164639@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sanan.hasanou@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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