mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dell-smbios: fix double free in dell_smbios_init() and fixes in dell_smbios_exit()
@ 2022-12-15 23:17 Rustam Subkhankulov
  2023-01-12 16:40 ` Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: Rustam Subkhankulov @ 2022-12-15 23:17 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Rustam Subkhankulov, Mark Gross, ye xingchen,
	Darren Hart (VMware),
	Mario Limonciello, platform-driver-x86, linux-kernel,
	Alexey Khoroshilov

If an error occurs in function build_tokens_sysfs(), then all the memory
that has been allocated is correctly freed at certain labels at the end
of this function.

build_tokens_sysfs() returns a non-zero value on error, function
free_group() is called, resulting in a double-free. Removing
free_group() function call will fix this problem.

Also, it seems that instead of free_group() call, there should be
exit_dell_smbios_smm() and exit_dell_smbios_wmi() calls, since there is
initialization, but there is no release of resources in case of an error.

Since calling 'exit' functions for 'smm' and 'wmi' is unsafe if
initialization failed, in dell_smbios_exit() and dell_smbios_init()
we need to call 'exit' only if initialization before was successful.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Rustam Subkhankulov <subkhankulov@ispras.ru>
Fixes: 25d47027e100 ("platform/x86: dell-smbios: Link all dell-smbios-* modules together")
---
 drivers/platform/x86/dell/dell-smbios-base.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/dell/dell-smbios-base.c b/drivers/platform/x86/dell/dell-smbios-base.c
index fc086b66f70b..cfef8cdd1215 100644
--- a/drivers/platform/x86/dell/dell-smbios-base.c
+++ b/drivers/platform/x86/dell/dell-smbios-base.c
@@ -29,6 +29,8 @@ static struct device_attribute *token_location_attrs;
 static struct device_attribute *token_value_attrs;
 static struct attribute **token_attrs;
 static DEFINE_MUTEX(smbios_mutex);
+static bool wmi_initialized;
+static bool smm_initialized;
 
 struct smbios_device {
 	struct list_head list;
@@ -607,6 +609,9 @@ static int __init dell_smbios_init(void)
 			goto fail_sysfs;
 	}
 
+	wmi_initialized = !(wmi);
+	smm_initialized = !(smm);
+
 	return 0;
 
 fail_sysfs:
@@ -628,8 +633,16 @@ static int __init dell_smbios_init(void)
 
 static void __exit dell_smbios_exit(void)
 {
-	exit_dell_smbios_wmi();
-	exit_dell_smbios_smm();
+	if (wmi_initialized) {
+		exit_dell_smbios_wmi();
+		wmi_initialized = 0;
+	}
+
+	if (smm_initialized) {
+		exit_dell_smbios_smm();
+		smm_initialized = 0;
+	}
+
 	mutex_lock(&smbios_mutex);
 	if (platform_device) {
 		if (da_tokens)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-12 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15 23:17 [PATCH] dell-smbios: fix double free in dell_smbios_init() and fixes in dell_smbios_exit() Rustam Subkhankulov
2023-01-12 16:40 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®