From patchwork Mon Sep 25 13:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13397826 X-Patchwork-Delegate: hdegoede@redhat.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72AEFCE7A81 for ; Mon, 25 Sep 2023 13:29:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231794AbjIYN3R (ORCPT ); Mon, 25 Sep 2023 09:29:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230284AbjIYN3O (ORCPT ); Mon, 25 Sep 2023 09:29:14 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01DD910E; Mon, 25 Sep 2023 06:29:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695648529; x=1696253329; i=w_armin@gmx.de; bh=RDTGeRg8m+ex27ocQe6qZsyvm1iCvXo28qa08fOWNpg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=DZdUHsv5crvlVJFTTrkY9MfX+IbjoaHe0C3vAVj2EW5VIst6ZdXcVhNJDk5Im9vPvYt+77oHNzJ c1r+OcTL8S6b9h+YOxyQrA6k6jV2tCMUAS8M8ppwqbCiNUxMEwtSpRXFcLnzmMc3nDtt+2mpdJ2ux 4OFVdGHf0gbUBnQFQ2kuasbpFv+pQsMSp02ZLfoqytydGWyER/4QocBB0QWweTQNAz6fyT0Au7VVe 7+Ruu73mGWpALy8z5TIGcgSoPf2lCl1KnruX4sH8tqgcRPjtSKB8EwcqGhRpAS/mCz5R0jpDgrb2W RhokTrLhRzyOtPNEiTbPJadFHRyQ5U8pmTVw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MBm1U-1qwtfZ0BCO-00CAir; Mon, 25 Sep 2023 15:28:49 +0200 From: Armin Wolf To: markpearson@lenovo.com, jorge.lopez2@hp.com Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] platform/x86: think-lmi: Fix reference leak Date: Mon, 25 Sep 2023 15:28:43 +0200 Message-Id: <20230925132844.72479-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925132844.72479-1-W_Armin@gmx.de> References: <20230925132844.72479-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:f8bun32Dbxt8C5XhmyOMmc0eZElWdHxIhVgx1/DLOtGjEPENrAn 7RbawcWQuYm/dHl6Bp4tjUV0BuEWA79RoFEGdXdcSjBOMit2zztBEjmvVIb8R6OtyRL8oqx cMZnMpf6EIl8A69vYOSi7yCmbMdfiAQBDBqViQRHI74oaHyj8iLROrGVniAPw5ffPaTvpwN d1ZKlZkiFFAQuWQjjUYDg== UI-OutboundReport: notjunk:1;M01:P0:ZUToJMOjej4=;whp+qgCHvgDB5g9yWRRyqv4536Z Lh5m2+vMP0w4w/tT4gTNohXUPoRm92tZsKx47ZtafcqaLAdB/+9ruOls/vuhQ/pLxKRi4lSdz iLn1JIoxYxLgE79Ue1TjkJFyINxBJJAYxLmmGfQZl42Mr5CIlz2teJSiQt46GgdNqeFZChym7 ORXwWkqg9LZhX/NMP+tFSG6bI5ws45vwMygW/ThIFN4K9lH42ysxDSmaac7eR52ty1QxpMlTq xLkyjiyUuzY58tpRsFCvBrnBiY9C1G2PiqNPz9hs7Dvtyel4OmzhvrYZuVvqZtXDubPXPQ3VQ 5LALlYBDDLCiT1UN5RdzeZwoqHx5JklUH1uL+rNJmqvaV3H0NIifv4Xu0iBY57CfePU+AkDI+ U4f99lojc8Ez4dBxPyahIOVTJnaPM5laOfkEHBjOlR75yOsyjZgcMaSHYbfeJkbGJ4fEAnHFA xFzsAzBXg92Lr5isjaj+sS7NJj0WfPl2aK+H2vxZxa2jWvS6aWUK4sjY5e9VkUip+90hP9Gre 0xGVgM8Vqwn/evA0902vuo4+BNvYAvqB9PSIM3+BfFecCVQmQKGcga/NuLbdzw6tgGTIBmyFJ IEb1FUY0Dl6lNfjpdyPN9OLzKKbJx0KFSRde6VjD1enc1metUzRWw7ZEqGKJbJ+py+qGPvjY+ qzhEw9S61SvpVgEFsfCOQIyo07tMcW6ikNf5L4TD3a+rZEg+7W+uis4O6m16aYZdCmrCBWOtP s6L5gLCCkuTMqxzNos5ZGASXsb8YyPGDck/WsX3Rnt3ZXHJegaz+WtXxcBh4C9pa+8kbFZaZI JYUtVtOzaZgvwIkm/ZXv8IDu8f+RiTjoJI2PobTQc27qYERJbUD9CIfKciGHnEgoG9Rl+XBE7 9A2G4njOFTSW78QTg2kpzMjFm7lfK4Tu794XXIdCVVusEJV6hsqk17953pqZokz6G4BcHKg6Y WFloDY2CrnNEHyIxE/V7QNtpbsQ= Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org If a duplicate attribute is found using kset_find_obj(), a reference to that attribute is returned which needs to be disposed accordingly using kobject_put(). Move the setting name validation into a separate function to allow for this change without having to duplicate the cleanup code for this setting. As a side note, a very similar bug was fixed in commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"), so it seems that the bug was copied from that driver. Compile-tested only. Fixes: 1bcad8e510b2 ("platform/x86: think-lmi: Fix issues with duplicate attributes") Reviewed-by: Ilpo Järvinen Signed-off-by: Armin Wolf --- Changes in v3: - add Reviewed-by Changes in v2: - no changes --- drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 4be6f28d4600..3a396b763c49 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -1344,6 +1344,24 @@ static void tlmi_release_attr(void) kset_unregister(tlmi_priv.authentication_kset); } +static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name) +{ + struct kobject *duplicate; + + if (!strcmp(name, "Reserved")) + return -EINVAL; + + duplicate = kset_find_obj(attribute_kset, name); + if (duplicate) { + pr_debug("Duplicate attribute name found - %s\n", name); + /* kset_find_obj() returns a reference */ + kobject_put(duplicate); + return -EBUSY; + } + + return 0; +} + static int tlmi_sysfs_init(void) { int i, ret; @@ -1372,10 +1390,8 @@ static int tlmi_sysfs_init(void) continue; /* check for duplicate or reserved values */ - if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) || - !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) { - pr_debug("duplicate or reserved attribute name found - %s\n", - tlmi_priv.setting[i]->display_name); + if (tlmi_validate_setting_name(tlmi_priv.attribute_kset, + tlmi_priv.setting[i]->display_name) < 0) { kfree(tlmi_priv.setting[i]->possible_values); kfree(tlmi_priv.setting[i]); tlmi_priv.setting[i] = NULL; From patchwork Mon Sep 25 13:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13397825 X-Patchwork-Delegate: hdegoede@redhat.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D361ACE7A94 for ; Mon, 25 Sep 2023 13:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231773AbjIYN3Q (ORCPT ); Mon, 25 Sep 2023 09:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231742AbjIYN3M (ORCPT ); Mon, 25 Sep 2023 09:29:12 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DA81FF; Mon, 25 Sep 2023 06:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695648530; x=1696253330; i=w_armin@gmx.de; bh=RvUmrJpI8L7JM1w0AgZ8nzrY2l+SMzgiJ9T5DMWjVFU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=gS1bxp5eWBF+smPOfnh75xFR/dlXq5911ngC83XvuGbJXg6fr+wLlF1YKjnSNtbZfidkBSsm00O lMrczo5fq9cSzWonBwVB6OtLdqjacEfmEX4ov+smDKRjD6LiIAjMZLhZoYG66nA5+LsV7AUnwmtc8 eIKCr01/vDaYOwRRjTX2zX9h4aIHUrhUHrSevZsyJNhCYT7Ecrvd2UeuGz21Q9JiGdDtAD2uCfX5R JU89oIiV7WJIMIqNyCkggTYQpZ4anFBEtJVeuiAHBh4HvPzjX8FbPst7LohkflfbdmIFxPIFRszYN hMu6JW/q6yuAErL3jspB7bMB1AaA+leazJ/g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mzhj9-1rWpz11ziz-00vg5V; Mon, 25 Sep 2023 15:28:50 +0200 From: Armin Wolf To: markpearson@lenovo.com, jorge.lopez2@hp.com Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] platform/x86: hp-bioscfg: Fix reference leak Date: Mon, 25 Sep 2023 15:28:44 +0200 Message-Id: <20230925132844.72479-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925132844.72479-1-W_Armin@gmx.de> References: <20230925132844.72479-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:wVU/vvnTaXPRlpfetkvvBU2Zdlhe7jV9e10G0/ZGWrqbbgyNtvq xBekzlXdpOcCqQ4svJlyU7WBVJfvZngztNMS7F1S86nR/UfyLv38j5tESdmMycIkM6fWyii YxG2nsTzhk0I4vmeeYrw3/dkXnRKT0gAC8CFHpIOjbaHrrVK+wwJM6CMJKy+quAwjJJTEYr NyCrdTA3QvcrlK8cRvs1g== UI-OutboundReport: notjunk:1;M01:P0:GSnf9eeADtg=;xxaEpJW0WiO5EqPgGDnYGCQtVB1 uZH1P6q+Xxm4wDcREARAx0vv26BpbuIEnbuTF7A7iQ6e46nLOhrtWgX6GJdUMlXOwryxXQRyp WVcV69dY3vpi1ovGv52qqZyf2uvIlHpibtVzvCvlw6KtooVEKDhHrZqJhB+jgM938r9Kr5N1A sk6ZQXrBmcWVVUymCA0KRb/D+ewtPltJjv9NHxh2pEJTWLq3OgTXJklydXJJ+xP/SFmV5jOuB DVVS2mTZHJyC/LdTAJIzRTaeOYGKDe8OXW2k8EF8wr6XfLC+4RHHTEEG9bqqGYDsh/0cUnT9R 3QSw4Xy2mbfhqsNbiYkpiG0DTYZyM5+StoSdLn47t3aWODgI8b7h0FJxcxmCVaZW5fbm8LEnZ VHNytsetZoezoAFy9KaNu943mKl9r6gbYM04WqW9hXukCMalPME21O2ujKTFQMBMI+ZRwrl5N rVfm6GNEHgHADSuE99ThTR6by6xY3XHscHVAWiZfMl7NdRIjehueLpWHX6G4ECe2nNsOSYEVI D65sUHpmduvDXU2TlimHKzR7o/ganM2W7JxXEq4sPdN+RwguDCa7uoeqfevLYZ4EKGCQ5rmvj WW7ldrvehSgndoX6ViqXxEUQxLUaEAo+ASBJfuvvYugCHlnz07pwybwion3ZGr7WRK/Ce7I5Y DBJ5nfmAcyhPWCIbmjRTYAhXIUyrME5vI9EP3g/0JIP7X9E92nmOjx9dzp4WeZnfjjeci4EvR Twsrd/Mhtzf/gJ3dB+18Htog9F638lrKuGurBaeiEmMbza8ciBokjMQVZgxCGXCJcQ+fRvTK6 Lv64Ckf6VdqrcoJMniZOE2BI5OyluM9fr7IbdX9CFlJqk/fQGSz7b9+DpBhgRcwcbsqdoq9or b8s4UFfxMNDmm3oYpOBB9hwQ3HgB5KGtVd4bPCDwIibWg/E6LpzDhd3bdQK9DyblVuP1Dzu4Z ZceKSw8oiPWEYRULD1K3KXTc0pM= Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org If a duplicate attribute is found using kset_find_obj(), a reference to that attribute is returned which needs to be disposed accordingly using kobject_put(). Use kobject_put() to dispose the duplicate attribute in such a case. As a side note, a very similar bug was fixed in commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"), so it seems that the bug was copied from that driver. Compile-tested only. Fixes: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg") Suggested-by: Ilpo Järvinen Signed-off-by: Armin Wolf Reviewed-by: Ilpo Järvinen --- Changes in v3: - no changes Changes in v2: - add patch --- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c index 8c4f9e12f018..0c83e66f8d0b 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c @@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, const char *guid, int min_elements, int instance_id) { - struct kobject *attr_name_kobj; + struct kobject *attr_name_kobj, *duplicate; union acpi_object *elements; struct kset *temp_kset; @@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, } /* All duplicate attributes found are ignored */ - if (kset_find_obj(temp_kset, str_value)) { + duplicate = kset_find_obj(temp_kset, str_value); + if (duplicate) { pr_debug("Duplicate attribute name found - %s\n", str_value); + /* kset_find_obj() returns a reference */ + kobject_put(duplicate); goto pack_attr_exit; } @@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, const char *guid, int min_elements, int instance_id) { - struct kobject *attr_name_kobj; + struct kobject *attr_name_kobj, *duplicate; struct kset *temp_kset; char str[MAX_BUFF_SIZE]; @@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, temp_kset = bioscfg_drv.main_dir_kset; /* All duplicate attributes found are ignored */ - if (kset_find_obj(temp_kset, str)) { + duplicate = kset_find_obj(temp_kset, str); + if (duplicate) { pr_debug("Duplicate attribute name found - %s\n", str); + /*kset_find_obj() returns a reference */ + kobject_put(duplicate); goto buff_attr_exit; }