mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yuvan Shen via B4 Relay <devnull+yuvanshen09.gmail.com@kernel.org>
To: Lee Jones <lee@kernel.org>, Sven Peter <sven@kernel.org>,
	 Janne Grunau <j@jannau.net>
Cc: Neal Gompa <neal@gompa.dev>, Hector Martin <marcan@marcan.st>,
	 asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	 mfd@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org,  Yuvan Shen <yuvanshen09@gmail.com>
Subject: [PATCH] mfd: macsmc: Hold the lock while reading key info
Date: Sun, 01 Nov 2026 11:51:58 -0600	[thread overview]
Message-ID: <20261101-upstream-macsmc-key-info-v1-1-fa9ff863d199@gmail.com> (raw)

From: Yuvan Shen <yuvanshen09@gmail.com>

apple_smc_get_key_info() releases the SMC mutex when apple_smc_cmd()
returns, and only then copies the reply out of the shared memory buffer.
A command issued by another thread in between can overwrite the buffer,
so the key's size, type and flags can come from a different reply. The
hwmon and power sub-devices call it from their probe functions, while
the other sub-devices may already be issuing commands.

Hold the mutex until the reply has been copied, as apple_smc_read() and
apple_smc_write() do.

Fixes: e038d985c982 ("mfd: Add Apple Silicon System Management Controller")
Cc: stable@vger.kernel.org
Signed-off-by: Yuvan Shen <yuvanshen09@gmail.com>
---
 drivers/mfd/macsmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
index 514cba7dc897..4dbaacc7eb3d 100644
--- a/drivers/mfd/macsmc.c
+++ b/drivers/mfd/macsmc.c
@@ -210,7 +210,9 @@ int apple_smc_get_key_info(struct apple_smc *smc, smc_key key, struct apple_smc_
 	u8 key_info[6];
 	int ret;
 
-	ret = apple_smc_cmd(smc, SMC_MSG_GET_KEY_INFO, key, 0, 0, NULL);
+	guard(mutex)(&smc->mutex);
+
+	ret = apple_smc_cmd_locked(smc, SMC_MSG_GET_KEY_INFO, key, 0, 0, NULL);
 	if (ret >= 0 && info) {
 		memcpy_fromio(key_info, smc->shmem.iomem, sizeof(key_info));
 		info->size = key_info[0];

---
base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
change-id: 20261101-upstream-macsmc-key-info-714c15af3652

Best regards,
--  
Yuvan Shen <yuvanshen09@gmail.com>



                 reply	other threads:[~2026-11-01 17:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261101-upstream-macsmc-key-info-v1-1-fa9ff863d199@gmail.com \
    --to=devnull+yuvanshen09.gmail.com@kernel.org \
    --cc=asahi@lists.linux.dev \
    --cc=j@jannau.net \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=mfd@lists.linux.dev \
    --cc=neal@gompa.dev \
    --cc=stable@vger.kernel.org \
    --cc=sven@kernel.org \
    --cc=yuvanshen09@gmail.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®