* [PATCH] Replace kmalloc_array() with kcalloc()
2025-02-02 16:54 ` Markus Elfring
@ 2025-02-02 21:21 ` Jiasheng Jiang
2025-02-02 21:29 ` [PATCH] scsi: qedf: Add check for bdt_info Jiasheng Jiang
` (2 subsequent siblings)
3 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-02 21:21 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH] scsi: qedf: Add check for bdt_info
2025-02-02 16:54 ` Markus Elfring
2025-02-02 21:21 ` [PATCH] Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-02 21:29 ` Jiasheng Jiang
2025-02-02 21:32 ` [PATCH] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-02 21:33 ` [PATCH v2] scsi: qedf: Use kcalloc() and add " Jiasheng Jiang
3 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-02 21:29 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap
Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
drivers/scsi/qedf/qedf_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..cab16a3e2a30 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
- if (bdt_info->bd_tbl) {
+ if (bdt_info && bdt_info->bd_tbl) {
dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
bdt_info->bd_tbl = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-02 16:54 ` Markus Elfring
2025-02-02 21:21 ` [PATCH] Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-02 21:29 ` [PATCH] scsi: qedf: Add check for bdt_info Jiasheng Jiang
@ 2025-02-02 21:32 ` Jiasheng Jiang
2025-02-03 7:20 ` [PATCH v3?] " Markus Elfring
2025-02-02 21:33 ` [PATCH v2] scsi: qedf: Use kcalloc() and add " Jiasheng Jiang
3 siblings, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-02 21:32 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-02 21:32 ` [PATCH] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-03 7:20 ` Markus Elfring
2025-02-04 2:51 ` [PATCH v3] " Jiasheng Jiang
2025-02-04 2:52 ` [PATCH v3?] " Jiasheng Jiang
0 siblings, 2 replies; 33+ messages in thread
From: Markus Elfring @ 2025-02-03 7:20 UTC (permalink / raw)
To: Jiasheng Jiang, linux-scsi, GR-QLogic-Storage-Upstream,
James Bottomley, Javed Hasan, Martin K. Petersen, Saurav Kashyap
Cc: LKML, Arun Easi, Bart Van Assche, Manish Rangankar, Nilesh Javali
> Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
> used/freed.…
> ---
> drivers/scsi/qedf/qedf_io.c | 4 +---
…
Will you become more familiar with patch version descriptions?
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13#n310
Regards,
Markus
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-03 7:20 ` [PATCH v3?] " Markus Elfring
@ 2025-02-04 2:51 ` Jiasheng Jiang
2025-02-04 2:52 ` [PATCH v3?] " Jiasheng Jiang
1 sibling, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-04 2:51 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v4.11+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v2 -> v3:
1. Remove the check for bdt_info.
v1 -> v2:
1. Replace kzalloc() with kcalloc().
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-03 7:20 ` [PATCH v3?] " Markus Elfring
2025-02-04 2:51 ` [PATCH v3] " Jiasheng Jiang
@ 2025-02-04 2:52 ` Jiasheng Jiang
2025-02-04 8:05 ` [v3?] " Markus Elfring
1 sibling, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-04 2:52 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-scsi, GR-QLogic-Storage-Upstream, James Bottomley,
Javed Hasan, Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
Hi Markus,
On Mon, Feb 3, 2025 at 2:20 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
> > used/freed.…
> > ---
> > drivers/scsi/qedf/qedf_io.c | 4 +---
> …
>
> Will you become more familiar with patch version descriptions?
> https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13#n310
>
> Regards,
> Markus
Thanks, I have submitted a v3 and added the changelog.
-Jiasheng
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-04 2:52 ` [PATCH v3?] " Jiasheng Jiang
@ 2025-02-04 8:05 ` Markus Elfring
2025-02-05 1:07 ` [PATCH v3 1/2] " Jiasheng Jiang
` (2 more replies)
0 siblings, 3 replies; 33+ messages in thread
From: Markus Elfring @ 2025-02-04 8:05 UTC (permalink / raw)
To: Jiasheng Jiang, linux-scsi
Cc: GR-QLogic-Storage-Upstream, James Bottomley, Javed Hasan,
Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
> Thanks, I have submitted a v3 and added the changelog.
Are you going to improve your version management?
Would a small patch series have been helpful to avoid any confusion here?
Regards,
Markus
^ permalink raw reply [flat|nested] 33+ messages in thread* [PATCH v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-04 8:05 ` [v3?] " Markus Elfring
@ 2025-02-05 1:07 ` Jiasheng Jiang
2025-02-05 1:07 ` [PATCH v3 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-05 1:08 ` [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-05 2:01 ` [PATCH RESEND v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2 siblings, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-05 1:07 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v2 -> v3:
1. Remove the check for bdt_info.
v1 -> v2:
1. Replace kzalloc() with kcalloc().
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH v3 2/2] scsi: qedf: Add check for bdt_info
2025-02-05 1:07 ` [PATCH v3 1/2] " Jiasheng Jiang
@ 2025-02-05 1:07 ` Jiasheng Jiang
0 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-05 1:07 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v2 -> v3:
1. No change.
v1 -> v2:
1. No change.
---
drivers/scsi/qedf/qedf_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index d52057b97a4f..1ed0ee4f8dde 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
- if (bdt_info->bd_tbl) {
+ if (bdt_info && bdt_info->bd_tbl) {
dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
bdt_info->bd_tbl = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-04 8:05 ` [v3?] " Markus Elfring
2025-02-05 1:07 ` [PATCH v3 1/2] " Jiasheng Jiang
@ 2025-02-05 1:08 ` Jiasheng Jiang
2025-02-05 8:11 ` Markus Elfring
2025-02-05 2:01 ` [PATCH RESEND v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2 siblings, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-05 1:08 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-scsi, GR-QLogic-Storage-Upstream, James Bottomley,
Javed Hasan, Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
Hi Markus,
On Tue, Feb 4, 2025 at 3:05 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > Thanks, I have submitted a v3 and added the changelog.
> Are you going to improve your version management?
> Would a small patch series have been helpful to avoid any confusion here?
>
> Regards,
> Markus
Thanks, I have submitted the patch series.
-Jiasheng
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-05 1:08 ` [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-05 8:11 ` Markus Elfring
2025-02-06 5:12 ` Jiasheng Jiang
2025-02-06 5:25 ` [PATCH 0/2] scsi: qedf: Replace alloction API and add null check Jiasheng Jiang
0 siblings, 2 replies; 33+ messages in thread
From: Markus Elfring @ 2025-02-05 8:11 UTC (permalink / raw)
To: Jiasheng Jiang, linux-scsi
Cc: GR-QLogic-Storage-Upstream, James Bottomley, Javed Hasan,
Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
> Thanks, I have submitted the patch series.
* Would a cover letter have been helpful?
* Why did you find a “RESEND” relevant already?
* Is there a need to increase version numbers?
Regards,
Markus
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-05 8:11 ` Markus Elfring
@ 2025-02-06 5:12 ` Jiasheng Jiang
2025-02-06 12:16 ` Markus Elfring
2025-02-06 5:25 ` [PATCH 0/2] scsi: qedf: Replace alloction API and add null check Jiasheng Jiang
1 sibling, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-06 5:12 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-scsi, GR-QLogic-Storage-Upstream, James Bottomley,
Javed Hasan, Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
Hi Markus,
On Wed, Feb 5, 2025 at 3:12 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > Thanks, I have submitted the patch series.
> * Would a cover letter have been helpful?
Okay, I will resubmit the patech series with a cover letter.
>
> * Why did you find a “RESEND” relevant already?
>
My previous patch missed "Cc: stable", so I resend it.
> * Is there a need to increase version numbers?
Okay, I will keep v2.
-Jiasheng
>
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-06 5:12 ` Jiasheng Jiang
@ 2025-02-06 12:16 ` Markus Elfring
0 siblings, 0 replies; 33+ messages in thread
From: Markus Elfring @ 2025-02-06 12:16 UTC (permalink / raw)
To: Jiasheng Jiang, linux-scsi
Cc: GR-QLogic-Storage-Upstream, James Bottomley, Javed Hasan,
Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
>> * Is there a need to increase version numbers?
>
> Okay, I will keep v2.
I hope that remaining communication difficulties will be resolved
in other directions.
Are you still looking for better guidance?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/researcher-guidelines.rst?h=v6.13#n5
Regards,
Markus
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 0/2] scsi: qedf: Replace alloction API and add null check
2025-02-05 8:11 ` Markus Elfring
2025-02-06 5:12 ` Jiasheng Jiang
@ 2025-02-06 5:25 ` Jiasheng Jiang
2025-02-06 5:25 ` [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
` (2 more replies)
1 sibling, 3 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-06 5:25 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap
This patch series improves memory safety in the qedf SCSI driver by:
1. Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
2. Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
### Changelog:
#### v2:
- Replace kzalloc() with kcalloc().
Jiasheng Jiang (2):
scsi: qedf: Replace kmalloc_array() with kcalloc()
scsi: qedf: Add check for bdt_info
drivers/scsi/qedf/qedf_io.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 33+ messages in thread* [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-06 5:25 ` [PATCH 0/2] scsi: qedf: Replace alloction API and add null check Jiasheng Jiang
@ 2025-02-06 5:25 ` Jiasheng Jiang
2025-02-06 5:36 ` Greg KH
2025-02-06 5:25 ` [PATCH 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-06 11:56 ` [PATCH v5? 0/2] scsi: qedf: Replace alloction API and add null check Markus Elfring
2 siblings, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-06 5:25 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-06 5:25 ` [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-06 5:36 ` Greg KH
2025-02-06 5:38 ` Greg KH
0 siblings, 1 reply; 33+ messages in thread
From: Greg KH @ 2025-02-06 5:36 UTC (permalink / raw)
To: Jiasheng Jiang
Cc: markus.elfring, GR-QLogic-Storage-Upstream, James.Bottomley,
arun.easi, bvanassche, jhasan, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
On Thu, Feb 06, 2025 at 05:25:22AM +0000, Jiasheng Jiang wrote:
> Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
> used/freed.
Used/freed where?
>
> Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
> Cc: <stable@vger.kernel.org> # v5.10+
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
> drivers/scsi/qedf/qedf_io.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
> index fcfc3bed02c6..d52057b97a4f 100644
> --- a/drivers/scsi/qedf/qedf_io.c
> +++ b/drivers/scsi/qedf/qedf_io.c
> @@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
> }
>
> /* Allocate pool of io_bdts - one for each qedf_ioreq */
> - cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
> - GFP_KERNEL);
> -
> + cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
This is just an array that is then properly all initialized a few lines
below this.
So why does this need to be zeroed out at all?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 33+ messages in thread* Re: [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-06 5:36 ` Greg KH
@ 2025-02-06 5:38 ` Greg KH
2025-02-06 19:19 ` [PATCH v2 " Jiasheng Jiang
0 siblings, 1 reply; 33+ messages in thread
From: Greg KH @ 2025-02-06 5:38 UTC (permalink / raw)
To: Jiasheng Jiang
Cc: markus.elfring, GR-QLogic-Storage-Upstream, James.Bottomley,
arun.easi, bvanassche, jhasan, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
On Thu, Feb 06, 2025 at 06:36:58AM +0100, Greg KH wrote:
> On Thu, Feb 06, 2025 at 05:25:22AM +0000, Jiasheng Jiang wrote:
> > Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
> > used/freed.
>
> Used/freed where?
>
> >
> > Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
> > Cc: <stable@vger.kernel.org> # v5.10+
> > Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> > ---
> > drivers/scsi/qedf/qedf_io.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
> > index fcfc3bed02c6..d52057b97a4f 100644
> > --- a/drivers/scsi/qedf/qedf_io.c
> > +++ b/drivers/scsi/qedf/qedf_io.c
> > @@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
> > }
> >
> > /* Allocate pool of io_bdts - one for each qedf_ioreq */
> > - cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
> > - GFP_KERNEL);
> > -
> > + cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
>
> This is just an array that is then properly all initialized a few lines
> below this.
>
> So why does this need to be zeroed out at all?
Oh, I think I figured it out, but your text for the changelog is wrong,
and needs to be fixed to properly describe what is going on here.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 33+ messages in thread* [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-06 5:38 ` Greg KH
@ 2025-02-06 19:19 ` Jiasheng Jiang
2025-02-06 19:20 ` [PATCH v2 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-07 15:09 ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Greg KH
0 siblings, 2 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-06 19:19 UTC (permalink / raw)
To: gregkh
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, markus.elfring, martin.petersen, nilesh.javali,
skashyap, stable
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changlog:
v1 -> v2:
1. Replace kzalloc() with kcalloc() to not reintroduce the possibility of multiplication overflow.
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH v2 2/2] scsi: qedf: Add check for bdt_info
2025-02-06 19:19 ` [PATCH v2 " Jiasheng Jiang
@ 2025-02-06 19:20 ` Jiasheng Jiang
2025-02-07 15:09 ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Greg KH
1 sibling, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-06 19:20 UTC (permalink / raw)
To: gregkh
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, markus.elfring, martin.petersen, nilesh.javali,
skashyap, stable
Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v1 -> v2:
1. No change.
---
drivers/scsi/qedf/qedf_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index d52057b97a4f..1ed0ee4f8dde 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
- if (bdt_info->bd_tbl) {
+ if (bdt_info && bdt_info->bd_tbl) {
dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
bdt_info->bd_tbl = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-06 19:19 ` [PATCH v2 " Jiasheng Jiang
2025-02-06 19:20 ` [PATCH v2 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
@ 2025-02-07 15:09 ` Greg KH
2025-02-07 15:45 ` [PATCH v3 " Jiasheng Jiang
2025-02-07 15:46 ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
1 sibling, 2 replies; 33+ messages in thread
From: Greg KH @ 2025-02-07 15:09 UTC (permalink / raw)
To: Jiasheng Jiang
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, linux-kernel, linux-scsi, manish.rangankar,
markus.elfring, martin.petersen, nilesh.javali, skashyap, stable
On Thu, Feb 06, 2025 at 07:19:59PM +0000, Jiasheng Jiang wrote:
> Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
> used/freed.
"Potentially" being freed. It will not be used. And this is only for
an error path that obviously no one has hit before.
Please explain this much better.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-07 15:09 ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Greg KH
@ 2025-02-07 15:45 ` Jiasheng Jiang
2025-02-07 15:45 ` [PATCH v3 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-07 15:46 ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
1 sibling, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-07 15:45 UTC (permalink / raw)
To: gregkh
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, markus.elfring, martin.petersen, nilesh.javali,
skashyap, stable
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
potentially used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changlog:
v2 -> v3:
1. Add "potentially" in the commit message to explain this much better.
v1 -> v2:
1. Replace kzalloc() with kcalloc() to not reintroduce the possibility of multiplication overflow.
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH v3 2/2] scsi: qedf: Add check for bdt_info
2025-02-07 15:45 ` [PATCH v3 " Jiasheng Jiang
@ 2025-02-07 15:45 ` Jiasheng Jiang
0 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-07 15:45 UTC (permalink / raw)
To: gregkh
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, markus.elfring, martin.petersen, nilesh.javali,
skashyap, stable
Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v2 -> v3:
1. No change.
v1 -> v2:
1. No change.
---
drivers/scsi/qedf/qedf_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index d52057b97a4f..1ed0ee4f8dde 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
- if (bdt_info->bd_tbl) {
+ if (bdt_info && bdt_info->bd_tbl) {
dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
bdt_info->bd_tbl = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-07 15:09 ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Greg KH
2025-02-07 15:45 ` [PATCH v3 " Jiasheng Jiang
@ 2025-02-07 15:46 ` Jiasheng Jiang
1 sibling, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-07 15:46 UTC (permalink / raw)
To: Greg KH
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, linux-kernel, linux-scsi, manish.rangankar,
markus.elfring, martin.petersen, nilesh.javali, skashyap, stable
Hi Greg,
On Fri, Feb 7, 2025 at 10:10 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Feb 06, 2025 at 07:19:59PM +0000, Jiasheng Jiang wrote:
> > Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
> > used/freed.
>
> "Potentially" being freed. It will not be used. And this is only for
> an error path that obviously no one has hit before.
>
> Please explain this much better.
>
> thanks,
>
> greg k-h
Thanks, I have submitted a v3 and added "potentially" in the commit message.
-Jiasheng
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 2/2] scsi: qedf: Add check for bdt_info
2025-02-06 5:25 ` [PATCH 0/2] scsi: qedf: Replace alloction API and add null check Jiasheng Jiang
2025-02-06 5:25 ` [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-06 5:25 ` Jiasheng Jiang
2025-02-06 11:56 ` [PATCH v5? 0/2] scsi: qedf: Replace alloction API and add null check Markus Elfring
2 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-06 5:25 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
drivers/scsi/qedf/qedf_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index d52057b97a4f..1ed0ee4f8dde 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
- if (bdt_info->bd_tbl) {
+ if (bdt_info && bdt_info->bd_tbl) {
dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
bdt_info->bd_tbl = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [PATCH v5? 0/2] scsi: qedf: Replace alloction API and add null check
2025-02-06 5:25 ` [PATCH 0/2] scsi: qedf: Replace alloction API and add null check Jiasheng Jiang
2025-02-06 5:25 ` [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-06 5:25 ` [PATCH 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
@ 2025-02-06 11:56 ` Markus Elfring
2 siblings, 0 replies; 33+ messages in thread
From: Markus Elfring @ 2025-02-06 11:56 UTC (permalink / raw)
To: Jiasheng Jiang, linux-scsi
Cc: GR-QLogic-Storage-Upstream, James Bottomley, Javed Hasan,
Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
…
> ### Changelog:
> #### v2:
…
Why did you overlook to increment version numbers once more?
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13#n605
Regards,
Markus
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH RESEND v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
2025-02-04 8:05 ` [v3?] " Markus Elfring
2025-02-05 1:07 ` [PATCH v3 1/2] " Jiasheng Jiang
2025-02-05 1:08 ` [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-05 2:01 ` Jiasheng Jiang
2025-02-05 2:01 ` [PATCH RESEND v3 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2 siblings, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-05 2:01 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being
used/freed.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v2 -> v3:
1. Remove the check for bdt_info.
v1 -> v2:
1. Replace kzalloc() with kcalloc().
---
drivers/scsi/qedf/qedf_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..d52057b97a4f 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
}
/* Allocate pool of io_bdts - one for each qedf_ioreq */
- cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
- GFP_KERNEL);
-
+ cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(*cmgr->io_bdt_pool), GFP_KERNEL);
if (!cmgr->io_bdt_pool) {
QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
goto mem_err;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread* [PATCH RESEND v3 2/2] scsi: qedf: Add check for bdt_info
2025-02-05 2:01 ` [PATCH RESEND v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-05 2:01 ` Jiasheng Jiang
0 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-05 2:01 UTC (permalink / raw)
To: markus.elfring
Cc: GR-QLogic-Storage-Upstream, James.Bottomley, arun.easi,
bvanassche, jhasan, jiashengjiangcool, linux-kernel, linux-scsi,
manish.rangankar, martin.petersen, nilesh.javali, skashyap,
stable
Add a check for "bdt_info". Otherwise, if one of the allocations
for "cmgr->io_bdt_pool[i]" fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.
Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
Changelog:
v2 -> v3:
1. No change.
v1 -> v2:
1. No change.
---
drivers/scsi/qedf/qedf_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index d52057b97a4f..1ed0ee4f8dde 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
for (i = 0; i < num_ios; i++) {
bdt_info = cmgr->io_bdt_pool[i];
- if (bdt_info->bd_tbl) {
+ if (bdt_info && bdt_info->bd_tbl) {
dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
bdt_info->bd_tbl = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH v2] scsi: qedf: Use kcalloc() and add check for bdt_info
2025-02-02 16:54 ` Markus Elfring
` (2 preceding siblings ...)
2025-02-02 21:32 ` [PATCH] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
@ 2025-02-02 21:33 ` Jiasheng Jiang
3 siblings, 0 replies; 33+ messages in thread
From: Jiasheng Jiang @ 2025-02-02 21:33 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-scsi, GR-QLogic-Storage-Upstream, James Bottomley,
Javed Hasan, Martin K. Petersen, Saurav Kashyap, LKML, Arun Easi,
Bart Van Assche, Manish Rangankar, Nilesh Javali
Hi Markus,
On Sun, Feb 2, 2025 at 11:54 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> …
> > +++ b/drivers/scsi/qedf/qedf_io.c
> …
> @@ -254,9 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
> }
>
> /* Allocate pool of io_bdts - one for each qedf_ioreq */
> …
> + cmgr->io_bdt_pool = kcalloc(num_ios, sizeof(struct io_bdt *), GFP_KERNEL);
> …
>
> See also:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.13#n941
>
> Regards,
> Markus
Thanks, I have split it into two new patches and fixed the error.
-Jiasheng
^ permalink raw reply [flat|nested] 33+ messages in thread