Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp883335rwi; Wed, 19 Oct 2022 04:17:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4F8m74cWykjjQaiDFOnIcUhF2QvInjxa/V5eB/5HuM9GqB05rBd6ruzRrgRRxxgpAsS/OR X-Received: by 2002:a17:902:f08c:b0:183:9296:8b65 with SMTP id p12-20020a170902f08c00b0018392968b65mr8230327pla.59.1666178226968; Wed, 19 Oct 2022 04:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178226; cv=none; d=google.com; s=arc-20160816; b=sOp4X0hAnKj3saXizxKk7eiLyCRzJ0y9BSbcc2JYHk+kFmKxSBdJsnjnVxO4zbEaSk F89jJt+bzty11FA/5U8sRs9hRx6Lnxw6fPVMGWXi1/cKEz//R2o1wL5zfrOI7//vLfFj TJ7xhGMQMegsdrpCMLEzk/xoMKTGBx+hE9guxlJ4Rmx+6wHgjYDk8F1N1Mfxd1SJmwNI 6RBCbGh7YgtiEFfrMkBzwwzvtNSi1Wo/zFzqwRAQ5zsHwkvgF+X99TkvPR1XNnIv9qiE 1NxoEXlL0aQX9eSNUMRklFWoZownwREOExCL0ieYaHSLQ9GniZvTfdis7Jg4Tp715aPL Tiog== 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=rTx9YQFTPQDDpCXQMPho8yQUGfd5EU//y1jFmfPtDHQPLjmdENw5Fnv5Ig9xy3KOM+ AV5PaoFNUYwoA8pGlLxivahWsf8aQn3+1QoLqUvmrsXk7m//SefqJuBNRKDFMLGX1/2Z N4AuJbXlXKa+0IgyZkQuzofU6W75DZ5GJvA6f6FfiM96Tcuz1rgARZhWFkPAAKTOanbK OnS4m7z+FC0Ut7e4T2yIMMsbEB5TJByRbif6vCx6qM2Kcl9OYsgPMYk747pBpxh8zRqb upesLQuADoHOZYv3zrwDuYq3mW6V+zYI4cCOMrKcuFxZ6ZKXeuvOGcXlkYPwrWqSNxqB 9t8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RYEFj3sb; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a630a4b000000b0044b8e2abe1csi18747263pgk.170.2022.10.19.04.16.32; Wed, 19 Oct 2022 04:17:06 -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=RYEFj3sb; 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 S232450AbiJSKnh (ORCPT + 99 others); Wed, 19 Oct 2022 06:43:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232523AbiJSKmq (ORCPT ); Wed, 19 Oct 2022 06:42:46 -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 3AF8AD73D2; Wed, 19 Oct 2022 03:20:15 -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 64D9BB82398; Wed, 19 Oct 2022 08:54:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1C6AC433D6; Wed, 19 Oct 2022 08:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169669; bh=fpkRYoZRvDjIHv0uj2UG4gMaTQvdCazIzAKjiv1dqaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RYEFj3sbc4dJ1rCOOjJ8rxyownWi2gDN5dqDTgZ4d8EnsaIYkglJuSvs8cPvW8OxK MlZEj7CUw98R4BeBBkUo82NHRRWmaOM9hkSt50zyJumGhvFw4gXtHr8E/m0Fibb3qR xJVwRlR8sUMUkUDCesm3pj/7CvcyQW9o3Hi5aYcM= 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 6.0 363/862] platform/chrome: fix double-free in chromeos_laptop_prepare() Date: Wed, 19 Oct 2022 10:27:30 +0200 Message-Id: <20221019083306.044452229@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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; } -- 2.35.1