Skip to contentSkip to conversation

cxl/region: Fix leakage in __construct_region()

PATCH Applied Davidlohr Bueso 5 participants 9 messages Feb 2 – Mar 4 CXL

lore
Share & tools
lore

Davidlohr Bueso

author maintainer
#0 lore raw

PATCH 1/1 cxl/region: Fix leakage in __construct_region()

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

---
 drivers/cxl/core/region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +3 -1
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {
Signature · 1 line
2.39.5
author maintainer
#1 lore raw
Quoted 4 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

Fixes d6602e25819d (cxl/region: Add support to indicate region has extended linear cache)
Quoted 24 lines

---
drivers/cxl/core/region.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +3 -1
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {
Signature · 1 line
2.39.5
maintainer
#3 lore raw
In reply to Davidlohr Bueso
Quoted 14 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

---
 drivers/cxl/core/region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +0 -0
index 96888d87a8df..28d70497283d 100644

drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3801

Quoted 8 lines
drivers/cxl/core/region.c +3 -1
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}

Can sysfs_update_group() be done earlier in __construct_region, before resource is allocated?

Quoted 6 lines
drivers/cxl/core/region.c +0 -0
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {
Signature · 1 line
2.39.5
author maintainer
#4 lore raw
Quoted 17 lines · Alison Schofield
Quoted 16 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

---
 drivers/cxl/core/region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +0 -0
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
Quoted 10 lines

drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3801

Quoted 6 lines
drivers/cxl/core/region.c +3 -1
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}

Can sysfs_update_group() be done earlier in __construct_region, before resource is allocated?

I don't think so, extended_linear_cache_size is part of cxl_region_attrs.

Thanks,
Davidlohr

Reviewed-by on v1 1/1
#5 lore raw
In reply to Davidlohr Bueso
Quoted 15 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

---
 drivers/cxl/core/region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +0 -0
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}

drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3804

Quoted 10 lines
drivers/cxl/core/region.c +3 -1
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {

There is another call to sysfs_update_group() with potential failure after the insert_resource(). Does that need to be handled? Or is the resource turned over to the root decoder at that point?

Assuming it is ok.

Ira

author maintainer
#6 lore raw
Quoted 24 lines · Ira Weiny
Quoted 23 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

---
 drivers/cxl/core/region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +3 -1
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}
 
Quoted 8 lines

drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3804

Quoted 2 lines
drivers/cxl/core/region.c +0 -0
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {

There is another call to sysfs_update_group() with potential failure after the insert_resource(). Does that need to be handled? Or is the resource turned over to the root decoder at that point?

Assuming it is ok.

Yes, the second call failure is after the region param p->res = res so taken care of in cxl_region_iomem_release().

Quoted 1 line

Thanks!

maintainer Applied
#7 lore raw
In reply to Davidlohr Bueso
Quoted 5 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

Applied to cxl/fixes
77b310bb7b5ff8c017524df83292e0242ba89791

Quoted 20 lines
---
 drivers/cxl/core/region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +3 -1
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {
author maintainer
#8 lore raw
In reply to Davidlohr Bueso

ping? Dave, can this be picked up for the next round you send to Linus?

Thanks,
Davidlohr

Quoted 28 lines · Davidlohr Bueso

Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.

---
drivers/cxl/core/region.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +3 -2
index 96888d87a8df..28d70497283d 100644
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr,
 	}
 
 	rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
-	if (rc)
+	if (rc) {
+		kfree(res);
 		return rc;
+	}
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {
--

2.39.5