[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5wfozb7rrh7snccab6dxckrd3umk7u34bixwjfqveta76237um@l23sftnckeep>
Date: Mon, 15 Dec 2025 10:29:03 +1100
From: Alistair Popple <apopple@...dia.com>
To: Joel Fernandes <joelagnelf@...dia.com>
Cc: Alexandre Courbot <acourbot@...dia.com>,
Danilo Krummrich <dakr@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
John Hubbard <jhubbard@...dia.com>, Timur Tabi <ttabi@...dia.com>, Edwin Peer <epeer@...dia.com>,
"nouveau@...ts.freedesktop.org" <nouveau@...ts.freedesktop.org>,
"dri-devel@...ts.freedesktop.org" <dri-devel@...ts.freedesktop.org>, "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"rust-for-linux@...r.kernel.org" <rust-for-linux@...r.kernel.org>
Subject: Re: [PATCH 2/4] gpu: nova-core: gsp: Fix length of received messages
On 2025-12-12 at 18:59 +1100, Joel Fernandes <joelagnelf@...dia.com> wrote...
> Hi Alex,
>
> > On Nov 22, 2025, at 12:00 AM, Alexandre Courbot <acourbot@...dia.com> wrote:
> >
> > The size of messages' payload is miscalculated, leading to extra data
> > passed to the message handler. While this is not a problem with our
> > current set of commands, others with a variable-length payload may
> > misbehave. Fix this.
> >
> > Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
> > ---
> > drivers/gpu/nova-core/gsp/cmdq.rs | 11 +++++++----
> > drivers/gpu/nova-core/gsp/fw.rs | 2 +-
> > 2 files changed, 8 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
> > index 6f946d14868a..dab73377c526 100644
> > --- a/drivers/gpu/nova-core/gsp/cmdq.rs
> > +++ b/drivers/gpu/nova-core/gsp/cmdq.rs
> > @@ -588,21 +588,24 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
> > header.length(),
> > );
> >
> > + // The length of the message that follows the header.
> > + let msg_length = header.length() - size_of::<GspMsgElement>();
Wouldn't it be better to add a new method to GspMsgElement to get the size of
the associated message rather than open coding it here?
- Alistair
> Is this immune to under flow without one of the checked subtraction wrappers? Either way, we should not tolerate the underflow I think. Which means it can panic when the rust overflow checks are enabled. Since the header length comes from firmware, this cannot be guaranteed to not underflow in the event of a malformed message.
>
> thanks,
>
> - Joel
>
>
>
> > +
> > // Check that the driver read area is large enough for the message.
> > - if slice_1.len() + slice_2.len() < header.length() {
> > + if slice_1.len() + slice_2.len() < msg_length {
> > return Err(EIO);
> > }
> >
> > // Cut the message slices down to the actual length of the message.
> > - let (slice_1, slice_2) = if slice_1.len() > header.length() {
> > + let (slice_1, slice_2) = if slice_1.len() > msg_length {
> > // PANIC: we checked above that `slice_1` is at least as long as `msg_header.length()`.
> > - (slice_1.split_at(header.length()).0, &slice_2[0..0])
> > + (slice_1.split_at(msg_length).0, &slice_2[0..0])
> > } else {
> > (
> > slice_1,
> > // PANIC: we checked above that `slice_1.len() + slice_2.len()` is at least as
> > // large as `msg_header.length()`.
> > - slice_2.split_at(header.length() - slice_1.len()).0,
> > + slice_2.split_at(msg_length - slice_1.len()).0,
> > )
> > };
> >
> > diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
> > index abffd6beec65..7fcba5afb0a3 100644
> > --- a/drivers/gpu/nova-core/gsp/fw.rs
> > +++ b/drivers/gpu/nova-core/gsp/fw.rs
> > @@ -853,7 +853,7 @@ pub(crate) fn set_checksum(&mut self, checksum: u32) {
> > self.inner.checkSum = checksum;
> > }
> >
> > - /// Returns the total length of the message.
> > + /// Returns the total length of the message, message and RPC headers included.
> > pub(crate) fn length(&self) -> usize {
> > // `rpc.length` includes the length of the GspRpcHeader but not the message header.
> > size_of::<Self>() - size_of::<bindings::rpc_message_header_v>()
> >
> > --
> > 2.51.2
> >
Powered by blists - more mailing lists