acpi/nfit: Fix memory corruption/Unregister mce decoder on failure
Subsystems (2)
PATCH 1/1 acpi/nfit: Fix memory corruption/Unregister mce decoder on failure
nfit_init() calls nfit_mce_register() on module load. When the module load fails the nfit mce decoder is not unregistered. The module's memory is freed leaving the decoder chain referencing junk. This will cause panics as future registrations will reference the free'd memory.
Only register the nfit mce decoder on success.
--- drivers/acpi/nfit/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/nfit/core.c +6 -2
@@ -3043,6 +3043,8 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event)static __init int nfit_init (void ) { +int ret; +BUILD_BUG_ON (sizeof (struct acpi_table_nfit ) !=40 );BUILD_BUG_ON (sizeof (struct acpi_nfit_system_address ) !=56 );BUILD_BUG_ON (sizeof (struct acpi_nfit_memory_map ) !=48 );
@@ -3069,9 +3071,11 @@ static __init int nfit_init(void)if (!nfit_wq)return -ENOMEM ; -nfit_mce_register (); + ret =acpi_bus_register_driver (&acpi_nfit_driver); +if (!ret) +nfit_mce_register (); -return acpi_bus_register_driver (&acpi_nfit_driver); +return ret; } static __exit void nfit_exit(void)
Signature · 1 line
1.7.9.3
Verma, Vishal L
maintainerQuoted 6 lines · Prarit Bhargava
nfit_init()callsnfit_mce_register()on module load. When the module load fails the nfit mce decoder is not unregistered. The module's memory is freed leaving the decoder chain referencing junk. This will cause panics as future registrations will reference the free'd memory.Only register the nfit mce decoder on success.
Good find! I'm wondering if registering the mce handler after the rest of the init will leave a (small) window open where MCEs can happen but the handler has yet to be registered.. Maybe it is inconsequential, and we can just do this. Alternatively, if acpi_bus_register_driver fails, then go back and unregister the mce handler..
Quoted 41 lines
Signed-off-by Prarit Bhargava <[email protected]>Cc Jeff Moyer <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc Dan Williams <[email protected]>Cc Vishal Verma <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Linda Knippers <[email protected]>---
drivers/acpi/nfit/core.c | 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)drivers/acpi/nfit/core.c +0
-0@@ -3043,6 +3043,8 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event)
static__initintnfit_init(void)
{drivers/acpi/nfit/core.c +2
-0+int ret; +
BUILD_BUG_ON(sizeof(struct acpi_table_nfit) != 40);BUILD_BUG_ON(sizeof(struct acpi_nfit_system_address) != 56);BUILD_BUG_ON(sizeof(struct acpi_nfit_memory_map) != 48);drivers/acpi/nfit/core.c +0
-0@@ -3069,9 +3071,11 @@ static __init int nfit_init(void) if (!nfit_wq) return -ENOMEM;drivers/acpi/nfit/core.c +3
-1-nfit_mce_register (); + ret =acpi_bus_register_driver (&acpi_nfit_driver); +if (!ret) +nfit_mce_register ();drivers/acpi/nfit/core.c +1
-1-return acpi_bus_register_driver (&acpi_nfit_driver); +return ret;}
static__exitvoidnfit_exit(void)
Quoted 6 lines · Vishal L
Quoted 5 lines · Prarit Bhargava
nfit_init()callsnfit_mce_register()on module load. When the module load fails the nfit mce decoder is not unregistered. The module's memory is freed leaving the decoder chain referencing junk. This will cause panics as future registrations will reference the free'd memory.
Quoted 7 lines
Quoted 1 line
Only register the nfit mce decoder on success.
Good find! I'm wondering if registering the mce handler after the rest of the init will leave a (small) window open where MCEs can happen but the handler has yet to be registered.. Maybe it is inconsequential, and we can just do this. Alternatively, if
acpi_bus_register_driverfails, then go back and unregister the mce handler..
FWIW my first version did exactly what you describe. I felt like the version below was a cleaner approach in terms of code, and because I thought that the possibility of an MCE occurring in those few moments between the return and registration was minimal.
I could be wrong though :) and I still have that original patch so it isn't a big deal to do a v2.
P.
Quoted 42 lines
Quoted 42 lines
Signed-off-by Prarit Bhargava <[email protected]>Cc Jeff Moyer <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc Dan Williams <[email protected]>Cc Vishal Verma <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Linda Knippers <[email protected]>--- drivers/acpi/nfit/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/acpi/nfit/core.c +2
-0@@ -3043,6 +3043,8 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event)static __init int nfit_init (void ) { +int ret; +BUILD_BUG_ON (sizeof (struct acpi_table_nfit ) !=40 );BUILD_BUG_ON (sizeof (struct acpi_nfit_system_address ) !=56 );drivers/acpi/nfit/core.c +4
-2BUILD_BUG_ON (sizeof (struct acpi_nfit_memory_map ) !=48 );@@ -3069,9 +3071,11 @@ static __init int nfit_init(void)if (!nfit_wq)return -ENOMEM ; -nfit_mce_register (); + ret =acpi_bus_register_driver (&acpi_nfit_driver); +if (!ret) +nfit_mce_register (); -return acpi_bus_register_driver (&acpi_nfit_driver); +return ret; } static __exit void nfit_exit(void)