Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2521858lqp; Mon, 25 Mar 2024 01:00:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrblIB7NxlN0oIPFcA4KTqhX2iadLbLgZiWPFesGUYWfGwDnGaUD8na7YFh6oY3YL8Hfs8u+ENw9GHzeVMspu0OEddDMHraAP/QG6qtA== X-Google-Smtp-Source: AGHT+IFWZQsZi1aGlCbz6i455Zms4Obotob37gMxoWjNjZ7MWzGmYO/yJ5HZAqLlEKd7u28LZrQt X-Received: by 2002:ac8:5ac1:0:b0:431:57e:d205 with SMTP id d1-20020ac85ac1000000b00431057ed205mr7792189qtd.58.1711353624171; Mon, 25 Mar 2024 01:00:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711353624; cv=pass; d=google.com; s=arc-20160816; b=qs6VU4rWvhFzZqSckS6QJhHDhN2Chv4r51HtQO6GqTrS5sqTaae0cfmS6+A2fqj/Kv E0S76ZW++47R8C3UXngZjs7CADW0gTJLk1LtohnGJrRhF0LBHpaMxiB7529Ky1H/JRjc +8FJkU9t20kRF2CxZmk6TThjPkEFekTdBcsrt4t2c9t4eqjYk/FBf4kaHbiU4BcxZreL jJlM5N/JSJ4rBhV1GEqKBxnaQgoGmtAwrzDLSKiA//MHKssXPIxON8LCrh1/p1rg4m/v wFCcQqN5BbhOnn2FpjyNVpGUzkPeRN2RdhmI1ZxViVY5MPYK2dsEg02LRA8wDprrx4hz 8osQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0KIryT9Z1nAcW7obfCqsTjNEKFB5bBdTI4Tw7nlcUVA=; fh=EI9KM0AmDYvHA7jghHiLra8DhUeG3ic2hqNnze8w5tg=; b=1GUBOGFBGKpkkRuK3/ZsCTZtfLGV/01kGpCCwY4iNksDqOFJ9V6FRcw25sigfdUnHu YjPPvDDuIuBOVkz5SVxoAU6yQSGTtYLOsV/Rmh0YSDpZ2a7S7TpelSl62DbevCHal1+H EWyfD5LbpU+r7szTtjviHLEmMyQ+Lij/H05hsFLf8uVmUoR4rCVS6ywDzBwd5Vek4VBd toMyFGTf6j2zICJEWCIgY3tbeGCz+sDIPNejjlOJyBJbNrnFIr9arJuw4lgstVV0vJYE KmtWClnDPaWvtqfBnNnlCheAXzCDtoQD/SlLgYKy7s7XXSGQxd+jc+fykLG/Gt3I6tgm xXdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sDC9DAc5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115710-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115710-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w1-20020a05622a190100b00430d7881964si4788786qtc.671.2024.03.25.01.00.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 01:00:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115710-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sDC9DAc5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115710-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115710-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3D8341C2F328 for ; Mon, 25 Mar 2024 08:00:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 203A715B991; Mon, 25 Mar 2024 02:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sDC9DAc5" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DCAD1EEEF2; Sun, 24 Mar 2024 23:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321745; cv=none; b=qFKea/O02sypilldGmbbDoR/RtxuRWVIpaZz+vw6VomJV1/qcmoSBBdIs9OSrBAKsqQWO4+Dr4gilbApLd+vtG88lglqa9+gW2DOvTKI9cJaUmUTOIecFOHLWfD5NeI1rlypowFe7QwgYTxnRyr3+g7ekJ6Zn8sE43519w4uWPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321745; c=relaxed/simple; bh=6d8vYBUrO4Vbhqa++pTzSboo0d76L1VMT2hA2lPcTZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e1n3MQD+QDYV5H2RAu+PTaFhHgRJskQYwHDSNozHrYOgTh4x46lU5WbDfVrM/wNKVoxIK2J3WWtMNB2EIo+DU0KKxEBcgAnPTFgMIsREZAtfmPm54E5SKfCGITfXnJybHorUdRAw7a4PM3JNuKKfDpJJi7Az/roKRJwU52VQR/k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sDC9DAc5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC5D9C433F1; Sun, 24 Mar 2024 23:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321745; bh=6d8vYBUrO4Vbhqa++pTzSboo0d76L1VMT2hA2lPcTZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sDC9DAc5L8tmj1wKmr/WgwCvsK2uqzGqo94nSB7VQ1uKpPSS0nm94lP3sHBEWzyh9 f2xhmQk3xLx8O7gA9TsaF5bpkLq4b+eTYzNEdWOCgb3qALwODkSeYE9UoIBqRc/dJu TBdvwrBwVqGdgX9OP73MKFTcl4fFrXOrqvd4G/D16eq/YSm5wMegIURzUm6peVRrYF Y7rKIfcPj7DRBCCiLorMJBvL41cZej3/bv9u52rMU0motyJLfxaPBcuf4KnW4g3O3K VN8lj8w3tqu+ro0obAu/p0H0PmVE7Hf5wJLWl2Plvz9C3D517S1IrUWEa+TSP8VNqR 1j5wVrOL4Nx7Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qiheng Lin , Michael Ellerman , Sasha Levin Subject: [PATCH 6.6 473/638] powerpc/pseries: Fix potential memleak in papr_get_attr() Date: Sun, 24 Mar 2024 18:58:30 -0400 Message-ID: <20240324230116.1348576-474-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324230116.1348576-1-sashal@kernel.org> References: <20240324230116.1348576-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Qiheng Lin [ Upstream commit cda9c0d556283e2d4adaa9960b2dc19b16156bae ] `buf` is allocated in papr_get_attr(), and krealloc() of `buf` could fail. We need to free the original `buf` in the case of failure. Fixes: 3c14b73454cf ("powerpc/pseries: Interface to represent PAPR firmware attributes") Signed-off-by: Qiheng Lin Signed-off-by: Michael Ellerman Link: https://msgid.link/20221208133449.16284-1-linqiheng@huawei.com Signed-off-by: Sasha Levin --- arch/powerpc/platforms/pseries/papr_platform_attributes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/pseries/papr_platform_attributes.c b/arch/powerpc/platforms/pseries/papr_platform_attributes.c index 526c621b098be..eea2041b270b5 100644 --- a/arch/powerpc/platforms/pseries/papr_platform_attributes.c +++ b/arch/powerpc/platforms/pseries/papr_platform_attributes.c @@ -101,10 +101,12 @@ static int papr_get_attr(u64 id, struct energy_scale_attribute *esi) esi_buf_size = ESI_HDR_SIZE + (CURR_MAX_ESI_ATTRS * max_esi_attrs); temp_buf = krealloc(buf, esi_buf_size, GFP_KERNEL); - if (temp_buf) + if (temp_buf) { buf = temp_buf; - else - return -ENOMEM; + } else { + ret = -ENOMEM; + goto out_buf; + } goto retry; } -- 2.43.0