scsi: qedf: Use kzalloc() and add check for bdt_info
Subsystems (3)
PATCH 1/1 scsi: qedf: Use kzalloc() and add check for bdt_info
Replace kmalloc_array() with kzalloc() to avoid old (dirty) data being used/freed.
Moreover, 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.
--- drivers/scsi/qedf/qedf_io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/scsi/qedf/qedf_io.c +2 -3
@@ -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 ;
@@ -254,8 +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 =kzalloc (num_ios *sizeof (struct io_bdt *),GFP_KERNEL );if (!cmgr->io_bdt_pool) {QEDF_WARN (&(qedf->dbg_ctx),"Failed to alloc io_bdt_pool.\n" );
Signature · 1 line
2.25.1
drivers/scsi/qedf/qedf_io.c struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf) · line 257
Quoted 3 lines · Jiasheng Jiang
drivers/scsi/qedf/qedf_io.c +1
-2- cmgr->io_bdt_pool =kmalloc_array (num_ios,sizeof (struct io_bdt *), -GFP_KERNEL ); + cmgr->io_bdt_pool =kzalloc (num_ios *sizeof (struct io_bdt *),GFP_KERNEL );
Please do not reintroduce the possibility of multiplication overflow. What is wrong with adding __GFP_ZERO to the second kmalloc_array() argument or with using kcalloc()? From include/linux/slab.h:
#define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
Thanks,
Bart.
PATCH v2 1/1 scsi: qedf: Use kcalloc() and add check for bdt_info
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
Moreover, 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:
v1 -> v2:
1. Replace kzalloc() with kcalloc().
--- drivers/scsi/qedf/qedf_io.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/qedf/qedf_io.c +2 -4
@@ -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 ;
@@ -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 (struct io_bdt *),GFP_KERNEL );if (!cmgr->io_bdt_pool) {QEDF_WARN (&(qedf->dbg_ctx),"Failed to alloc io_bdt_pool.\n" ); goto mem_err;
Signature · 1 line
2.25.1
Re: [PATCH v2] scsi: qedf: Use kcalloc() and add check for bdt_info
Quoted 3 lines
Replace
kmalloc_array()withkcalloc()to avoid old (dirty) data being used/freed.
Moreover, add a check for "bdt_info". Otherwise, if one of the allocations
…
Please provide desired changes as separate update steps.
Regards,
Markus
Re: [PATCH v2] scsi: qedf: Use kcalloc() and add check for bdt_info
In reply to Jiasheng Jiang…
Quoted 1 line
+++
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);
…
Regards,
Markus
PATCH 1/1 Replace kmalloc_array() with kcalloc()
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
--- drivers/scsi/qedf/qedf_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
PATCH 1/1 scsi: qedf: Add check for bdt_info
In reply to Markus ElfringAdd 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.
--- drivers/scsi/qedf/qedf_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qedf/qedf_io.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
PATCH 1/1 scsi: qedf: Replace kmalloc_array() with kcalloc()
In reply to Markus ElfringReplace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
--- drivers/scsi/qedf/qedf_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
Re: [PATCH v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
Quoted 4 lines
Replace
kmalloc_array()withkcalloc()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
PATCH v3 1/1 scsi: qedf: Replace kmalloc_array() with kcalloc()
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
---
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(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
Re: [PATCH v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
In reply to Markus ElfringHi Markus,
Quoted 5 lines · Markus Elfring
Quoted 5 lines
Replace
kmalloc_array()withkcalloc()to avoid old (dirty) data being used/freed.…--- drivers/scsi/qedf/qedf_io.c | 4 +---
Quoted 8 lines
…
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#n310Regards,
Markus
Thanks, I have submitted a v3 and added the changelog.
-Jiasheng
Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
Quoted 1 line
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
PATCH v3 1/2 scsi: qedf: Replace kmalloc_array() with kcalloc()
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
---
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(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
PATCH v3 2/2 scsi: qedf: Add check for bdt_info
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 -> v3:
1. No change.
v1 -> v2:
1. No change.
--- drivers/scsi/qedf/qedf_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qedf/qedf_io.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
In reply to Markus ElfringHi Markus,
Quoted 7 lines · Markus Elfring
Quoted 2 lines
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
Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
Quoted 1 line
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
Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
Hi Markus,
Quoted 3 lines · Markus Elfring
Quoted 2 lines
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.
Quoted 3 lines
* Why did you find a “RESEND” relevant already?
My previous patch missed "Cc: stable", so I resend it.
Quoted 1 line
* Is there a need to increase version numbers?
Okay, I will keep v2.
-Jiasheng
Quoted 4 lines
Regards,
Markus
Re: [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc()
Quoted 3 lines
Quoted 1 line
* 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
cover scsi: qedf: Replace alloction API and add null check
In reply to Markus ElfringThis 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(-)
Signature · 1 line
2.25.1
PATCH 1/2 scsi: qedf: Replace kmalloc_array() with kcalloc()
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
--- drivers/scsi/qedf/qedf_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
Greg KH
maintainerRe: [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
Quoted 2 lines · Jiasheng Jiang
Replace
kmalloc_array()withkcalloc()to avoid old (dirty) data being used/freed.
Used/freed where?
Quoted 13 lines
Fixes 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")Cc <[email protected]> # v5.10+Signed-off-by Jiasheng Jiang <[email protected]>--- drivers/scsi/qedf/qedf_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/scsi/qedf/qedf_io.c +0
-0
drivers/scsi/qedf/qedf_io.c struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf) · line 257
Quoted 7 lines
drivers/scsi/qedf/qedf_io.c +1
-3@@ -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
Greg KH
maintainerRe: [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
Quoted 30 lines · Greg KH
Quoted 2 lines · Jiasheng Jiang
Replace
kmalloc_array()withkcalloc()to avoid old (dirty) data being used/freed.Used/freed where?
Quoted 13 lines
Fixes 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")Cc <[email protected]> # v5.10+Signed-off-by Jiasheng Jiang <[email protected]>--- drivers/scsi/qedf/qedf_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/scsi/qedf/qedf_io.c +0
-0drivers/scsi/qedf/qedf_io.c struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf) · line 257
Quoted 7 lines
drivers/scsi/qedf/qedf_io.c +1
-3@@ -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.
Quoted 1 line
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
PATCH v2 1/2 scsi: qedf: Replace kmalloc_array() with kcalloc()
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
---
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(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 2/2 scsi: qedf: Add check for bdt_info
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:
v1 -> v2:
1. No change.
--- drivers/scsi/qedf/qedf_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qedf/qedf_io.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Greg KH
maintainerRe: [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
In reply to Jiasheng JiangQuoted 2 lines · Jiasheng Jiang
Replace
kmalloc_array()withkcalloc()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
PATCH v3 1/2 scsi: qedf: Replace kmalloc_array() with kcalloc()
Replace kmalloc_array() with kcalloc() to avoid old (dirty) data being potentially used/freed.
---
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(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
PATCH v3 2/2 scsi: qedf: Add check for bdt_info
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 -> v3:
1. No change.
v1 -> v2:
1. No change.
--- drivers/scsi/qedf/qedf_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qedf/qedf_io.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc()
In reply to Greg KHHi Greg,
Quoted 5 lines · Greg KH
Quoted 2 lines · Jiasheng Jiang
Replace
kmalloc_array()withkcalloc()to avoid old (dirty) data being used/freed.
Quoted 8 lines
"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
PATCH 2/2 scsi: qedf: Add check for bdt_info
In reply to Jiasheng JiangAdd 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.
--- drivers/scsi/qedf/qedf_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qedf/qedf_io.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Re: [PATCH v5? 0/2] scsi: qedf: Replace alloction API and add null check
In reply to Jiasheng Jiang…
Quoted 2 lines
### 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
PATCH RESEND v3 1/2 scsi: qedf: Replace kmalloc_array() with kcalloc()
In reply to Markus ElfringReplace kmalloc_array() with kcalloc() to avoid old (dirty) data being used/freed.
---
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(-)
drivers/scsi/qedf/qedf_io.c +1 -3
@@ -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;
Signature · 1 line
2.25.1
PATCH RESEND v3 2/2 scsi: qedf: Add check for bdt_info
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 -> v3:
1. No change.
v1 -> v2:
1. No change.
--- drivers/scsi/qedf/qedf_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qedf/qedf_io.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Re: [PATCH v2] scsi: qedf: Use kcalloc() and add check for bdt_info
In reply to Markus ElfringHi Markus,
Quoted 12 lines · Markus Elfring
…
Quoted 1 line
+++
b/drivers/scsi/qedf/qedf_io.c…
drivers/scsi/qedf/qedf_io.c +1
-0@@ -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 );
Quoted 5 lines
Regards,
Markus
Thanks, I have split it into two new patches and fixed the error.
-Jiasheng