Skip to contentSkip to conversation

coretemp: avoid leaving around dangling pointer

PATCH In review Jan Beulich 2 participants 4 messages Sep 23, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coretemp: avoid leaving around dangling pointer

Storing the struct temp_data pointer allocated from create_core_data() before passing the last 'goto exit_free' has the potential of leaving around a pointer to freed memory. As there's no need for the pointer to be stored before calling create_core_attrs(), simply move the storing past that call.

---
 drivers/hwmon/coretemp.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/coretemp.c +2 -1
@@ -609,13 +609,14 @@ static int create_core_data(struct platf
 				  THERM_SHIFT_THRESHOLD1) * 1000;
 	}
 
-	pdata->core_data[attr_no] = tdata;
 
 	/* Create sysfs interfaces */
 	err = create_core_attrs(tdata, &pdev->dev, attr_no);
 	if (err)
 		goto exit_free;
 
+	pdata->core_data[attr_no] = tdata;
+
 	return 0;
 exit_free:
 	kfree(tdata);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Re: [lm-sensors] [PATCH] coretemp: avoid leaving around dangling

Quoted 18 lines · Jan Beulich

Storing the struct temp_data pointer allocated from create_core_data() before passing the last 'goto exit_free' has the potential of leaving around a pointer to freed memory. As there's no need for the pointer to be stored before calling create_core_attrs(), simply move the storing past that call.

---
 drivers/hwmon/coretemp.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/coretemp.c +0 -0
@@ -609,13 +609,14 @@ static int create_core_data(struct platf
 				  THERM_SHIFT_THRESHOLD1) * 1000;
 	}

drivers/hwmon/coretemp.c static int create_core_data(struct platf · line 619

Quoted 10 lines
drivers/hwmon/coretemp.c +2 -1
 
-	pdata->core_data[attr_no] = tdata;
 
 	/* Create sysfs interfaces */
 	err = create_core_attrs(tdata, &pdev->dev, attr_no);
 	if (err)
 		goto exit_free;
 
+	pdata->core_data[attr_no] = tdata;
+

Problem with this patch is that core_data can be accessed after the call to create_core_attrs() (since the attributes now exist). So the patch introduces a small window where an access to core_data[] can result in a NULL pointer access.

drivers/hwmon/coretemp.c static int create_core_data(struct platf · line 621

Quoted 2 lines
drivers/hwmon/coretemp.c +0 -0
 	return 0;
 exit_free:

Any problem with just resetting pdata->core_data[attr_no] to NULL here ?

Guenter

drivers/hwmon/coretemp.c static int create_core_data(struct platf · line 622

Quoted 4 lines
drivers/hwmon/coretemp.c +0 -0
 	kfree(tdata);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw

Re: [lm-sensors] [PATCH] coretemp: avoid leaving around dangling

In reply to Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · Guenter Roeck
Quoted 18 lines · Jan Beulich

Storing the struct temp_data pointer allocated from create_core_data() before passing the last 'goto exit_free' has the potential of leaving around a pointer to freed memory. As there's no need for the pointer to be stored before calling create_core_attrs(), simply move the storing past that call.

---
 drivers/hwmon/coretemp.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/coretemp.c +0 -0
@@ -609,13 +609,14 @@ static int create_core_data(struct platf
 				  THERM_SHIFT_THRESHOLD1) * 1000;
 	}

drivers/hwmon/coretemp.c static int create_core_data(struct platf · line 619

Quoted 10 lines
drivers/hwmon/coretemp.c +2 -1
 
-	pdata->core_data[attr_no] = tdata;
 
 	/* Create sysfs interfaces */
 	err = create_core_attrs(tdata, &pdev->dev, attr_no);
 	if (err)
 		goto exit_free;
 
+	pdata->core_data[attr_no] = tdata;
+

Problem with this patch is that core_data can be accessed after the call to create_core_attrs() (since the attributes now exist). So the patch introduces a small window where an access to core_data[] can result in a NULL pointer access.

Quoted 4 lines

drivers/hwmon/coretemp.c static int create_core_data(struct platf · line 621

Quoted 2 lines
drivers/hwmon/coretemp.c +0 -0
 	return 0;
 exit_free:

Any problem with just resetting pdata->core_data[attr_no] to NULL here ?

Certainly not - I just didn't realize the dependency you point out above, and without that it seemed more clean to just move the assignment.

Will send an updated patch in a little while, unless you want to go ahead and fix this the right way before I would get to it.

Jan

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw

Re: [lm-sensors] [PATCH] coretemp: avoid leaving around dangling

In reply to Jan Beulich
Quoted 38 lines · Jan Beulich
Quoted 38 lines
Quoted 1 line
Quoted 1 line · Guenter Roeck
Quoted 18 lines · Jan Beulich

Storing the struct temp_data pointer allocated from create_core_data() before passing the last 'goto exit_free' has the potential of leaving around a pointer to freed memory. As there's no need for the pointer to be stored before calling create_core_attrs(), simply move the storing past that call.

---
 drivers/hwmon/coretemp.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/coretemp.c +0 -0
@@ -609,13 +609,14 @@ static int create_core_data(struct platf
 				  THERM_SHIFT_THRESHOLD1) * 1000;
 	}

drivers/hwmon/coretemp.c static int create_core_data(struct platf · line 619

Quoted 10 lines
drivers/hwmon/coretemp.c +2 -1
 
-	pdata->core_data[attr_no] = tdata;
 
 	/* Create sysfs interfaces */
 	err = create_core_attrs(tdata, &pdev->dev, attr_no);
 	if (err)
 		goto exit_free;
 
+	pdata->core_data[attr_no] = tdata;
+

Problem with this patch is that core_data can be accessed after the call to create_core_attrs() (since the attributes now exist). So the patch introduces a small window where an access to core_data[] can result in a NULL pointer access.

Quoted 2 lines
drivers/hwmon/coretemp.c +0 -0
 	return 0;
 exit_free:
Quoted 8 lines
Quoted 1 line

Any problem with just resetting pdata->core_data[attr_no] to NULL here ?

Certainly not - I just didn't realize the dependency you point out above, and without that it seemed more clean to just move the assignment.

Will send an updated patch in a little while, unless you want to go ahead and fix this the right way before I would get to it.

I'll wait for your updated patch.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors