mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhang Rui <rui.zhang@intel.com>
To: rafael.j.wysocki@intel.com
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: [PATCH 1/6] powercap: intel_rapl: Fix a NULL pointer dereference bug
Date: Wed, 31 Jan 2024 19:37:08 +0800	[thread overview]
Message-ID: <20240131113713.74779-2-rui.zhang@intel.com> (raw)
In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com>

A NULL pointer dereference bug is triggered when probing MMIO RAPL
driver on platforms with CPU ID not listed in intel_rapl_common CPU
model list.

This is because the intel_rapl_common module still probes on such
platforms even if 'defaults_msr' is not set after commit 1488ac990ac8
("powercap: intel_rapl: Allow probing without CPUID match"). Thus the
MMIO RAPL rp->priv->defaults is NULL when registering to RAPL framework.

Fix the problem by adding sanity check to ensure rp->priv->rapl_defaults
is always valid.

Fixes: 1488ac990ac8 ("powercap: intel_rapl: Allow probing without CPUID match")
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Cc: <stable@vger.kernel.org>
---
 drivers/powercap/intel_rapl_common.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index 2feed036c1cd..1a739afd47d9 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -759,6 +759,11 @@ static int rapl_config(struct rapl_package *rp)
 	default:
 		return -EINVAL;
 	}
+
+	/* defaults_msr can be NULL on unsupported platforms */
+	if (!rp->priv->defaults || !rp->priv->rpi)
+		return -ENODEV;
+
 	return 0;
 }
 
-- 
2.34.1


  reply	other threads:[~2024-01-31 11:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 11:37 [PATCH 0/6] powercap: intel_rapl: Fixes and new platform enabling Zhang Rui
2024-01-31 11:37 ` Zhang Rui [this message]
2024-01-31 11:37 ` [PATCH 2/6] powercap: intel_rapl: Fix locking for TPMI RAPL Zhang Rui
2024-01-31 11:37 ` [PATCH 3/6] powercap: intel_rapl_tpmi: Fix a register bug Zhang Rui
2024-01-31 11:37 ` [PATCH 4/6] powercap: intel_rapl_tpmi: Fix System Domain probing Zhang Rui
2024-01-31 11:37 ` [PATCH 5/6] powercap: intel_rapl: Add support for LNL-M paltform Zhang Rui
2024-01-31 11:37 ` [PATCH 6/6] powercap: intel_rapl: add support for Arrow Lake Zhang Rui
2024-02-13 18:37 ` [PATCH 0/6] powercap: intel_rapl: Fixes and new platform enabling Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240131113713.74779-2-rui.zhang@intel.com \
    --to=rui.zhang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®