[1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
Message ID | 20230401184345.208960-1-mpearson-lenovo@squebb.ca |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1384406vqo; Sat, 1 Apr 2023 11:58:33 -0700 (PDT) X-Google-Smtp-Source: AKy350YzQ3MskOld4als8KbTs6wmBUPCM8mFmxqLhMqUTOgTJMU1OjC3N6xcrGRCySKvGVUGJXly X-Received: by 2002:a17:906:341a:b0:931:de76:c2e8 with SMTP id c26-20020a170906341a00b00931de76c2e8mr34227481ejb.9.1680375513753; Sat, 01 Apr 2023 11:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680375513; cv=none; d=google.com; s=arc-20160816; b=dAmcA66TQ4cIgYcpjAt8KYYro7vmmT6rKyviCkB5H5XAmHDu+e6h8IADzRQR29wckw Reh6hy+ZC4WknO1h4bI2r1qcb/W7jeawE1duMOv268TLlBKsPWF+zt3EvG3BFeYVjP5+ K4MH9FJjLnFEd84eI2uXAPJxO+6i1VAIkTNsjuvAytONYSOOv+OA5QIk3H3IF9vEDyUf +9kAhjQ4LoTmIjnmYfDhD9HPjKFPHPxpo9nZWvsDtDBa2vR1I/Qnv9lt+NIvKJzLfMOl V9dfI0uz2p/YvDGKBb9NgoiP+SWXkNwwkwIZagJm9bMWXuUSenOr0fSypeW2T4PCBMWY eklw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=NzdlQHPf2ubVQgJ2HZpDAwS0DtAbvUSrLwWN7up3J78=; b=mmsHB98HunMuQan7Wh5NnUSJeyD+IDtDz8OaqOiqus4rrDgmW8oCrKv0g4RnmsrVY7 ++U6aTb0SuH7iUbQP2o1OYbNZOe/XmdbCGos/0ju++YyhD6Ul9da9r9C5VRNoCfsgpRD zra8GexAarMaHr9Bxstg8wHWYx4Mfyqa+AuEOuSVCKcqG/LTK/Je+4WwNkNWPtmdoRvd IKBTf25yChxAgbJ1q75htCYb55txIKmKCNRPePYmFHVWzxk8Pjo70DW7s627q1X9fmDX AaUQqvW6I9WHHj+nr3UEd4mAtcq7SPQabtN+jFvrnPlYnoM0qoYpaqgMhKxcspTxzOa/ CUcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@squebb.ca header.s=fm3 header.b=KZmKcnlK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=t2fNE5E2; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a1709064c8400b0093b83e8dc21si4841407eju.26.2023.04.01.11.58.09; Sat, 01 Apr 2023 11:58:33 -0700 (PDT) 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=@squebb.ca header.s=fm3 header.b=KZmKcnlK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=t2fNE5E2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229887AbjDASoI (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Sat, 1 Apr 2023 14:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjDASoD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 1 Apr 2023 14:44:03 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85A857694; Sat, 1 Apr 2023 11:44:02 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6DF2F3200917; Sat, 1 Apr 2023 14:43:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 01 Apr 2023 14:44:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squebb.ca; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1680374639; x= 1680461039; bh=NzdlQHPf2ubVQgJ2HZpDAwS0DtAbvUSrLwWN7up3J78=; b=K ZmKcnlKnb0ftNbtcdgOmgHNqT8d/XGAe2faoivoB1BBEy55hWKpJQuJoxH31Alm+ xoRiATcwAFyAtjHFNqkw6o88CW/qvKOeqoqmzI0Rggdr3eeh++6oR2Lao+ZXT+v+ jlv8KNKTW3/RRSd8UvNQwFmKWKo+qGoWOi04orMKzfGTCLSE0JdbElBjQBsI8LIe NwFH+tr4Wt6jCNuBzoPrlzby4MKM5Ea7GRLKpw7dK7QHsqenOKslXVXQSJQYUaGw R7JsJtLdTLssjuLgf3P+uuLfAfbRpsV3PgpUchlrhi/vp7x5pxV5VO95CmysCU4t 8oNqCNzON6rEhz3xW89MA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1680374639; x= 1680461039; bh=NzdlQHPf2ubVQgJ2HZpDAwS0DtAbvUSrLwWN7up3J78=; b=t 2fNE5E2ltcsimc1VKb+onhUveuswjjEQU7FjkEr25UdU6EqTYBBELWlhJjbUWl48 zgMEFep6KmlMU2afC8NyT6NzSs+AqMi5o/EEYJ0iypvs76sIv2y4grBveVCR/Pdl 3k85sYzGmEsNsD0UB0xWmxLz1xSgOrLM8dSwzHbn5upYx8HkPiUnOJA/pE2D0VJi cyI6swUtjJLzXpQOQAqRjGvu/Y+ktHBHILX6OLVQ+UbcLaE5+Qy9qje2ILxERvfw 3Jp+dfL20i2vx/ZifgC0X3lUOuiURBdM/gBPeVnQP+zblI4T/7iGPlYrzjWrrNAH uDYIidAjq8vseVdd+a36A== X-ME-Sender: <xms:bnsoZP2z0bWNRqpQoUyvhsMxJieqMsSYhOXGXXJnsnQrkFBLzJB14A> <xme:bnsoZOEMMW0w_BNjol2trzUBmiiuN49OLdULd6iTJ-gX2BBZoD51t3ITB0SV4I38- bKJNhMKxw75SJ0ESWw> X-ME-Received: <xmr:bnsoZP75QIRWD9ACwImVObEu7F3V7WDbIgGX-SNUEJ7ESUKWuy_qayjX9y3PU6T8BsttkxGaXmmBSEq1VFmSK7Z6I6z68FQgmUrqjOz0NK_Vh9lzJHZ91u_q5gDpwOTj4wVf4Dlbsw> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeifedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecuogetfedtuddqtdduucdludehmdenucfjughrpe fhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcurfgvrghr shhonhcuoehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggrqeenucggtf frrghtthgvrhhnpeevtdelgfeggfejtedtvdfgkefhuefguedtkeeffeduueduvdeiuedt leejvdfhvdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhpvggrrhhsohhnqdhlvghnohhv ohesshhquhgvsggsrdgtrg X-ME-Proxy: <xmx:bnsoZE0RUK-n8PIfOEvzGusFjBuzRQjyOCmkPWTpR-RH_MOaXXx-MA> <xmx:bnsoZCFQ4okyi5UhpnAq2C3dgkHJVP4P3sgRn-4fAeZmQdkH6mfM3g> <xmx:bnsoZF9grAbxCRjFOnlAFwmrVj3BHwnuiIoJJwtpGuBZTs6zSRqXVQ> <xmx:b3soZF2R60Md8j-4HPGX53t6EWfjiR8p1cwvrApqOcdADoZZXl01-Q> Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 1 Apr 2023 14:43:57 -0400 (EDT) From: Mark Pearson <mpearson-lenovo@squebb.ca> To: mpearson-lenovo@squebb.ca Cc: hdegoede@redhat.com, markgross@kernel.org, W_Armin@gmx.de, mirsad.todorovac@alu.unizg.hr, linux@weissschuh.net, Mario.Limonciello@amd.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Date: Sat, 1 Apr 2023 14:43:44 -0400 Message-Id: <20230401184345.208960-1-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.39.2 In-Reply-To: <mpearson-lenovo@squebb.ca> References: <mpearson-lenovo@squebb.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762001434607235746?= X-GMAIL-MSGID: =?utf-8?q?1762001434607235746?= |
Series |
[1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
|
|
Commit Message
Mark Pearson
April 1, 2023, 6:43 p.m. UTC
My previous commit introduced a memory leak where the item allocated
from tlmi_setting was not freed.
This commit also renames it to avoid confusion with the similarly name
variable in the same function.
Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation")
Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
This patch series builds on top of the proposed patch from Armin Wolf
"platform/x86: think-lmi: Fix memory leak when showing current settings"
drivers/platform/x86/think-lmi.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
On 4/1/23 13:43, Mark Pearson wrote: > My previous commit introduced a memory leak where the item allocated > from tlmi_setting was not freed. > This commit also renames it to avoid confusion with the similarly name > variable in the same function. > > Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation") > Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr> > Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/ > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca> > --- > This patch series builds on top of the proposed patch from Armin Wolf > "platform/x86: think-lmi: Fix memory leak when showing current settings" Which version of the patch did you do it from? I tried to apply v3 of Armin's patch to Linus' tree and then apply these two. The first applied, but the second had conflicts. Here was my base (with patch 1 in this series applied). 50c77e3211d7 (HEAD -> master) platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings ede629af1e2c platform/x86: think-lmi: Fix memory leak when showing current settings 00c7b5f4ddc5 (origin/master, origin/HEAD) Merge tag 'input-for-v6.3-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input ...... Applying: platform/x86: think-lmi: Clean up display of current_value on Thinkstation error: patch failed: drivers/platform/x86/think-lmi.c:931 error: drivers/platform/x86/think-lmi.c: patch does not apply > drivers/platform/x86/think-lmi.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c > index 88da7bcb6ce9..ad952b49617b 100644 > --- a/drivers/platform/x86/think-lmi.c > +++ b/drivers/platform/x86/think-lmi.c > @@ -1459,10 +1459,10 @@ static int tlmi_analyze(void) > * name string. > * Try and pull that out if it's available. > */ > - char *item, *optstart, *optend; > + char *optitem, *optstart, *optend; > > - if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) { > - optstart = strstr(item, "[Optional:"); > + if (!tlmi_setting(setting->index, &optitem, LENOVO_BIOS_SETTING_GUID)) { > + optstart = strstr(optitem, "[Optional:"); > if (optstart) { > optstart += strlen("[Optional:"); > optend = strstr(optstart, "]"); > @@ -1471,6 +1471,7 @@ static int tlmi_analyze(void) > kstrndup(optstart, optend - optstart, > GFP_KERNEL); > } > + kfree(optitem); > } > } > /*
Hi Mario On Sun, Apr 2, 2023, at 10:04 AM, Mario Limonciello wrote: > On 4/1/23 13:43, Mark Pearson wrote: > >> My previous commit introduced a memory leak where the item allocated >> from tlmi_setting was not freed. >> This commit also renames it to avoid confusion with the similarly name >> variable in the same function. >> >> Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation") >> Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr> >> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/ >> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca> >> --- >> This patch series builds on top of the proposed patch from Armin Wolf >> "platform/x86: think-lmi: Fix memory leak when showing current settings" > > Which version of the patch did you do it from? I tried to apply v3 of > Armin's patch > to Linus' tree and then apply these two. > > The first applied, but the second had conflicts. Here was my base (with > patch 1 in > this series applied). I was using v2 - but there shouldn't be any code changes between v3 and v2....so I hadn't re-based. I'm working in the fixes branch from pdx86.git (with the aim of making it easier for Hans to pull in the patches). It's possible I've goofed somehow...though not sure how :( I'll go double check - but likely won't be until tomorrow I'm afraid. I should probably just wait for the patch to be accepted and then work from there.... Mark
On 4/2/2023 14:23, Mark Pearson wrote: > Hi Mario > > On Sun, Apr 2, 2023, at 10:04 AM, Mario Limonciello wrote: >> On 4/1/23 13:43, Mark Pearson wrote: >> >>> My previous commit introduced a memory leak where the item allocated >>> from tlmi_setting was not freed. >>> This commit also renames it to avoid confusion with the similarly name >>> variable in the same function. >>> >>> Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation") >>> Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr> >>> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/ >>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca> >>> --- >>> This patch series builds on top of the proposed patch from Armin Wolf >>> "platform/x86: think-lmi: Fix memory leak when showing current settings" >> >> Which version of the patch did you do it from? I tried to apply v3 of >> Armin's patch >> to Linus' tree and then apply these two. >> >> The first applied, but the second had conflicts. Here was my base (with >> patch 1 in >> this series applied). > > I was using v2 - but there shouldn't be any code changes between v3 and v2....so I hadn't re-based. > > I'm working in the fixes branch from pdx86.git (with the aim of making it easier for Hans to pull in the patches). It's possible I've goofed somehow...though not sure how :( > > I'll go double check - but likely won't be until tomorrow I'm afraid. I should probably just wait for the patch to be accepted and then work from there.... > > Mark Hmm, I just tried on platform-x86/for-next. commit e3271a5917d1501089b1a224d702aa053e2877f4 (tag: platform-drivers-x86-v6.3-4, platform-x86/fixes) I get the same problem there. I just applied Armin's single v3 patch and then tried your series.
On Sun, Apr 2, 2023, at 6:17 PM, Limonciello, Mario wrote: > On 4/2/2023 14:23, Mark Pearson wrote: >> Hi Mario >> >> On Sun, Apr 2, 2023, at 10:04 AM, Mario Limonciello wrote: >>> On 4/1/23 13:43, Mark Pearson wrote: >>> >>>> My previous commit introduced a memory leak where the item allocated >>>> from tlmi_setting was not freed. >>>> This commit also renames it to avoid confusion with the similarly name >>>> variable in the same function. >>>> >>>> Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation") >>>> Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr> >>>> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/ >>>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca> >>>> --- >>>> This patch series builds on top of the proposed patch from Armin Wolf >>>> "platform/x86: think-lmi: Fix memory leak when showing current settings" >>> >>> Which version of the patch did you do it from? I tried to apply v3 of >>> Armin's patch >>> to Linus' tree and then apply these two. >>> >>> The first applied, but the second had conflicts. Here was my base (with >>> patch 1 in >>> this series applied). >> >> I was using v2 - but there shouldn't be any code changes between v3 and v2....so I hadn't re-based. >> >> I'm working in the fixes branch from pdx86.git (with the aim of making it easier for Hans to pull in the patches). It's possible I've goofed somehow...though not sure how :( >> >> I'll go double check - but likely won't be until tomorrow I'm afraid. I should probably just wait for the patch to be accepted and then work from there.... >> >> Mark > > Hmm, I just tried on platform-x86/for-next. > commit e3271a5917d1501089b1a224d702aa053e2877f4 (tag: > platform-drivers-x86-v6.3-4, platform-x86/fixes) > > I get the same problem there. I just applied Armin's single v3 patch > and then tried your series. You're absolutely right...it doesn't apply if I start again from clean. I have no idea why - it must have been something I did when applying the patch in the first place but I'm at a loss as to what. Urgh :( I'm regenerating the patch and will resend as a v2. Just going to run some tests as a sanity check first. Mark
diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 88da7bcb6ce9..ad952b49617b 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -1459,10 +1459,10 @@ static int tlmi_analyze(void) * name string. * Try and pull that out if it's available. */ - char *item, *optstart, *optend; + char *optitem, *optstart, *optend; - if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) { - optstart = strstr(item, "[Optional:"); + if (!tlmi_setting(setting->index, &optitem, LENOVO_BIOS_SETTING_GUID)) { + optstart = strstr(optitem, "[Optional:"); if (optstart) { optstart += strlen("[Optional:"); optend = strstr(optstart, "]"); @@ -1471,6 +1471,7 @@ static int tlmi_analyze(void) kstrndup(optstart, optend - optstart, GFP_KERNEL); } + kfree(optitem); } } /*