Skip to contentSkip to conversation

cxl/region: Validate partition index before array access

PATCH Applied KobaK 3 participants 6 messages Apr 14 – May 21 CXL

lore
Share & tools
lore

KobaK

author
#0 lore raw

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.

Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")
---
 drivers/cxl/core/region.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cxl/core/region.c +3 -0
index edc267c6cf77..de749b54fd62 100644
@@ -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
maintainer
#1 lore raw
Quoted 10 lines · KobaK

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.

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

---

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
index edc267c6cf77..de749b54fd62 100644
@@ -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
author
#2 lore raw
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

---

Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentary

Sorry, missed it. Will add in v3.

- Koba

maintainer
#3 lore raw
Quoted 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

---

Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentary

Sorry, missed it. Will add in v3.

No need to v3. Just a note for next time.

Quoted 2 lines

- Koba

maintainer Reviewed-by
#4 lore raw
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

---

Need a changelog here.
See https://docs.kernel.org/process/submitting-patches.html#commentary

Sorry, missed it. Will add in v3.

No need to v3. Just a note for next time.

Quoted 2 lines

- Koba

maintainer Applied
#5 lore raw
In reply to KobaK
Quoted 11 lines · KobaK

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.

Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")

Applied to cxl/next
abb3c0de1190

Quoted 18 lines
---
 drivers/cxl/core/region.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cxl/core/region.c +3 -0
index edc267c6cf77..de749b54fd62 100644
@@ -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),