[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <37cc2302-6a3d-4046-b28c-605221a67329@nvidia.com>
Date: Mon, 15 Dec 2025 11:46:10 +0900
From: John Hubbard <jhubbard@...dia.com>
To: Joel Fernandes <joelagnelf@...dia.com>,
Alistair Popple <apopple@...dia.com>
Cc: Dirk Behme <dirk.behme@...il.com>, 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>,
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 12/15/25 10:22 AM, Joel Fernandes wrote:
>> On Dec 15, 2025, at 8:43 AM, Alistair Popple <apopple@...dia.com> wrote:...
>> So the above calculation expands to:
>>
>> msg_length = size_of::<Self>() - size_of::<bindings::rpc_message_header_v>()
>> + num::u32_as_usize(self.inner.rpc.length) - size_of::<GspMsgElement>();
>>
>> Where self.inner.rpc.length is guaranteed to be >= size_of::<rpc_message_header_v>() by the construction of the type.
>
> But this length field is coming from the firmware, correct? The guarantee is provided by firmware, not by Rust code calculating the length.
>
> Maybe Rust validating that the length matches, or is greater than or equal to, the message header would be one way to avoid doing the checked subtraction. I would still be comfortable doing the checked subtraction in case the firmware payload in the message buffer is corrupted and the length field is corrupted.
>
> I think Rust cannot trust fields coming from the firmware and needs to check them to prevent undefined behavior.
Right. The firmware is a separate code base, running on a separate
processor, and it is not part of the Rust driver. So it cannot
participate in any of the various Rust guarantees.
We should treat data that comes from the firmware as not yet
validated, external data.
Or maybe the policy is to include safety comments, like we do when
expecting C code to behave in a certain way. I
do not know. But we should identify the policy for this and stick to it
for future such issues.es
Yes. I've written above what I believe we should use for a policy.
thanks,
--
John Hubbard
Powered by blists - more mailing lists