platform/x86: hp-bioscfg: Fix some memory leaks in hp_populate_enumeration_elements_from_package()
Message ID | 9770122e4e079dfa87d860ed86ba1a1237bcf944.1689627201.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1349315vqt; Mon, 17 Jul 2023 14:17:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlG9j2TJGWrciCwmDQEh+mSKN0O/Ov5/40SM0ThDnIUx54BYBwMfynOqiFK7+vo8/Urq1qUc X-Received: by 2002:a9d:4e85:0:b0:6b8:7c43:50ac with SMTP id v5-20020a9d4e85000000b006b87c4350acmr12732430otk.21.1689628630536; Mon, 17 Jul 2023 14:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689628630; cv=none; d=google.com; s=arc-20160816; b=OLK/99Il3PXkWUo4EkRQzkRMusWflngVp6XH1tovlwsa5qDLkaeTMlyP28GplYJ9Ab qHWF18ux8DCEU77GT5w9EtRHIeaP9+miwiLfAyeX6CsRvZI0EtZpkP39gN2OtTJx+HXx RQwhf2l22QHHutWZOzeRFba35E+qi/bAEZi6S+9m4LRM+VPoMudZ75vwBiLzcYC5rGZa P1sQUEyvgvTqtdeIjlvgDHxHp54RF7UbNavq4f7r7DaaQXD1QLRCzau11XVT3mhkgJYX VmvFUrRiOW4k09W6/CdX8uxizh6o8OZDaffeT4fqcqAlCnC+2w7z2DV9D6K8AqiA7kW+ wH5w== 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; bh=gH/CT643ZS5ZguiPFDy4NfnRiWDoPJy5TfU7apbBTY4=; fh=3kO181L50Qcr0y55afcdcyD39TL/YS79tVW5ZtpSGcY=; b=ZKlTOGJ+kkzOcbVKqxVKGgvkUHY+xZzao+q6oFv2/tBl5qGTYr5plqs25Uib3/WtdT e90viDkPbUK6+YIYdDdRPtCTyEDBRKKbJ4u6yoMp4If4eu8JNMTfCULGTSWWqidEO2m2 OybRY5pTIaNdtmwT2h3ubcY3oPOx7o4e9SAgTVXZkdE2yvukLJHZdbQ+WdiEdlebJ+ew NBAhnkcNmp7WhRBxrrgFK9X+sFXZo2fnOxrVQTlRvWS6ZzNn/bdfivJAkQV1vO3EJS5O H2UYQkuSuDWQbaFR7NkfHYOZDaz1jd5Reebc7tBDiEL6VU37BVZasyLumKIpgK2uJAl/ vVVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=EUxW+eBq; 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 n11-20020a63ee4b000000b0054fe295d487si374516pgk.434.2023.07.17.14.16.57; Mon, 17 Jul 2023 14:17:10 -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=@wanadoo.fr header.s=t20230301 header.b=EUxW+eBq; 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 S231294AbjGQUxt (ORCPT <rfc822;hadasmailinglist@gmail.com> + 99 others); Mon, 17 Jul 2023 16:53:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbjGQUxo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Jul 2023 16:53:44 -0400 Received: from smtp.smtpout.orange.fr (smtp-23.smtpout.orange.fr [80.12.242.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CD29BB for <linux-kernel@vger.kernel.org>; Mon, 17 Jul 2023 13:53:43 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id LVDvqk82e2ts4LVDvqgmhS; Mon, 17 Jul 2023 22:53:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689627221; bh=gH/CT643ZS5ZguiPFDy4NfnRiWDoPJy5TfU7apbBTY4=; h=From:To:Cc:Subject:Date; b=EUxW+eBqx0/fwJQ4mgi6TBoMfh2JIImC5lXvo4ECT562e2t/Pe25+tCgrwogyu7TW 34f6skb/GVFv9oRX95oCPkM0o2XzJilSzDsFzjB1pxM5q5vqzomhi3fAB8d11h4DZZ pCrsK4Yfm2hSz5L8D6b8Jr7olrJgiBMFaG7u3OwMHbV6O6PJB8A20qLxtd1W3gb54U HZ2WLgmx7vG9PuCOHL8HjbZA+ROG2YNwNWJ3W3vHS9FSaWu12UXGVvMhRKND0vNznj swWYgfwcqIjMRk9ADNPg6mER/KqK0vCheGn94fEkkwiHqm/Bfi53yE+gW5QQarZhCa TvcXmXOrFSYaw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 17 Jul 2023 22:53:41 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Jorge Lopez <jorge.lopez2@hp.com>, Hans de Goede <hdegoede@redhat.com>, Mark Gross <markgross@kernel.org>, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, platform-driver-x86@vger.kernel.org Subject: [PATCH] platform/x86: hp-bioscfg: Fix some memory leaks in hp_populate_enumeration_elements_from_package() Date: Mon, 17 Jul 2023 22:53:37 +0200 Message-Id: <9770122e4e079dfa87d860ed86ba1a1237bcf944.1689627201.git.christophe.jaillet@wanadoo.fr> 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,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771704030740438967 X-GMAIL-MSGID: 1771704030740438967 |
Series |
platform/x86: hp-bioscfg: Fix some memory leaks in hp_populate_enumeration_elements_from_package()
|
|
Commit Message
Christophe JAILLET
July 17, 2023, 8:53 p.m. UTC
In the loop in the ENUM_POSSIBLE_VALUES case, we allocate some memory that
is never freed.
While at it, add some "str_value = NULL" to avoid some potential double
free.
Fixes: 6b2770bfd6f9 ("platform/x86: hp-bioscfg: enum-attributes")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
/!\ Speculative /!\
This patch is based on analysis of the surrounding code and should be
reviewed with care !
/!\ Speculative /!\
---
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
On Mon, Jul 17, 2023 at 10:53:37PM +0200, Christophe JAILLET wrote: > In the loop in the ENUM_POSSIBLE_VALUES case, we allocate some memory that > is never freed. > > While at it, add some "str_value = NULL" to avoid some potential double > free. > > Fixes: 6b2770bfd6f9 ("platform/x86: hp-bioscfg: enum-attributes") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > /!\ Speculative /!\ > > This patch is based on analysis of the surrounding code and should be > reviewed with care ! > > /!\ Speculative /!\ I reported these bugs yesterday. I don't think this is the correct fix. I thought about making the str_value local to the for loop. That's sort of like what your patch does. But I wasn't sure that was necessarily correct either. This code needs more testing as well. It seems no one has called this function. Smatch complained about uninitialized variables as well. I didn't bother to report that yesterday but I may as well. regards, dan carpenter drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:188 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:191 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:194 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:197 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:200 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:239 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:242 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:245 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:192 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:195 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:198 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:201 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:204 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:238 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:242 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:262 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'value_len'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:198 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:201 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:204 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:207 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:246 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:249 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:252 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:255 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:180 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:183 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:186 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:189 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:192 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:231 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:239 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:279 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:282 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:285 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:288 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:291 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:324 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:327 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:330 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:333 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:362 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'.
Le 18/07/2023 à 09:55, Dan Carpenter a écrit : > On Mon, Jul 17, 2023 at 10:53:37PM +0200, Christophe JAILLET wrote: >> In the loop in the ENUM_POSSIBLE_VALUES case, we allocate some memory that >> is never freed. >> >> While at it, add some "str_value = NULL" to avoid some potential double >> free. >> >> Fixes: 6b2770bfd6f9 ("platform/x86: hp-bioscfg: enum-attributes") >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> >> --- >> /!\ Speculative /!\ >> >> This patch is based on analysis of the surrounding code and should be >> reviewed with care ! >> >> /!\ Speculative /!\ > > I reported these bugs yesterday. Ok, seen now... ... but I don't read platform-driver-x86@vger.kernel.org :) CJ > I don't think this is the correct fix. > I thought about making the str_value local to the for loop. That's sort > of like what your patch does. But I wasn't sure that was necessarily > correct either. > > This code needs more testing as well. It seems no one has called this > function. > > Smatch complained about uninitialized variables as well. I didn't > bother to report that yesterday but I may as well. > > regards, > dan carpenter > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:188 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:191 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:194 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:197 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:200 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:239 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:242 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:245 hp_populate_string_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:192 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:195 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:198 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:201 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:204 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:238 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:242 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:262 hp_populate_ordered_list_elements_from_package() error: uninitialized symbol 'value_len'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:198 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:201 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:204 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:207 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:246 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:249 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:252 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:255 hp_populate_integer_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:180 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:183 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:186 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:189 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:192 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:231 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:239 hp_populate_enumeration_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:279 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:282 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:285 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:288 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:291 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:324 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:327 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:330 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:333 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:362 hp_populate_password_elements_from_package() error: uninitialized symbol 'int_value'. >
Hi Christophe, I will submit a patch to address memory leaks in hp_populate_enumeration_elements_from_package() reported here and to address some uninitialized variable errors reported in a separate email. Regards, Jorge Lopez HP Inc "Once you stop learning, you start dying" Albert Einstein > -----Original Message----- > From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > Sent: Monday, July 17, 2023 3:54 PM > To: Lopez, Jorge A (Security) <jorge.lopez2@hp.com>; Hans de Goede > <hdegoede@redhat.com>; Mark Gross <markgross@kernel.org>; Thomas > Weißschuh <linux@weissschuh.net> > Cc: linux-kernel@vger.kernel.org; kernel-janitors@vger.kernel.org; > Christophe JAILLET <christophe.jaillet@wanadoo.fr>; platform-driver- > x86@vger.kernel.org > Subject: [PATCH] platform/x86: hp-bioscfg: Fix some memory leaks in > hp_populate_enumeration_elements_from_package() > > CAUTION: External Email > > In the loop in the ENUM_POSSIBLE_VALUES case, we allocate some memory > that is never freed. > > While at it, add some "str_value = NULL" to avoid some potential double > free. > > Fixes: 6b2770bfd6f9 ("platform/x86: hp-bioscfg: enum-attributes") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > /!\ Speculative /!\ > > This patch is based on analysis of the surrounding code and should be > reviewed with care ! > > /!\ Speculative /!\ > --- > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c > b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c > index b1b241f0205a..dd173020c747 100644 > --- a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c > +++ b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c > @@ -224,6 +224,7 @@ static int > hp_populate_enumeration_elements_from_package(union acpi_object > *enum > sizeof(enum_data->common.prerequisites[reqs])); > > kfree(str_value); > + str_value = NULL; > } > break; > > @@ -275,6 +276,9 @@ static int > hp_populate_enumeration_elements_from_package(union acpi_object > *enum > strscpy(enum_data->possible_values[pos_values], > str_value, > sizeof(enum_data- > >possible_values[pos_values])); > + > + kfree(str_value); > + str_value = NULL; > } > break; > default: > @@ -283,6 +287,7 @@ static int > hp_populate_enumeration_elements_from_package(union acpi_object > *enum > } > > kfree(str_value); > + str_value = NULL; > } > > exit_enumeration_package: > -- > 2.34.1
Hi Christophe, I will submit individual patches to address memory leaks and uninitialized variable errors for each source file listed below. > hp_populate_string_elements_from_package drivers/platform/x86/hp/hp-bioscfg/string-attributes.c > hp_populate_ordered_list_elements_from_package() drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c > hp_populate_integer_elements_from_package() drivers/platform/x86/hp/hp-bioscfg/int-attributes.c > hp_populate_enumeration_elements_from_package() drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c > hp_populate_password_elements_from_package() drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c Regards, Jorge Lopez HP Inc “Once you stop learning, you start dying” Albert Einstein > -----Original Message----- > From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > Sent: Tuesday, July 18, 2023 12:37 PM > To: Dan Carpenter <dan.carpenter@linaro.org> > Cc: Lopez, Jorge A (Security) <jorge.lopez2@hp.com>; Hans de Goede > <hdegoede@redhat.com>; Mark Gross <markgross@kernel.org>; Thomas > Weißschuh <linux@weissschuh.net>; linux-kernel@vger.kernel.org; kernel- > janitors@vger.kernel.org; platform-driver-x86@vger.kernel.org > Subject: Re: [PATCH] platform/x86: hp-bioscfg: Fix some memory leaks in > hp_populate_enumeration_elements_from_package() > > CAUTION: External Email > > Le 18/07/2023 à 09:55, Dan Carpenter a écrit : > > On Mon, Jul 17, 2023 at 10:53:37PM +0200, Christophe JAILLET wrote: > >> In the loop in the ENUM_POSSIBLE_VALUES case, we allocate some > memory > >> that is never freed. > >> > >> While at it, add some "str_value = NULL" to avoid some potential > >> double free. > >> > >> Fixes: 6b2770bfd6f9 ("platform/x86: hp-bioscfg: enum-attributes") > >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > >> --- > >> /!\ Speculative /!\ > >> > >> This patch is based on analysis of the surrounding code and should be > >> reviewed with care ! > >> > >> /!\ Speculative /!\ > > > > I reported these bugs yesterday. > > Ok, seen now... > ... but I don't read platform-driver-x86@vger.kernel.org :) > > CJ > > > I don't think this is the correct fix. > > I thought about making the str_value local to the for loop. That's > > sort of like what your patch does. But I wasn't sure that was > > necessarily correct either. > > > > This code needs more testing as well. It seems no one has called this > > function. > > > > Smatch complained about uninitialized variables as well. I didn't > > bother to report that yesterday but I may as well. > > > > regards, > > dan carpenter > > > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:188 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:191 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:194 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:197 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:200 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:239 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:242 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/string-attributes.c:245 > hp_populate_string_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:192 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:195 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:198 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:201 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:204 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:238 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:242 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c:262 > hp_populate_ordered_list_elements_from_package() error: uninitialized > symbol 'value_len'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:198 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:201 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:204 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:207 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:246 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:249 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:252 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/int-attributes.c:255 > hp_populate_integer_elements_from_package() error: uninitialized symbol > 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:180 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:183 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:186 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:189 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:192 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:231 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c:239 > hp_populate_enumeration_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:279 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:282 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:285 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:288 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:291 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:324 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:327 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:330 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:333 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > > drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c:362 > hp_populate_password_elements_from_package() error: uninitialized > symbol 'int_value'. > >
diff --git a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c index b1b241f0205a..dd173020c747 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c @@ -224,6 +224,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum sizeof(enum_data->common.prerequisites[reqs])); kfree(str_value); + str_value = NULL; } break; @@ -275,6 +276,9 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum strscpy(enum_data->possible_values[pos_values], str_value, sizeof(enum_data->possible_values[pos_values])); + + kfree(str_value); + str_value = NULL; } break; default: @@ -283,6 +287,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum } kfree(str_value); + str_value = NULL; } exit_enumeration_package: