Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1884980rwb; Thu, 15 Dec 2022 16:06:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5rn02p0nXUSBHf86idhJEdh8ufGQceQd/Uz7rkGo2xXw8rCW2jYF/GYjq/VSJMmJSEI3KI X-Received: by 2002:a17:906:7e11:b0:7c1:311f:3533 with SMTP id e17-20020a1709067e1100b007c1311f3533mr23391757ejr.60.1671149205440; Thu, 15 Dec 2022 16:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671149205; cv=none; d=google.com; s=arc-20160816; b=YjrJ76HsQGIFLjhigXfTNGrkY9zbX4Qx4Zvf+MzqkDnLCGsp/wNXehMEJYXr7RRsw4 4rOxWdnDg+n0uecVZ5klYEuwLfZvcH95sNhMg+tY9EsbEgDg4jjhQVwtCmjHWrCmLdBg GoKfabAz2ZAhx19jgSVpxCpTzD9k7Yedkvi8a0xY7Q34tziG+tRWa4mWJUYur3ZbtXu1 vS2XeDgJw82xHgx5NrwBtLQR3vOgfAXNXAkpp1ndEMrfCYgtd7Ti4uhHbUNPdbAT2Ekn DfqILUme4oc9BEJb3DzHu7lo4mKWaC01aUBL4yD8XwACFL9egpvwcxPjcYEfv1Y4rgb0 da9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=H5crU78K2zee4DdEMLmYCKLNeQWcvsMzZNn++UaUCUw=; b=c+w5Jt0QvEuKt89Qhh/QTPMT5YXtbIyFSGXZHvuBNEy5/+BJlRJwA4CsZAhygBoLKK zv0p4ivJhDgFnlg1YDIdnJwhAqOvS43/KCVOalZMQdfO4TXsDObPkUPYeqGiXTOuygoQ d+XMgqB+4A19mmCq/1W6VWX1hGxPZMB4Y3ItQwP7Db6dF5elaS/gr+fssiVbU5xoaWfB nxvp0G9vpUenNjYRS3hmZ7qNwBAwq/nMrVql/DtwfshyfC4X36YDyzy+vVGSl1bdIBIN G5akFhovQ1HhgR4kVCECrIgOz/URnyPM8PalgWnV8awRdiH5VtPgYqBN7JbkLLyJ9w/C RZ6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=TW3AGIqC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ml21-20020a170906cc1500b007c0889e324esi480633ejb.366.2022.12.15.16.06.28; Thu, 15 Dec 2022 16:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=TW3AGIqC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbiLOXVP (ORCPT + 68 others); Thu, 15 Dec 2022 18:21:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiLOXVN (ORCPT ); Thu, 15 Dec 2022 18:21:13 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C79BDFBF; Thu, 15 Dec 2022 15:21:11 -0800 (PST) Received: from rustam-GF63-Thin-9RCX.. (unknown [93.175.1.130]) by mail.ispras.ru (Postfix) with ESMTPSA id 70FD040D403D; Thu, 15 Dec 2022 23:21:07 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 70FD040D403D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671146467; bh=H5crU78K2zee4DdEMLmYCKLNeQWcvsMzZNn++UaUCUw=; h=From:To:Cc:Subject:Date:From; b=TW3AGIqCEXiBI6wHJW24PtJsv3PGrEj7RLl0TKUh5C3MzIW2cR6Xgi3YPwZq+hMjH 8fce9uRpLjyyLEtabNcGWUobcFY4Tf4R3xsyJ2RVLwaPWYus+DOD3XLRk6GopVBIia Jqp6fP+8+j+q7qtJkVFua0mRcfBbQ+Qi34ueT+wM= From: Rustam Subkhankulov To: Hans de Goede Cc: Rustam Subkhankulov , Mark Gross , ye xingchen , "Darren Hart (VMware)" , Mario Limonciello , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov Subject: [PATCH] dell-smbios: fix double free in dell_smbios_init() and fixes in dell_smbios_exit() Date: Fri, 16 Dec 2022 02:17:41 +0300 Message-Id: <20221215231741.154355-1-subkhankulov@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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