Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp379861rdh; Sat, 23 Sep 2023 15:00:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwNUwemdt+j8JkkLTFd/aXVAYiw3rQNrhbwFiluT84ltZ63QjU56zcSRBfo5t/n2EGsoSl X-Received: by 2002:a17:903:2305:b0:1c1:e258:7447 with SMTP id d5-20020a170903230500b001c1e2587447mr3641922plh.22.1695506446752; Sat, 23 Sep 2023 15:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695506446; cv=none; d=google.com; s=arc-20160816; b=hIb/miSDDZSp2Xu6s4MuOHoMk8x9z46EGja4pJUzQP2qI7NkeTPOa3xB9xJDV266FR OJMQLUq53tYnvYF4gU0cusK2v2sj/Bq0e9ZGK07d+uCeZYCnrqwhndPuGVK1jLSfIfTC uZpyc10h+P1/s7U3dkrulU1ZFn1TsxecDibZpBUpdJGs0sKGNJ3r2fmxoyR1E9Sm+qiH cIPyjQRkQbB+picpFBTZFJZh/LsAsJKzKSgN7PlNtrnOfiWLC9+9ILjqxnSqAHDiCoNk uGjbrsTvvViiWN7LJ1L93OGWM6iY0qlqxB730TK+IP4EJsKfOd5TbwoLkBpIyuKEWZsr A2sw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=rU92T7+NBfeDe2lNll/8f6A0V1ai/n+iA8f3wdbjFsg=; fh=1h2Rm5+wq+TMpeYx3V+jlA2lg2MGCIkOXtF+OMoIrWQ=; b=TtMdu28PAbYVvAC6X/iz/xri68hRFfxmJ0sBeDwihDVYTT7pNB8yUbKNezTIGwCvHG dXQwGLc2JZOpIwhZ4dfik8cUurBIs31spKs0lEmoT0/nwdArFsA6OgnvlA+TrwQOCqak SM37NTVf4zhzx3kEwSroVUDomwNwR0xstvyNlKCvaWvsDSfCPIJT6cWTHRNS+MFJP3ng 4y9wup8KJoNE0fsuTwwctezOlXI4ec++TrqA14Tc8IhSkHgd9zfcW2tgy06SysqPn9nY pzp1ReGTmI4r6Hk3OvV1Z2i3HnRlYeMJJacySltr+5gh1pZqrdos9QrLXd2jqCUbVrH2 OY0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=nSY+xcav; 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 Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id y6-20020a17090322c600b001c35cccca33si6938538plg.448.2023.09.23.15.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 15:00:46 -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=nSY+xcav; 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 28FD78241E1D; Sat, 23 Sep 2023 13:42:32 -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 S229618AbjIWUmY (ORCPT + 99 others); Sat, 23 Sep 2023 16:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjIWUmW (ORCPT ); Sat, 23 Sep 2023 16:42:22 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBCF3139; Sat, 23 Sep 2023 13:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695501717; x=1696106517; i=w_armin@gmx.de; bh=v8QTdDa9zizuofuXHY/8uWirblQY/wodxLqL6Wr/bh4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=nSY+xcav6HcNXj0H+FD9aQOyGVkoM3Y/zPvsuVu/Evk6KcpBNY047gfHG1/6+BjkwD/Sbn/BIFW 1WQFcTz77bkcQAtoMWG+9s4hE5Cv2jQTIVOss6lOCMqAXO35hP0WtzEs/XYRMMMRpXBFkI6wdRdbN 0GUNCXY1nZ6qtlH2oCKF6E2CAARNOVysttimWQF5lrJk7Yk9zzokeHZhPtwCHsHM3ZIPKCXRsOCSB LDBtFvPJOx3CfUONodNc4YKQM7PgxUI7kmMlYk1E68TTYF6qO+uFefeOvbouGySCNawRkNRWYIJeQ TMZjwtfqokrJgGs6LOERyD695Ayrk5rxUUWg== 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 1N1OXZ-1rgoms0Q27-012rgk; Sat, 23 Sep 2023 22:41:57 +0200 From: Armin Wolf To: markpearson@lenovo.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] platform/x86: think-lmi: Fix reference leak Date: Sat, 23 Sep 2023 22:41:54 +0200 Message-Id: <20230923204154.86815-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags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AgAE35l6LuwkQTW2 rBEAgWaLT4RiHaI667hjNEPQvbOtYVvMIzRddbkDbv3+3tskBe31h3RKMvfDnCABkHXXnCfwl Yqp2r0VFMKv0VlbSz6ATmj9ByY4iKrp1FYcStmtzRYz5CIBaOlT7FliWakyN6gKoIh20kJUPJ HXAO00QB9M6VMTENqtzv0FCre2o= 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]); Sat, 23 Sep 2023 13:42:32 -0700 (PDT) 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 a= ttributes") Signed-off-by: Armin Wolf =2D-- drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think= -lmi.c index 4be6f28d4600..3a396b763c49 100644 =2D-- 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 =3D 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]->displ= ay_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] =3D NULL; =2D- 2.39.2