mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Muralidhara M K <muralidhara.mk@amd.com>
To: <ilpo.jarvinen@linux.intel.com>
Cc: <platform-driver-x86@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Muralidhara M K <muralidhara.mk@amd.com>,
	Sashiko <sashiko-reviews@lists.linux.dev>
Subject: [PATCH 1/2] platform/x86/amd/hsmp: Validate num_args before the fd-mode gate in hsmp_ioctl_msg()
Date: Sat, 17 Oct 2026 22:21:52 +0530	[thread overview]
Message-ID: <20261017165153.3748458-2-muralidhara.mk@amd.com> (raw)
In-Reply-To: <20261017165153.3748458-1-muralidhara.mk@amd.com>

is_get_msg() reads msg.args[0]'s CHECK_GET_BIT to tell GET and SET apart
for HSMP_SET_GET messages, but hsmp_ioctl_msg() calls it before
validate_message() (reached later through hsmp_send_message()) checks
that msg.num_args matches desc->num_args. A request with num_args = 0
for such a message reaches is_get_msg() anyway, so args[0] is read even
though the request does not carry it.

Check msg.num_args against desc->num_args before the fd-mode switch, so
a num_args mismatch is rejected with -EINVAL before is_get_msg() reads
args[0], rather than surfacing as -EPERM from the fd-mode gate.

Reported-by: Sashiko <sashiko-reviews@lists.linux.dev>
Link: https://sashiko.dev/#/patchset/20261012085407.1202295-1-muralidhara.mk@amd.com
Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
---
 drivers/platform/x86/amd/hsmp/hsmp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 45d20beda946..635e6d5723ac 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -485,6 +485,16 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg)
 		if (!desc)
 			return -ENOMSG;
 
+		/*
+		 * is_get_msg() below reads msg.args[0] for HSMP_SET_GET
+		 * messages. Reject a num_args mismatch here first, so a
+		 * malformed request fails with -EINVAL instead of letting
+		 * the fd-mode gate read an argument slot the request does
+		 * not actually carry.
+		 */
+		if (msg.num_args != desc->num_args)
+			return -EINVAL;
+
 		switch (fp->f_mode & (FMODE_WRITE | FMODE_READ)) {
 		case FMODE_WRITE:
 			/*
-- 
2.34.1


  reply	other threads:[~2026-10-17 16:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17 16:51 [PATCH 0/2] platform/x86/amd/hsmp: Validate num_args and Report raw SMU mailbox status Muralidhara M K
2026-10-17 16:51 ` Muralidhara M K [this message]
2026-10-17 16:51 ` [PATCH 2/2] platform/x86/amd/hsmp: Report raw SMU mailbox status via smu_response Muralidhara M K

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=20261017165153.3748458-2-muralidhara.mk@amd.com \
    --to=muralidhara.mk@amd.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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®