From patchwork Sat Oct 22 07:23:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1097128wrr; Sat, 22 Oct 2022 01:06:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5H1jSKfj+qb6fPmzvA5FlcLur2u5aIAwnn7UMxraOVu0tFLSeYGjkmXTJeuxh+h1/VxYLh X-Received: by 2002:a05:6a00:1306:b0:555:6d3f:11ed with SMTP id j6-20020a056a00130600b005556d3f11edmr23280680pfu.55.1666426012731; Sat, 22 Oct 2022 01:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666426012; cv=none; d=google.com; s=arc-20160816; b=GMFtidzh6ucVSpbu+O5A0/CHYyuRZb8Geks0Vj+ZhZ39yBhw91kIxDzWeXfdqzKz74 Ep6xi3u4MYgH8BL011NTiL6PSKGG0yD5T273x9xruqyVTfKc/cNLyn5bdPjHxHfHr9Wl +2NKUPuBSRNvaPaAq2GwV0JwYtYLB6SL5T8KkUmfLg4hqXX834/aUi675GfS2xxe/WIm JfRol9sG10+wLRP0SQJca85NgPdScXmdgrXHiXWLyQx2v3r+JswmQ/TDquxiBc37IWfj 3rqzyvGbPQ7NFXtMlugla5hIeZAuWNQaGsHivI3zLh8RG/P76H6H38jBHOh+sXzxdYZ7 ZHqw== 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=yiJsqhWZ51lv6jSigGqrq4pl8vUIDOOi4yq4AybLCTw=; b=YTKXbOdHtZjJlcgOzuKgA31Am7J8+GGYhzYPojE32q5JTe+I4+cKgni5HsXZvAeU1i FrZ7xS5i6dyeRIOuzaMDHEgIOKZMFpr9QmYdOWGsYcDMowA3w8zzm4J4rn/w2roBgBDP OD2du844OYKQGsh0YUu1Ng3nToziD36tE84Jq/kMCNaUCZV0zHHkUvBf+B7AruuCdMfP XSwgRQoCht0fG5lOFd0mzr4wWMPTs27XIYGV4U+GkHVCW4sDlz8CkoT05DDFosZXCfYp Sn7fpUEB+ypc/T9vK9CGhO0LygcezKOR4gaUBFKKSw4YLJ+tevPKX3wBqZoIjzqkYNWf judg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AhEFL6bA; 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 h8-20020a170902f70800b0017f59ed2dfasi25865171plo.63.2022.10.22.01.06.40; Sat, 22 Oct 2022 01:06:52 -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=AhEFL6bA; 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 S232848AbiJVIGR (ORCPT + 99 others); Sat, 22 Oct 2022 04:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232747AbiJVH7t (ORCPT ); Sat, 22 Oct 2022 03:59:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B50F237DE; Sat, 22 Oct 2022 00:49:58 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0697660AC3; Sat, 22 Oct 2022 07:47:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19E06C433D6; Sat, 22 Oct 2022 07:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424868; bh=fpkRYoZRvDjIHv0uj2UG4gMaTQvdCazIzAKjiv1dqaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AhEFL6bAqKSGqOZDssgTzuQNJFjXG/YgEJl18jrcEN7y2t1sU3QJEKB91sbQ2sSI3 hTcW9oQ/yJOFWN7smjxAVkqHGWsS4sMDMnCaVpfxyDSNGWFlRpwHs02vw4lA23xHll lvtZjP/cNJyioOexGtlj0zeulOpoI/uB36M2qILY= 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 5.19 307/717] platform/chrome: fix double-free in chromeos_laptop_prepare() Date: Sat, 22 Oct 2022 09:23:06 +0200 Message-Id: <20221022072506.971076554@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747374322831231985?= X-GMAIL-MSGID: =?utf-8?q?1747374322831231985?= 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 4e14b4d6635d..a2cdbfbaeae6 100644 --- a/drivers/platform/chrome/chromeos_laptop.c +++ b/drivers/platform/chrome/chromeos_laptop.c @@ -740,6 +740,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; @@ -748,17 +749,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); @@ -775,16 +774,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 (!IS_ERR_OR_NULL(info->fwnode)) fwnode_remove_software_node(info->fwnode); } - kfree(cros_laptop->i2c_peripherals); + kfree(i2c_peripherals); return error; }