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 689BB12DD90; Tue, 23 Jan 2024 00:16:19 +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=1705968979; cv=none; b=PokaM2gFxLz/ySHK+KeNoh4zv5t3/15zasQdmcEARudqqH+pWn/X7ebk8xTtb6obuufcBYGKkC1sqGu9Ny11Lw2Ee/Kg8nlX3L8GViirAb7mKP0J7JSXkEBfYllMEXFd/fxHPFtUfyp8g1yXJcWg44XTGL2MzG/KeLtHHnFcapA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705968979; c=relaxed/simple; bh=5e50xMsVTJ4wRDKtCn/pIcLx1kINXQDi7j9XjwxwpYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aCMO2yQDErYbMRd/BbT0TT6LGpuUfEf+NwZUvi1/crd0nup5O+bbXdCDc3KqysNkWRuixCRZrzgylchLoiQtt9EIoKeNA7pHXNuuoFQlDZrSH9XI/GjmDbfKz/RE/8no7X+Kqbe1T0i82k0R1iM1qlchrNnAxmgHXyEDzBYQSPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=i7vBWwFn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="i7vBWwFn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE5AAC433F1; Tue, 23 Jan 2024 00:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705968978; bh=5e50xMsVTJ4wRDKtCn/pIcLx1kINXQDi7j9XjwxwpYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i7vBWwFnv/qEB339CoJCGMojKeiWeTzmXPkoE++WpuMvp4mbVmgL+0DSmyYRCs+Ne NMtQ9QRViLkVmDs/SvDiBjm5uO7c3aUXKKxl/n7bpw/DGTqnXjzwjPIKyVkjfImEZP E250Y8CceqLQQErYjRrOPxAsBGRQqs0dXESCi1Wo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhipeng Lu , Alex Deucher , Sasha Levin Subject: [PATCH 5.4 129/194] drivers/amd/pm: fix a use-after-free in kv_parse_power_table Date: Mon, 22 Jan 2024 15:57:39 -0800 Message-ID: <20240122235724.767800641@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235719.206965081@linuxfoundation.org> References: <20240122235719.206965081@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhipeng Lu [ Upstream commit 28dd788382c43b330480f57cd34cde0840896743 ] When ps allocated by kzalloc equals to NULL, kv_parse_power_table frees adev->pm.dpm.ps that allocated before. However, after the control flow goes through the following call chains: kv_parse_power_table |-> kv_dpm_init |-> kv_dpm_sw_init |-> kv_dpm_fini The adev->pm.dpm.ps is used in the for loop of kv_dpm_fini after its first free in kv_parse_power_table and causes a use-after-free bug. Fixes: a2e73f56fa62 ("drm/amdgpu: Add support for CIK parts") Signed-off-by: Zhipeng Lu Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/kv_dpm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c index c8a5a5698edd..6eb6f05c1136 100644 --- a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c +++ b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c @@ -2733,10 +2733,8 @@ static int kv_parse_power_table(struct amdgpu_device *adev) non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) &non_clock_info_array->nonClockInfo[non_clock_array_index]; ps = kzalloc(sizeof(struct kv_ps), GFP_KERNEL); - if (ps == NULL) { - kfree(adev->pm.dpm.ps); + if (ps == NULL) return -ENOMEM; - } adev->pm.dpm.ps[i].ps_priv = ps; k = 0; idx = (u8 *)&power_state->v2.clockInfoIndex[0]; -- 2.43.0