Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp493505pxj; Tue, 18 May 2021 07:59:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6WDDOyk80v/BXEZSpsOMLRXDe52aLw0o0mb12MWLJ0VewLFhyLb7NuZS2CrIh0Paq5rrX X-Received: by 2002:a17:907:2dab:: with SMTP id gt43mr6602948ejc.369.1621349967044; Tue, 18 May 2021 07:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621349967; cv=none; d=google.com; s=arc-20160816; b=ApalEDqw5fUK/Yj9AKAbUc1/KsNQDM3r/6dn9FWSDIYUH6QeDKraBF0Ud/rx5NTxEk pYoouLOL8J+U9ktNaPKDWfEC2O76cs/N3NzAzxBccyFiLESXzFItl/nqCbHSY0M2eLq1 dFXzmQcU6GrNwP32cIXylKm5BxxEY7T92inirm5Fxjke9pc878Cxu5vzsyuKuK6O9GFg SxTOiV+EGhQQPO8/ENZvZ9vCt6/MPmhJVTeueaJkR55n7bsHjZABhGud/kHeb5SpwweT UtE9Jtdmuaso+vZsjrjSA0rU44DvH1EM7bg9+droK926LZF6AnbWoB1BEEhKsBj3PW+G X1eg== 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=RfDnaAxFwe+AoTKX0dQ9AdhBhfUetcVdF/vUMwSZWRA=; b=hfNd26vMxkURJg1x/YQjx3QgcRqNN78r96U9Gha87KAZ3OYAFb1QtwAnkUjLi9+lzS yzLHOSWfvGrWQ+Ky7S7FceVLhDV6d5SP3t0OF/kmLvu5kYvqJdPSXB1Hk5iTmk9NoLy4 VXc+UGz/NQOfJpVtU4yk90yZzcMO/t8/sHlJkrSs0uwekHigqogSbogpMcy4iJM6QSQ1 QWJsIcq7uQPZel9SsuLrdZgHLR5VzTS4MgK+Hazwf2FVvxBC/Lv98I3x56e7a69cJSIZ vGXYz0pXShAkuoY8VnbQ8ee/ArDPOs+0CDnz2Kpo+iC1Htx5oZkQjN+HNbA4dxW4IvIj lbtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t6wnMEPg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si21298731ejb.158.2021.05.18.07.59.03; Tue, 18 May 2021 07:59:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t6wnMEPg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1344948AbhEQPuF (ORCPT + 99 others); Mon, 17 May 2021 11:50:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:56322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244424AbhEQPdA (ORCPT ); Mon, 17 May 2021 11:33:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E31161CD4; Mon, 17 May 2021 14:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262332; bh=xXYglV3thzDfkjUsKAdn0/hHx08Sxuj3hW5Xsv5TBRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t6wnMEPg9163Q0rYPih+KXpc6nuG5H5ih/BO+xGPUJmklkUKChwgZBZm7dF/rIw6d +YDGY3lY8GcgXPe4j8Gxj3TGkederCynfVzIWl1phb1RCkOjyequO/LdnyTs0FihUq 9rbcQQyvy23tbmvtBlQavfwuw8SgLClVbf+4oktY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 163/289] drm/radeon: Avoid power table parsing memory leaks Date: Mon, 17 May 2021 16:01:28 +0200 Message-Id: <20210517140310.618657307@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit c69f27137a38d24301a6b659454a91ad85dff4aa ] Avoid leaving a hanging pre-allocated clock_info if last mode is invalid, and avoid heap corruption if no valid modes are found. Bug: https://bugzilla.kernel.org/show_bug.cgi?id=211537 Fixes: 6991b8f2a319 ("drm/radeon/kms: fix segfault in pm rework") Signed-off-by: Kees Cook Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/radeon/radeon_atombios.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c index 96e80b0eca04..aca6e5cfae53 100644 --- a/drivers/gpu/drm/radeon/radeon_atombios.c +++ b/drivers/gpu/drm/radeon/radeon_atombios.c @@ -2126,11 +2126,14 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev) return state_index; /* last mode is usually default, array is low to high */ for (i = 0; i < num_modes; i++) { - rdev->pm.power_state[state_index].clock_info = - kcalloc(1, sizeof(struct radeon_pm_clock_info), - GFP_KERNEL); + /* avoid memory leaks from invalid modes or unknown frev. */ + if (!rdev->pm.power_state[state_index].clock_info) { + rdev->pm.power_state[state_index].clock_info = + kzalloc(sizeof(struct radeon_pm_clock_info), + GFP_KERNEL); + } if (!rdev->pm.power_state[state_index].clock_info) - return state_index; + goto out; rdev->pm.power_state[state_index].num_clock_modes = 1; rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE; switch (frev) { @@ -2249,8 +2252,15 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev) break; } } +out: + /* free any unused clock_info allocation. */ + if (state_index && state_index < num_modes) { + kfree(rdev->pm.power_state[state_index].clock_info); + rdev->pm.power_state[state_index].clock_info = NULL; + } + /* last mode is usually default */ - if (rdev->pm.default_power_state_index == -1) { + if (state_index && rdev->pm.default_power_state_index == -1) { rdev->pm.power_state[state_index - 1].type = POWER_STATE_TYPE_DEFAULT; rdev->pm.default_power_state_index = state_index - 1; -- 2.30.2