All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bryam Vargas <hexlabsecurity@proton.me>
To: Alexander Graf <graf@amazon.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>
Cc: The AWS Nitro Enclaves Team <aws-nitro-enclaves-devel@amazon.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] misc: nsm: bound the device-reported response length
Date: Mon, 22 Jun 2026 07:50:20 +0000	[thread overview]
Message-ID: <20260622075013.51640-1-hexlabsecurity@proton.me> (raw)
In-Reply-To: <5fa26d33-fb13-4f74-b972-43b460ac916d@amazon.com>

On 2026-06-21, Alexander Graf wrote:
> I think as a stick in the ground saying "all virtio drivers are trusted"
> makes a lot of sense given that a lot of the virtualized world runs on
> virtio.

Agreed -- a guest can't attest its backend, so the practical TCB line is the
driver, not the device. I'll treat the NSM transport as untrusted and sweep the
rest of nsm.c on that basis.

> A quick AI scan revealed that the cbor_short_size switch has no default
> branch, which leads to uninitialized array_len.

Confirmed, and it's an uninitialized read rather than an OOB. The switch covers
23..27 with no default, so a device picking 0..22 or 28..31 matches no case and
array_len reaches the two trailing checks unset. Those clamp the result to
<= resp_len - array_offset and <= INT_MAX, so the memcpy in
parse_resp_get_random() stays inside resp->data. What's left is the
uninitialized length plus a plain decode bug: a short array of 0..22 elements is
read from garbage instead of cbor_short_size.

The existing case already handles 23 correctly, so the fix widens that label to
the whole short-form range (same body, no new case value -> no duplicate) and
adds a rejecting default:

-       case CBOR_SHORT_SIZE_MAX_VALUE:        /* short encoding */
+       case 0 ... CBOR_SHORT_SIZE_MAX_VALUE:  /* short form: len IS the value */
                array_len = cbor_short_size;
                break;
        ... U8/U16/U32/U64 cases unchanged ...
+       default:                               /* 28..31 reserved/indefinite */
+               return -EFAULT;

By inspection so far. I'll send that as its own patch this week once it's
through KMSAN here, and the wider nsm.c pass before -rc3.

Thanks for the review,
Bryam


      reply	other threads:[~2026-06-22  7:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-21  2:42 [PATCH] misc: nsm: bound the device-reported response length Bryam Vargas
2026-06-21  2:42 ` Bryam Vargas via B4 Relay
2026-06-21  5:38 ` Greg Kroah-Hartman
2026-06-21  8:07   ` Graf (AWS), Alexander
2026-06-22  7:50     ` Bryam Vargas [this message]

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=20260622075013.51640-1-hexlabsecurity@proton.me \
    --to=hexlabsecurity@proton.me \
    --cc=arnd@arndb.de \
    --cc=aws-nitro-enclaves-devel@amazon.com \
    --cc=graf@amazon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.