NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eliot Courtney" <ecourtney@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Alexandre Courbot" <acourbot@nvidia.com>
Cc: "John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/2] gpu: nova-core: gsp: cmdq: wrap the sequence number on overflow
Date: Wed, 11 Nov 2026 01:42:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-208053@kernel.org> (raw)
In-Reply-To: <20261111-msgq-64-pages-v1-1-d8c56b6fdd6c@nvidia.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] nova-core: double fetch in receive_msg() and
  send_single_command() [1]
--

commit f82fa576ff320e318515a10dc3abe76b072d7cb3
Author: Eliot Courtney <ecourtney@nvidia.com>

gpu: nova-core: gsp: cmdq: wrap the sequence number on overflow

This commit uses wrapping_add(1) when incrementing the command queue
sequence number so that it wraps around on overflow.

> diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
> index 5f3de456042e4..33074bb53e8c4 100644
> --- a/drivers/gpu/nova-core/gsp/cmdq.rs
> +++ b/drivers/gpu/nova-core/gsp/cmdq.rs
> @@ -578,7 +578,7 @@ fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result<u32>
>  
>          // All set - update the write pointer and inform the GSP of the new command.
>          let elem_count = dst.header.element_count();
> -        self.seq += 1;
> +        self.seq = self.seq.wrapping_add(1);
>          self.gsp_mem.advance_cpu_write_ptr(elem_count);

[Severity: Critical]
This problem wasn't introduced by this patch, but can a compromised GSP
alter dst.header.element_count() or message.header.msg_length() in shared
DMA memory between checksum calculation and the pointer updates [1]?

In send_command_element(), dst.header lives in coherent DMA memory that
the GSP can modify concurrently; re-reading dst.header.element_count()
after computing the checksum lets the GSP supply an out-of-bounds count to
advance_cpu_write_ptr().  Similarly, in receive_msg(), wait_for_msg()
checks bounds and validates the checksum using header.msg_length(), and
receive_msg() then fetches message.header.msg_length() a second time from
shared memory to compute elem_count for advance_cpu_read_ptr():

drivers/gpu/nova-core/gsp/cmdq.rs:receive_msg() {
    ...
        let message = self.wait_for_msg(timeout)?;
        let elem_count = u32::try_from(message.header.msg_length().div_ceil(GSP_PAGE_SIZE))
            .map_err(|_| {
                dev_err!(&self.dev, "GSP receive: message length overflow\n");
                EIO
            })?;
        ...
        // Advance the read pointer past this message.
        self.gsp_mem.advance_cpu_read_ptr(elem_count);
    ...
}

Either double fetch allows the GSP to desynchronize the ring buffer
pointers and trigger out-of-bounds reads and writes in shared memory.

[1] https://sashiko.dev/#/bug/linux-a84fa791-1958-42fa-b404-d7ebcb48d6c9

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111-msgq-64-pages-v1-0-d8c56b6fdd6c@nvidia.com?part=1

  reply	other threads:[~2026-11-11  1:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  1:37 [PATCH 0/2] gpu: nova-core: gsp: fix misc cmdq issues Eliot Courtney
2026-11-11  1:37 ` [PATCH 1/2] gpu: nova-core: gsp: cmdq: wrap the sequence number on overflow Eliot Courtney
2026-11-11  1:42   ` sashiko-bot [this message]
2026-11-11 14:43   ` Alexandre Courbot
2026-11-11  1:37 ` [PATCH 2/2] gpu: nova-core: gsp: cmdq: increase MSGQ_NUM_PAGES to 64 Eliot Courtney
2026-11-11 14:49   ` Alexandre Courbot
2026-11-12  1:43     ` Eliot Courtney
2026-11-12  5:19       ` Alexandre Courbot
2026-11-12  5:26         ` Eliot Courtney

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=sashiko-outbox-208053@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=nova-gpu@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    --cc=ttabi@nvidia.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