mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "M K, Muralidhara" <muralimk@amd.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Muralidhara M K" <muralidhara.mk@amd.com>
Cc: platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	Muthusamy Ramalingam <muthusamy.ramalingam@amd.com>
Subject: Re: [PATCH v5 6/8] platform/x86/amd/hsmp: Sanitize hsmp_ioctl_msg() msg_id for Spectre v1
Date: Thu, 11 Jun 2026 22:16:43 +0530	[thread overview]
Message-ID: <bf7abfa1-e9c7-47d2-8362-97c31feaba37@amd.com> (raw)
In-Reply-To: <0a312950-54df-7290-e702-14ba31951b0c@linux.intel.com>



On 6/11/2026 5:39 PM, Ilpo Järvinen wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> On Thu, 11 Jun 2026, Muralidhara M K wrote:
> 
>> Although validate_message() checks msg_id, a mispredicted branch can
>> still allow speculative indexing into hsmp_msg_desc_table[].  Clamp
>> msg.msg_id with array_index_nospec() at entry to hsmp_ioctl_msg() so
>> downstream dereferences (including via is_get_msg() and
>> hsmp_send_message()) see a bounded index.
>>
>> Reviewed-by: Muthusamy Ramalingam <muthusamy.ramalingam@amd.com>
>> Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
>> ---
>>   drivers/platform/x86/amd/hsmp/hsmp.c | 13 +++++++++++++
>>   1 file changed, 13 insertions(+)
>>
>> diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
>> index 36ff83744684..a9dca97568b8 100644
>> --- a/drivers/platform/x86/amd/hsmp/hsmp.c
>> +++ b/drivers/platform/x86/amd/hsmp/hsmp.c
>> @@ -306,6 +306,19 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg)
>>        if (msg.msg_id < HSMP_TEST || msg.msg_id >= HSMP_MSG_ID_MAX)
>>                return -ENOMSG;
>>
>> +     /*
>> +      * Sanitize the user-controlled msg_id against speculative
>> +      * execution.  The bounds check above retires the out-of-range
>> +      * case with -ENOMSG, but a mispredicted branch can still let the
>> +      * CPU speculatively use msg_id as an index into
>> +      * hsmp_msg_desc_table[] (here and in validate_message() /
>> +      * is_get_msg() called downstream via hsmp_send_message()), and
>> +      * pull arbitrary kernel memory into the cache (Spectre v1,
>> +      * CVE-2017-5753).  Clamp once into msg.msg_id so every downstream
>> +      * dereference sees the sanitized value.
>> +      */
>> +     msg.msg_id = array_index_nospec(msg.msg_id, HSMP_MSG_ID_MAX);
>> +
>>        switch (fp->f_mode & (FMODE_WRITE | FMODE_READ)) {
>>        case FMODE_WRITE:
>>                /*
> 
> Sashiko mentions there's similar gadget for sock_ind in
> hsmp_send_message().
> 
Thanks for pointing. I will update in next version.
> --
>   i.
> 


  reply	other threads:[~2026-06-11 16:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11  5:29 [PATCH v5 0/8] platform/x86/amd/hsmp: Family 1Ah Model 50h-5Fh HSMP and metrics Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 1/8] platform/x86/amd/hsmp: Add HSMP messages for Family 1Ah, Model 50h-5Fh Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 2/8] platform/x86/amd/hsmp: Add UAPI structures for Family 1Ah Model 50h-5Fh metrics table Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 3/8] platform/x86/amd/hsmp: Unify response_sz validation to an upper-bound check Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 4/8] platform/x86/amd/hsmp: Source metric-table size from firmware Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 5/8] platform/x86/amd/hsmp: Add IOCTL_GET_TELEMETRY_DATA for metric table reads Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 6/8] platform/x86/amd/hsmp: Sanitize hsmp_ioctl_msg() msg_id for Spectre v1 Muralidhara M K
2026-06-11 12:09   ` Ilpo Järvinen
2026-06-11 16:46     ` M K, Muralidhara [this message]
2026-06-11  5:29 ` [PATCH v5 7/8] platform/x86/amd/hsmp: Enable HSMP_PROTO_VER7 metric tables on the ACPI driver via the IOCTL Muralidhara M K
2026-06-11  5:29 ` [PATCH v5 8/8] platform/x86/amd/hsmp: Make metric table read locking use guard(mutex) Muralidhara M K
2026-06-11 13:18   ` Ilpo Järvinen
2026-06-11 16:51     ` M K, Muralidhara

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=bf7abfa1-e9c7-47d2-8362-97c31feaba37@amd.com \
    --to=muralimk@amd.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muralidhara.mk@amd.com \
    --cc=muthusamy.ramalingam@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /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®