From: jackysliu <1972843537@qq.com>
To: skashyap@marvell.com
Cc: jhasan@marvell.com, GR-QLogic-Storage-Upstream@marvell.com,
James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, jackysliu <1972843537@qq.com>
Subject: [PATCH] scsi: qedf: Fix a possible memory leak in qedf_prepare_sb()
Date: Tue, 17 Jun 2025 17:55:31 +0800 [thread overview]
Message-ID: <tencent_3C5078D216712F6F21FC8792FADED59A3D09@qq.com> (raw)
A memory leak vulnerability found in
linux/drivers/scsi/qedf/qedf_main.c , qedf_prepare_sb Function Due to
Missing Resource Cleanup in Error Path.
The qedf_prepare_sb function allocates resources in a loop for
multiple queues. If an allocation fails mid-loop (e.g., kcalloc for
fp->sb_info or qedf_alloc_and_init_sb fails), the error path (goto
err) returns without freeing resources allocated in previous
iterations
Signed-off-by: jackysliu <1972843537@qq.com>
---
drivers/scsi/qedf/qedf_main.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index 6b1ebab36fa3..8767d9de819f 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -2809,7 +2809,17 @@ static int qedf_prepare_sb(struct qedf_ctx *qedf)
sizeof(struct fcoe_cqe);
}
err:
- return 0;
+for (int i = 0; i < id; i++) {
+ fp = &qedf->fp_array[i];
+if (fp->sb_info) {
+ qedf_free_sb(qedf, fp->sb_info);
+kfree(fp->sb_info);
+fp->sb_info = NULL;
+}
+}
+kfree(qedf->fp_array);
+qedf->fp_array = NULL;
+return -ENOMEM;
}
void qedf_process_cqe(struct qedf_ctx *qedf, struct fcoe_cqe *cqe)
next reply other threads:[~2025-06-17 9:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 9:55 jackysliu [this message]
2025-06-23 19:36 ` kernel test robot
2025-06-24 3:16 ` [PATCH] [PATCH] scsi: qedf: fix inconsistent indenting warning Fix below inconsistent indenting smatch warning. New smatch warnings: drivers/scsi/qedf/qedf_main.c:2814 qedf_prepare_sb() warn: inconsistent indenting jackysliu
2025-06-24 3:19 ` [PATCH] scsi: qedf: fix inconsistent indenting warning jackysliu
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=tencent_3C5078D216712F6F21FC8792FADED59A3D09@qq.com \
--to=1972843537@qq.com \
--cc=GR-QLogic-Storage-Upstream@marvell.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=jhasan@marvell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=skashyap@marvell.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
all inboxes | Powered by JetHome®