From patchwork Mon Oct 24 11:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp535349wru; Mon, 24 Oct 2022 09:12:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4LM5CWvRIBSE9VmKYJknE5lu1B15TA/UWqwgNFv3FdPUvrxWR+dyagmUAFvELd38X/1kIt X-Received: by 2002:a17:902:f641:b0:17f:3633:5439 with SMTP id m1-20020a170902f64100b0017f36335439mr34450470plg.94.1666627965416; Mon, 24 Oct 2022 09:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627965; cv=none; d=google.com; s=arc-20160816; b=pBTM+7n27NLIJZ8XdrzM/nIkWKAHawYDB8DnzE00JYjazNmJKBSZqL6Dui3qTTaPzT A1zSn0lcNPuM+nSgRzdz7IOo0Tb0tKB5L1pdt7uiJhd5jOOLz4+ddBhlgHN6IscYhuHH c1wYoSagn49ptjhFCX9zx7aAJcpoPsbgjEKJy/zFdUInMDkiZnsgjbcILSu9Gdm0jqxS iBrFtMPJnnDPjoyYGEE7YJn+D5Me230/O8pFm5/Sp/Jn+fctp9rFAXVYf5AmecjKSgtB 7Hqzd0MOUYvNbvTzOjQt2gdZKPvL46PlJwxYxHVqxcbXtthFOgryqbqMQlEIkmPqASm7 q2Ig== 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=dk5jQqtk42/C5itRBtmtSqDLPQwDM2hZ6xYvUfrq/bc=; b=X1csvuENX28JMusgjh8xrTHPWP+4A1/FmRixz/6YyQ3hbq/WZzo2VprZbFXRXU+hx9 g/nJMclQ1Kzs+o7cSp6fwepVumq6CYwziVv0uBpVnfR8p1D/Vkof3cD0WmEwjDhHs93p utws+IACN8vUjaaS8EzqRW6Z8UTbVYTrg+ft3aKjlR9dJFV1pIcXncpPuFuYvbG/8q7Y nur/e13SOITi9kwsRjebvvfZYA3KqRsRDaB2Uy0rLGdieyXhHl2EU2B0I/Q0HhPYRlce r1VVHp4oBB2jOopTcDsZisthTxnoHQG6QcBFdE6yb3uwf55ffRSmQUWtFaIT8UJZG9IV mmrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M6Tn6CcT; 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 n9-20020a1709026a8900b001869cf73143si5697707plk.314.2022.10.24.09.12.31; Mon, 24 Oct 2022 09:12:45 -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=M6Tn6CcT; 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 S233807AbiJXQLv (ORCPT + 99 others); Mon, 24 Oct 2022 12:11:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbiJXQFQ (ORCPT ); Mon, 24 Oct 2022 12:05:16 -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 432194AD7F; Mon, 24 Oct 2022 07:58:14 -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 C1D10B81624; Mon, 24 Oct 2022 12:22:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21091C433D7; Mon, 24 Oct 2022 12:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614158; bh=Pi/zFYzeScmvLHTWHB3Cs3gpauAj1fhVi7HrqIamsfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M6Tn6CcTpnCH03vx21JUG50fMwpOO4q2ksf92diHmD8FKrnv8ZiuPWZLHq3nhrC28 8mf2EWoMUjpSaRt9lEJmh9K6/V/x5e7rawHwKYBMprx4LMlIFKDlFY6/Q8I67j9EYo /4X9pyLkTpQfi74hIF8fP1nY9hPoSof7q3iD3R0w= 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.10 147/390] platform/chrome: fix double-free in chromeos_laptop_prepare() Date: Mon, 24 Oct 2022 13:29:04 +0200 Message-Id: <20221024113028.948809916@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747586085406768815?= X-GMAIL-MSGID: =?utf-8?q?1747586085406768815?= 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 472a03daa869..109c191d35cf 100644 --- a/drivers/platform/chrome/chromeos_laptop.c +++ b/drivers/platform/chrome/chromeos_laptop.c @@ -718,6 +718,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; @@ -726,17 +727,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); @@ -754,16 +753,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; }