From patchwork Mon Sep 25 14:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 144438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:6f87:b0:13f:353d:d1ed with SMTP id tl7csp1141717rwb; Mon, 25 Sep 2023 07:29:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaD+LCka3kss/D7M2qpoiguURRQyDOwKvL3F84D4mwHFvI/1LvIk1gS0jArqPaT5zRfZN5 X-Received: by 2002:a05:6a20:1448:b0:15e:707c:904 with SMTP id a8-20020a056a20144800b0015e707c0904mr4223765pzi.24.1695652138403; Mon, 25 Sep 2023 07:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695652138; cv=none; d=google.com; s=arc-20160816; b=spVPAVpvKgOdsDo/+mgoqcq6cooKtGXuFYtVA5zmUzHyav0ArdY98qtRnDnDlJ3qkb UFlDOGg9duq3Qwbkh3qYG+9uEMW19LqkFmHwmUDOzHkqnAY/JPebb8+DD7irOFKEmtk3 Eo8eRWC7vjyUy7FIwJtvChfPnVzHZucpynA88pZ2gaBqgPYDEtQR8UqjvC0MuoXZ/OV7 iPjjWn2Dp/uBkGi3cngTNj/nvZ+U9y76L32RbiqZQBbpatecPxNOE4FUnIq+nddujvpH B1NHetFcnzv02zTD6FVkmsqFhVr5v6f3ifpBKl1pCI84vKcWvWayEXjZ2zbr5HKirp92 PoQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9l5gvj2nE/UBYa0ZDlDsGhQ5t4iNJvDpin3dIkZqYBY=; fh=JUqgqE2sM0crfy+ZSl9xW59lCsTd2U6P1z7TM85l0wU=; b=zvgEMy762XaggAkARvB8rPGtwpa4hg1Zu8CIbtZVgque0QPnERu81Vw9JF3JsvudQ4 QGmoGfTV1ZLca5j1QWuWvJ3rfl7U/3LFsxvsAgV5fTUv0oYwTyE2S5UzdKHqhfpZw3mw HSt2z4QmGxGZ9esxRvjg0zciZ8ljvVQkcRYq2+iqm++95tiEkAHSfFy3TmtPORUbJIPy 0auTr/LmHGNrMY2Mv6AGWDKgQk69ukwHWMzlRIVtD5h735nHNmD7//OYjh1uDlex7W1d BUpt1PUHAWEBn4waaMMZRZD4ewKovGhRpiS099GxB/Eaw8bLMPyFI4ISbtyNULUO41U/ tXmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=jAhHtiLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q17-20020a637511000000b005779c97fae5si9982079pgc.480.2023.09.25.07.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=jAhHtiLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 705DF81BECA5; Mon, 25 Sep 2023 07:28:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232354AbjIYO2x (ORCPT + 29 others); Mon, 25 Sep 2023 10:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232313AbjIYO2t (ORCPT ); Mon, 25 Sep 2023 10:28:49 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82369103; Mon, 25 Sep 2023 07:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695652105; x=1696256905; i=w_armin@gmx.de; bh=071gcdDLNBkCgiGL7swJLhOyDt5nxBTUzKca3uuN28I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jAhHtiLe0mXfe5UVvmsdPX9jfFWA1024EWDUdqqkw0pSUm8yjVOOCieVqQ0bVbpeCQxWXfh/wWD vJWW34+3v+huqyI6lr/SBmbXI4BqkylgPon3Yom3mheZN9CfV/hgKneP2SGrH6Sc/JRtXh7fcyV+2 MWMQBvnX64jVx3qbRqrhFRYZR3l7P0qNUWQHTTJjkVoy/CzAjLbeJpRyGE05wVZtKAZuUzX8R4gsa BUdb1qMSkJpBViOHTb7xvzfA3J5KxwTOsjkptpzU3RYSJ6v7QUnuLW0znml5oZlLIbyiDZoRCgpIB owkVmghaLFmTo58iZItYH63l++lY+HGRHagw== 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 1MDQiS-1qvGyF0ntG-00AVWy; Mon, 25 Sep 2023 16:28:25 +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 v4 1/2] platform/x86: think-lmi: Fix reference leak Date: Mon, 25 Sep 2023 16:28:18 +0200 Message-Id: <20230925142819.74525-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925142819.74525-1-W_Armin@gmx.de> References: <20230925142819.74525-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xLW589ADbeBLaSbObW/IkKlsPjnKinoeWFHFlYP2yKvjOxeMix8 tdH0CEbnJayZjjm/mr1pbvi56B/IKWGdkBL5BFEnC/AXdXRYPJ+5RD/3ZOPl6yL6zBSoH8j /gaxh0qorTWzE4tcIPq0vFxexNWee0VdCBZxXZRqLZH4ZFehyciEgNXHtKuPnvVJOIvi1Xb rVLF8F0sHGINhq1/tWQ3g== UI-OutboundReport: notjunk:1;M01:P0:DBTTDir0fBc=;/3Xslu3UF0jR4+NVqaPx8Dqb8zZ dM/LHUyK+XDNJArl7D4LGGWhQSMPK5fmlnyOLvKebr5bB5RYYwAMPnwj3WWmYqt8eo2aptPdv OADuvWhgiPfJMrFkEM5kPGVFH+c3NGL1l5ZeDqdgCfgvfPY7J2sd2RtgEttKUBj/u9Av6rvRC PI//uiEe+L6noLQKtQrHoBUKEDLa0iNoWLX9ifU9nAXWUNpH353gfZg0LC/pTn3NZIyxz7iI1 GI4S2cQYzGBGvQg98V/HafMm+eKApFAU6JEZ1ZesBofM3rPTSF/5I+8r4DQR0i0VW6FdqAHP2 NoC5VY1iqNc+Qa2oR0N3zQi4waUlo6FirvH+srgYFSTdftDKqEZcwyOZKkZ8omOCeILHAFaNc N7gTp0TKtkg4TGB54RTZ+ADaRAJLFt1hTNjOR65qPBooOVSE0BaLHXqOL1rOhKC7Kle16hM13 rZDdwG+/oHr7XB70qSR976vLJDzNyeblZSuU98ZDBOz3EmMLIGw2N+Qo4J8as+QW5XXLQZjpZ usfk3s/QTaakbceoHgVMyAcl0CZS9F0zM5HxCBqXl5Gq+G6G+QLNEsi/PIFCI9QJZu8b0oTUW Aj2pEnpCS3jM9i1Lg4BzPH35veaAu8d0y9dJOnMF3bhE9vtiJYbVy9Tu9DHGICfOa9CjC94/S DoELJVzVirWfGz0SPYJpZllU08Q5G0c0YAvj3IIfnOrldFI9GLoMzgzo2eSuJ9Haric2+XpgD oFwVU09j3VX/B/7jp3p8c5mrGWUw82Gt0MYGZj3MUKi8v+jArQ40cURDmZgSylIprD5JNU9Aw GCvso72kenBUUCH86+hAk1carRvmtqJ+GKNWsPHhsiBaKy58QfUUDHDLRTvo1ko46tDXtjmfd m/NaysBnRVlII3X2qnjMwbQJZfG6a48QSnqBrtjvYEaNFdzVI3xtTToDG9S3oXm+Z5mc/xN7K XpF/lZpW0HeWYgQOuJkozTQ50rg= X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 07:28:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778020136635866163 X-GMAIL-MSGID: 1778020136635866163 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: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Armin Wolf --- Changes in v4: - add another Reviewed-by 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;