Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3128539pxj; Mon, 17 May 2021 18:31:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3hcrixpDigSudmgTIJ3YgVdTHnETbgqWrwUNpZZZkUZEaSfL/uwZKT1oqG5/bZ6KPl/Ci X-Received: by 2002:a02:878c:: with SMTP id t12mr2800490jai.59.1621301515305; Mon, 17 May 2021 18:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621301515; cv=none; d=google.com; s=arc-20160816; b=XJ/YX+1uI/PicAcNwukBIe3w3wlwGc9cQHKeBrZGXmVzkAMzxW9natE2X5y0wiYje9 e3IAcN9l6+++7u+RYritXYn0t3bOA9Yn2OR7bCD9CqgrbY7uIDEJJAec8g6xRTcLP7/8 uXvyn5JW0YP94JpZ3/QiJiIzGYtUA3AvTYKBmXDC2Pp5+LThiFvh5Dp3rAD9SGZzrE4V LArHnzbqLgj1W49tT9d6BCTSvcF3HDMAr/jlX7Euj+7t76varmlNIXGra2XSPkyZC/DX uAOm+lEVnYOG6369rnnZ92jX9fioXr/DdW+lcd/HC73F+Q24eJvHMxaY5Aa+VO+BsubP iPwA== 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=jRAvE+cdRE/9NRaWWuW5IAWs0zd39VxDP9CCzPaQWSI=; b=KX0z7KHbTS2+7mE3pWrl8wBn8vcJAAbU0ckWkCJJscRvZtE1U+PwPynx3U78ELC2FV oJJHLZRLHGKdRnI/jqpRko7VD2oW87uQ5vZRcrgiCfaOGgYj/wH/NhdsgSLoycUHWek8 Wx+TfOP6etHd75Y1WvngSnlCtO+vDVuKWLsaJrYzYV8s9yDWDtW8Vh1npWAFs6IDzOaD 3ItVPWc2+mDQM/rAcEwGBtjjmypOfT6ZRFBOIUKjTYWyTOUVP6icH4XJr41E12PVs6gN LbS9VUsXxLDiZ90pgmUBKVWE3nwsVsiuOYyQcIV23yLmAR0hbHKceBjch2+P9VyTkfBW VsdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z4yYU8UB; 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 v8si20299261ilu.72.2021.05.17.18.31.42; Mon, 17 May 2021 18:31:55 -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=Z4yYU8UB; 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 S240389AbhEQOeL (ORCPT + 99 others); Mon, 17 May 2021 10:34:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:53288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239212AbhEQO2N (ORCPT ); Mon, 17 May 2021 10:28:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C083261626; Mon, 17 May 2021 14:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260854; bh=owXmZOYrZFTscCWbK1gsEsA9aZW+UUmh7ljGDKKekLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4yYU8UBNNEw02lE5lAQB3ufzLi1Wy5VgzYPXZZOBNcpsW7uTtUWyfz84zLwrb7JQ dgS40imvRZKxzD3H6GxLHbRj8ULlranikNjPk7mXtmZvmhthxZLdy210M5OYovQD8B JVUfVUiY6exuihCLR3pagG53JO26TfqmlbcAhL6Q= 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.12 214/363] drm/radeon: Avoid power table parsing memory leaks Date: Mon, 17 May 2021 16:01:20 +0200 Message-Id: <20210517140309.812339261@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 f9f4efa1738c..28c4413f4dc8 100644 --- a/drivers/gpu/drm/radeon/radeon_atombios.c +++ b/drivers/gpu/drm/radeon/radeon_atombios.c @@ -2120,11 +2120,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) { @@ -2243,8 +2246,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