From patchwork Mon Oct 24 11:30:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430787wru; Mon, 24 Oct 2022 05:42:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6eRJXL/8enThersG+4hpqaqkEOm7RPsygyfIzGVQNQ+o3bqMdbq23/6fBWgDoOefrnc6Ej X-Received: by 2002:a05:6a00:2303:b0:56b:cd7e:6cb with SMTP id h3-20020a056a00230300b0056bcd7e06cbmr5300405pfh.77.1666615337342; Mon, 24 Oct 2022 05:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615337; cv=none; d=google.com; s=arc-20160816; b=HrJJ55JuhYt/okskEc48s5heCFB6v2qs6PfhDpnpOQralLlzv+iRMtXMGBDlCH0y0e Yy28X2BBD7z6wkySVwTxd7ACeI3wiucy4yeP6n1aprE3IGS75l5tXr3WKWbjeIY23Qpp x7Xp2fVRMX7DA6TF6QHTDWicFppbgvK30sCLj4/7/RE12f1ch3mIHrzMTO7ROPxf2+LC bNZxykAQQCL2FSguSaWs6etbx6BGdjA+92ysFf8pT0Uyk6Q4RnEukTLUnyXNWtdFosTj pIuYFTpGgbbCNBXIQHoPSFqiJp7FPh4C8JFbS95/AIVcQ/AYDa0vag0dB4UwYkJ7FTSV lPzA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7uYPatAW9SteJkyqvwO1+D+mBwdWFGZ5tusNPrMZny0=; b=ffsaq61+zUkBU1KZaBzGyBvDiCW7f3YBazScuWKzNrYgB/1NmEAaa/sEA6otwYJuqG 9RtkA7U1XbpS2pIllGbiT8aP0Dj242owepQ/VyLsymixEmDDcj5XvtM1pybxt0hBmGR7 YF4KjMQxftjQm8rKWK5EmfCTxqCDKjIN3W0NIw953yaRT22X9VRj9Bi1CDZQEPLaJqkU 4p70yJVvyj/8jQ/6p2E8c+SI1HZ2EvCTv1Kbu39ro03+ubkUIBnd+CqqENkG4Lk0KGAH 71D0q/1MgG6jFMxddun7y5EHG6xbVk9sjhq9RDimqDszsB9A1INRMSQ/ItYbBuGCCDNj jSjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="s/Xkn4gW"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oj4-20020a17090b4d8400b001fde53d5d79si10750615pjb.5.2022.10.24.05.42.03; Mon, 24 Oct 2022 05:42:17 -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=@linuxfoundation.org header.s=korg header.b="s/Xkn4gW"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233861AbiJXMbK (ORCPT + 99 others); Mon, 24 Oct 2022 08:31:10 -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 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747572843870661155?= X-GMAIL-MSGID: =?utf-8?q?1747572843870661155?= 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@ispras.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/chrome/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_laptop, 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 chromeos_laptop *cros_laptop, if (!src->num_i2c_peripherals) return 0; - cros_laptop->i2c_peripherals = kmemdup(src->i2c_peripherals, - src->num_i2c_peripherals * - sizeof(*src->i2c_peripherals), - GFP_KERNEL); - if (!cros_laptop->i2c_peripherals) + i2c_peripherals = kmemdup(src->i2c_peripherals, + src->num_i2c_peripherals * + sizeof(*src->i2c_peripherals), + GFP_KERNEL); + if (!i2c_peripherals) return -ENOMEM; - cros_laptop->num_i2c_peripherals = src->num_i2c_peripherals; - - for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) { - i2c_dev = &cros_laptop->i2c_peripherals[i]; + for (i = 0; i < src->num_i2c_peripherals; i++) { + i2c_dev = &i2c_peripherals[i]; info = &i2c_dev->board_info; error = chromeos_laptop_setup_irq(i2c_dev); @@ -752,16 +751,19 @@ chromeos_laptop_prepare_i2c_peripherals(struct chromeos_laptop *cros_laptop, } } + cros_laptop->i2c_peripherals = i2c_peripherals; + cros_laptop->num_i2c_peripherals = src->num_i2c_peripherals; + return 0; err_out: while (--i >= 0) { - i2c_dev = &cros_laptop->i2c_peripherals[i]; + i2c_dev = &i2c_peripherals[i]; info = &i2c_dev->board_info; if (info->properties) property_entries_free(info->properties); } - kfree(cros_laptop->i2c_peripherals); + kfree(i2c_peripherals); return error; }