diff mbox

PROBLEM: NULL pointer dereference in acpi_ns_check_object_type()

Message ID 4FF15FA6.5070109@gentoo.org (mailing list archive)
State New, archived
Headers show

Commit Message

Vlastimil Babka July 2, 2012, 8:45 a.m. UTC
Hello,

I've been experiencing kernel panic with NULL pointer dereference in
acpi_ns_check_object_type since kernel 3.4 on a MacPro machine.

By recompiling as much of ACPI as possible as modules, I was able to get
the system running and postpone the error until doing 'modprobe
acpi-cpufreq', which now results in oops, not panic. The log is attached
as error.log.

By bisecting linus tree between 3.3 and 3.4, I found the guilty commit
6a99b1c94d053b3420eaa4a4bc8b2883dd90a2f9
"ACPICA: Object repair code: Support to add Package wrappers" [1]
However this patch does not directly touch the functions in the stack trace.

Next I created a kdump of the oops, and looked around with gdb.
- In acpi_ns_check_package(), the null pointer is in the parameter
return_object_ptr, which is dereferenced when initializing the variable
return_object.
- The calling function acpi_ns_check_package_list() is in the 'case
ACPI_PTYPE2_COUNT:' part, the passed null pointer is in the sub_elements
variable.
- Before the switch, sub_elements is initialized like this:

  sub_elements = sub_package->package.elements

  interestingly, in the crashdump, sub_elements is null, but
  sub_package->package.elements is non-null

I've added some printk's and verified that the call of
 status = acpi_ns_check_object_type(data, &sub_package,
				   ACPI_RTYPE_PACKAGE, i);

 makes sub_package->package.elements become non-null, but sub_elements
 was already initialized before this call and remains null.

The above led me to create the attached patch which simply moves the
initialization of sub_elements after the sub_package check. I think it's
this check that results in the Integer to Package conversion/wrapping.

After this patch, the null pointer dereference is gone, but the debug
output of ACPI (acpi.debug_layer=0xffffffff acpi.debug_level=0x00000008)
shows that something is probably still wrong:

[    1.353677] nsrepair-0681 [4294967287] ns_wrap_with_package  :
\_PR_.CPU0._PSD: Wrapped Integer with expected Package object
[    1.353869] nsrepair-0681 [4294967287] ns_wrap_with_package  :
\_PR_.CPU0._PSD: Wrapped Integer with expected Package object
[    1.354059] ACPI Warning: For \_PR_.CPU0._PSD: Return Sub-Package[0]
is too small - found 1 elements, expected 5 (20120320/nspredef-905)
[    1.354253] ACPI: Invalid package argument
[    1.354322] ACPI: Invalid _PSD data
... (the same for other CPUx)


In comparison, 3.3 kernel with same acpi debug options shows only stuff
like:
[    1.494238] nsrepair-0728 [4294967287] ns_repair_package_list:
\_PR_.CPU0._PSD: Repaired incorrectly formed Package
[    1.494449] nsrepair-0728 [4294967287] ns_repair_package_list:
\_PR_.CPU2._PSD: Repaired incorrectly formed Package
[    1.494657] nsrepair-0728 [4294967287] ns_repair_package_list:
\_PR_.CPU4._PSD: Repaired incorrectly formed Package
... (the same for other CPUx)

Since I don't know much about this subsystem, I figured that I should
just report my findings at this point. The patched system is usable, but
I guess it's not a complete fix.

I also attach the output of acpidump. I hope I didn't forget anything
important, please ask for more information if needed.

Thanks,
Vlastimil Babka

[1]
git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=6a99b1c94d053b3420eaa4a4bc8b2883dd90a2f9

Comments

Moore, Robert July 2, 2012, 7:59 p.m. UTC | #1
SSB3YXMgYWJsZSB0byByZXByb2R1Y2UgdGhlIHByb2JsZW0gaGVyZSB3aXRoIHlvdXIgQUNQSSB0
YWJsZXMuDQoNCldpbGwgbG9vayBhdCB5b3VyIHBhdGNoLCBhbmQgZ2V0IGJhY2sgdG8geW91Lg0K
DQpZb3Ugc2hvdWxkIHByb2JhYmx5IG9wZW4gYSBidWd6aWxsYSBvbiB0aGlzLg0KVGhhbmtzLA0K
Qm9iDQoNCg0KPiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBsaW51eC1hY3Bp
LW93bmVyQHZnZXIua2VybmVsLm9yZyBbbWFpbHRvOmxpbnV4LWFjcGktDQo+IG93bmVyQHZnZXIu
a2VybmVsLm9yZ10gT24gQmVoYWxmIE9mIFZsYXN0aW1pbCBCYWJrYQ0KPiBTZW50OiBNb25kYXks
IEp1bHkgMDIsIDIwMTIgMTo0NSBBTQ0KPiBUbzogbGludXgtYWNwaUB2Z2VyLmtlcm5lbC5vcmcN
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1lZCBQYWNrYWdlIC4uLiAodGhlIHNhbWUgZm9yDQo+
IG90aGVyIENQVXgpDQo+IA0KPiBTaW5jZSBJIGRvbid0IGtub3cgbXVjaCBhYm91dCB0aGlzIHN1
YnN5c3RlbSwgSSBmaWd1cmVkIHRoYXQgSSBzaG91bGQNCj4ganVzdCByZXBvcnQgbXkgZmluZGlu
Z3MgYXQgdGhpcyBwb2ludC4gVGhlIHBhdGNoZWQgc3lzdGVtIGlzIHVzYWJsZSwNCj4gYnV0IEkg
Z3Vlc3MgaXQncyBub3QgYSBjb21wbGV0ZSBmaXguDQo+IA0KPiBJIGFsc28gYXR0YWNoIHRoZSBv
dXRwdXQgb2YgYWNwaWR1bXAuIEkgaG9wZSBJIGRpZG4ndCBmb3JnZXQgYW55dGhpbmcNCj4gaW1w
b3J0YW50LCBwbGVhc2UgYXNrIGZvciBtb3JlIGluZm9ybWF0aW9uIGlmIG5lZWRlZC4NCj4gDQo+
IFRoYW5rcywNCj4gVmxhc3RpbWlsIEJhYmthDQo+IA0KPiBbMV0NCj4gZ2l0Lmtlcm5lbC5vcmcv
P3A9bGludXgva2VybmVsL2dpdC90b3J2YWxkcy9saW51eC0NCj4gMi42LmdpdDthPWNvbW1pdDto
PTZhOTliMWM5NGQwNTNiMzQyMGVhYTRhNGJjOGIyODgzZGQ5MGEyZjkNCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vlastimil Babka July 3, 2012, 9:15 a.m. UTC | #2
On 07/02/2012 09:59 PM, Moore, Robert wrote:
> I was able to reproduce the problem here with your ACPI tables.
>
> Will look at your patch, and get back to you.

Thanks.

> You should probably open a bugzilla on this.

Done: bug 44171

https://bugzilla.kernel.org/show_bug.cgi?id=44171

> Thanks,
> Bob
>
>
>> -----Original Message-----
>> From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-
>> owner@vger.kernel.org] On Behalf Of Vlastimil Babka
>> Sent: Monday, July 02, 2012 1:45 AM
>> To: linux-acpi@vger.kernel.org
>> Subject: PROBLEM: NULL pointer dereference in
>> acpi_ns_check_object_type()
>>
>> Hello,
>>
>> I've been experiencing kernel panic with NULL pointer dereference in
>> acpi_ns_check_object_type since kernel 3.4 on a MacPro machine.
>>
>> By recompiling as much of ACPI as possible as modules, I was able to
>> get the system running and postpone the error until doing 'modprobe
>> acpi-cpufreq', which now results in oops, not panic. The log is
>> attached as error.log.
>>
>> By bisecting linus tree between 3.3 and 3.4, I found the guilty commit
>> 6a99b1c94d053b3420eaa4a4bc8b2883dd90a2f9
>> "ACPICA: Object repair code: Support to add Package wrappers" [1]
>> However this patch does not directly touch the functions in the stack
>> trace.
>>
>> Next I created a kdump of the oops, and looked around with gdb.
>> - In acpi_ns_check_package(), the null pointer is in the parameter
>> return_object_ptr, which is dereferenced when initializing the variable
>> return_object.
>> - The calling function acpi_ns_check_package_list() is in the 'case
>> ACPI_PTYPE2_COUNT:' part, the passed null pointer is in the
>> sub_elements variable.
>> - Before the switch, sub_elements is initialized like this:
>>
>>    sub_elements = sub_package->package.elements
>>
>>    interestingly, in the crashdump, sub_elements is null, but
>>    sub_package->package.elements is non-null
>>
>> I've added some printk's and verified that the call of  status =
>> acpi_ns_check_object_type(data, &sub_package,
>> 				   ACPI_RTYPE_PACKAGE, i);
>>
>>   makes sub_package->package.elements become non-null, but sub_elements
>> was already initialized before this call and remains null.
>>
>> The above led me to create the attached patch which simply moves the
>> initialization of sub_elements after the sub_package check. I think
>> it's this check that results in the Integer to Package
>> conversion/wrapping.
>>
>> After this patch, the null pointer dereference is gone, but the debug
>> output of ACPI (acpi.debug_layer=0xffffffff
>> acpi.debug_level=0x00000008) shows that something is probably still
>> wrong:
>>
>> [    1.353677] nsrepair-0681 [4294967287] ns_wrap_with_package  :
>> \_PR_.CPU0._PSD: Wrapped Integer with expected Package object
>> [    1.353869] nsrepair-0681 [4294967287] ns_wrap_with_package  :
>> \_PR_.CPU0._PSD: Wrapped Integer with expected Package object
>> [    1.354059] ACPI Warning: For \_PR_.CPU0._PSD: Return Sub-Package[0]
>> is too small - found 1 elements, expected 5 (20120320/nspredef-905)
>> [    1.354253] ACPI: Invalid package argument
>> [    1.354322] ACPI: Invalid _PSD data
>> ... (the same for other CPUx)
>>
>>
>> In comparison, 3.3 kernel with same acpi debug options shows only stuff
>> like:
>> [    1.494238] nsrepair-0728 [4294967287] ns_repair_package_list:
>> \_PR_.CPU0._PSD: Repaired incorrectly formed Package
>> [    1.494449] nsrepair-0728 [4294967287] ns_repair_package_list:
>> \_PR_.CPU2._PSD: Repaired incorrectly formed Package
>> [    1.494657] nsrepair-0728 [4294967287] ns_repair_package_list:
>> \_PR_.CPU4._PSD: Repaired incorrectly formed Package ... (the same for
>> other CPUx)
>>
>> Since I don't know much about this subsystem, I figured that I should
>> just report my findings at this point. The patched system is usable,
>> but I guess it's not a complete fix.
>>
>> I also attach the output of acpidump. I hope I didn't forget anything
>> important, please ask for more information if needed.
>>
>> Thanks,
>> Vlastimil Babka
>>
>> [1]
>> git.kernel.org/?p=linux/kernel/git/torvalds/linux-
>> 2.6.git;a=commit;h=6a99b1c94d053b3420eaa4a4bc8b2883dd90a2f9
>
> N?????r??y???b?X???v?^?)?{.n?+????{?i?b?{ay????,j??f???h???z??w??????j:+v???w?j?m????????zZ+???j"??!tml=
>


--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

From 0e83f804ecac018e6b1dbeef31478e83a53dd520 Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <caster@gentoo.org>
Date: Fri, 29 Jun 2012 15:19:03 +0200
Subject: [PATCH] Hopeful fix.

---
 drivers/acpi/acpica/nspredef.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 23ce096..4a09384 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -718,7 +718,6 @@  acpi_ns_check_package_list(struct acpi_predefined_data *data,
 	 */
 	for (i = 0; i < count; i++) {
 		sub_package = *elements;
-		sub_elements = sub_package->package.elements;
 		data->parent_package = sub_package;
 
 		/* Each sub-object must be of type Package */
@@ -731,6 +730,7 @@  acpi_ns_check_package_list(struct acpi_predefined_data *data,
 
 		/* Examine the different types of expected sub-packages */
 
+		sub_elements = sub_package->package.elements;
 		data->parent_package = sub_package;
 		switch (package->ret_info.type) {
 		case ACPI_PTYPE2:
-- 
1.7.8.6