From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sDC9DAc5" 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