From nobody Wed Sep 3 05:56:09 2025 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 8680DFA3748 for ; Mon, 24 Oct 2022 12:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbiJXMbL (ORCPT ); Mon, 24 Oct 2022 08:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233892AbiJXM2f (ORCPT ); Mon, 24 Oct 2022 08:28:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E39C87084; Mon, 24 Oct 2022 05:02:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 31361B811F3; Mon, 24 Oct 2022 11:58:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83541C433D7; Mon, 24 Oct 2022 11:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612724; bh=jaNEfKMGPQ1cfaDS8CZOXepZ1pbex2yIiOQ5Fxk2vwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s/Xkn4gWDxWZurV5O5p3vz41t4kGaEG2RP/2lbXr9TGwkoPNpQyywPl4edHQqvWP+ 81eIv/fbqJCG44DuB0TDXPbyBi3XdzwCDvMqBrlZ55ofsPPlR8Sa5NvbI8C/ceZ7NT rsH3WnoOI1KDJLm0DJJc0KUgaddUlgJhGHHJ0WZ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rustam Subkhankulov , Dmitry Torokhov , Tzung-Bi Shih , Sasha Levin Subject: [PATCH 4.19 096/229] platform/chrome: fix double-free in chromeos_laptop_prepare() Date: Mon, 24 Oct 2022 13:30:15 +0200 Message-Id: <20221024113002.146835479@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rustam Subkhankulov [ Upstream commit 6ad4194d6a1e1d11b285989cd648ef695b4a93c0 ] If chromeos_laptop_prepare_i2c_peripherals() fails after allocating memory for 'cros_laptop->i2c_peripherals', this memory is freed at 'err_out' label and nonzero value is returned. Then chromeos_laptop_destroy() is called, resulting in double-free error. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Rustam Subkhankulov Fixes: 5020cd29d8bf ("platform/chrome: chromeos_laptop - supply properties = for ACPI devices") Reviewed-by: Dmitry Torokhov Signed-off-by: Tzung-Bi Shih Link: https://lore.kernel.org/r/20220813220843.2373004-1-subkhankulov@ispra= s.ru Signed-off-by: Sasha Levin --- drivers/platform/chrome/chromeos_laptop.c | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/c= hrome/chromeos_laptop.c index 24326eecd787..096e8e5b2cde 100644 --- a/drivers/platform/chrome/chromeos_laptop.c +++ b/drivers/platform/chrome/chromeos_laptop.c @@ -716,6 +716,7 @@ static int __init chromeos_laptop_prepare_i2c_peripherals(struct chromeos_laptop *cros_lapto= p, const struct chromeos_laptop *src) { + struct i2c_peripheral *i2c_peripherals; struct i2c_peripheral *i2c_dev; struct i2c_board_info *info; int i; @@ -724,17 +725,15 @@ chromeos_laptop_prepare_i2c_peripherals(struct chrome= os_laptop *cros_laptop, if (!src->num_i2c_peripherals) return 0; =20 - cros_laptop->i2c_peripherals =3D kmemdup(src->i2c_peripherals, - src->num_i2c_peripherals * - sizeof(*src->i2c_peripherals), - GFP_KERNEL); - if (!cros_laptop->i2c_peripherals) + i2c_peripherals =3D kmemdup(src->i2c_peripherals, + src->num_i2c_peripherals * + sizeof(*src->i2c_peripherals), + GFP_KERNEL); + if (!i2c_peripherals) return -ENOMEM; =20 - cros_laptop->num_i2c_peripherals =3D src->num_i2c_peripherals; - - for (i =3D 0; i < cros_laptop->num_i2c_peripherals; i++) { - i2c_dev =3D &cros_laptop->i2c_peripherals[i]; + for (i =3D 0; i < src->num_i2c_peripherals; i++) { + i2c_dev =3D &i2c_peripherals[i]; info =3D &i2c_dev->board_info; =20 error =3D chromeos_laptop_setup_irq(i2c_dev); @@ -752,16 +751,19 @@ chromeos_laptop_prepare_i2c_peripherals(struct chrome= os_laptop *cros_laptop, } } =20 + cros_laptop->i2c_peripherals =3D i2c_peripherals; + cros_laptop->num_i2c_peripherals =3D src->num_i2c_peripherals; + return 0; =20 err_out: while (--i >=3D 0) { - i2c_dev =3D &cros_laptop->i2c_peripherals[i]; + i2c_dev =3D &i2c_peripherals[i]; info =3D &i2c_dev->board_info; if (info->properties) property_entries_free(info->properties); } - kfree(cros_laptop->i2c_peripherals); + kfree(i2c_peripherals); return error; } =20 --=20 2.35.1