cxl/region: Validate partition index before array access
PATCH v2 1/1 cxl/region: Validate partition index before array access
From: Koba Ko <[email protected]>
construct_region() reads cxled->part and uses it to index cxlds->part[] without checking for a negative value. If the partition was never resolved, part remains at its initial value of -1, causing an out-of-bounds array access.
Add a guard to return -EBUSY when part is negative.
--- drivers/cxl/core/region.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/cxl/core/region.c +3 -0
@@ -3712,6 +3712,9 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,int rc, part =READ_ONCE (cxled->part);struct cxl_region *cxlr; +if (part <0 ) +return ERR_PTR (-EBUSY ); + do { cxlr = __create_region(cxlrd, cxlds->part[part].mode, atomic_read(&cxlrd->region_id),
Signature · 1 line
2.43.0
Alison Schofield
maintainerQuoted 10 lines · KobaK
From: Koba Ko <[email protected]>
construct_region()readscxled->partand uses it to index cxlds->part[] without checking for a negative value. If the partition was never resolved, part remains at its initial value of -1, causing an out-of-bounds array access.Add a guard to return
-EBUSYwhen part is negative.Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")
The above tag added the check for part < 0 in construct_region(), so that's not the fixes tag. Like I wrote in v1, I don't see the obvious tag that deleted that check, else I'd just tell you.
Quoted 2 lines
Signed-off-by Koba Ko <[email protected]>---
Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentary
Quoted 21 lines
drivers/cxl/core/region.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cxl/core/region.c +3
-0@@ -3712,6 +3712,9 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,int rc, part =READ_ONCE (cxled->part);struct cxl_region *cxlr; +if (part <0 ) +return ERR_PTR (-EBUSY ); + do { cxlr = __create_region(cxlrd, cxlds->part[part].mode, atomic_read(&cxlrd->region_id),Signature · 1 line
2.43.0
Quoted 5 lines · Alison Schofield
Quoted 1 line
Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")The above tag added the check for part < 0 in
construct_region(), so that's not the fixes tag. Like I wrote in v1, I don't see the obvious tag that deleted that check, else I'd just tell you.
The check was lost during a merge resolution, not by any single non-merge commit. How about dropping the Fixes tag entirely and explaining in the body instead?
Quoted 5 lines
Quoted 2 lines
Signed-off-by Koba Ko <[email protected]>---
Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentary
Sorry, missed it. Will add in v3.
- Koba
Alison Schofield
maintainerQuoted 10 lines · KobaK
Quoted 5 lines · Alison Schofield
Quoted 1 line
Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")The above tag added the check for part < 0 in
construct_region(), so that's not the fixes tag. Like I wrote in v1, I don't see the obvious tag that deleted that check, else I'd just tell you.The check was lost during a merge resolution, not by any single non-merge commit. How about dropping the Fixes tag entirely and explaining in the body instead?
Appreciate your follow-up Koba but a v3 is needless churn at this point. DaveJ can fix up or drop the tag upon merging.
Note to DaveJ: see the v1 thread.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Signed-off-by Koba Ko <[email protected]>---
Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentarySorry, missed it. Will add in v3.
No need to v3. Just a note for next time.
Quoted 2 lines
- Koba
Quoted 8 lines · Alison Schofield
Quoted 7 lines · KobaK
Quoted 5 lines · Alison Schofield
Quoted 1 line
Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")The above tag added the check for part < 0 in
construct_region(), so that's not the fixes tag. Like I wrote in v1, I don't see the obvious tag that deleted that check, else I'd just tell you.
Quoted 9 lines
Quoted 3 lines
The check was lost during a merge resolution, not by any single non-merge commit. How about dropping the Fixes tag entirely and explaining in the body instead?
Appreciate your follow-up Koba but a v3 is needless churn at this point. DaveJ can fix up or drop the tag upon merging.
Note to DaveJ: see the v1 thread.
Quoted 14 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Signed-off-by Koba Ko <[email protected]>---
Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentarySorry, missed it. Will add in v3.
No need to v3. Just a note for next time.
Quoted 2 lines
- Koba
Quoted 11 lines · KobaK
From: Koba Ko <[email protected]>
construct_region()readscxled->partand uses it to index cxlds->part[] without checking for a negative value. If the partition was never resolved, part remains at its initial value of -1, causing an out-of-bounds array access.Add a guard to return
-EBUSYwhen part is negative.Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")Signed-off-by Koba Ko <[email protected]>
Applied to cxl/nextabb3c0de1190
Quoted 18 lines
--- drivers/cxl/core/region.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cxl/core/region.c +3
-0@@ -3712,6 +3712,9 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,int rc, part =READ_ONCE (cxled->part);struct cxl_region *cxlr; +if (part <0 ) +return ERR_PTR (-EBUSY ); + do { cxlr = __create_region(cxlrd, cxlds->part[part].mode, atomic_read(&cxlrd->region_id),