From: Alice Ryhl <aliceryhl@google.com>
To: Bilal Hashim <AeeSec@126.com>
Cc: Alice Ryhl <aliceryhl@google.com>,
Daniel Almeida <daniel.almeida@collabora.com>,
Danilo Krummrich <dakr@kernel.org>,
dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/tyr: fw: fix integer overflow and inverted range check in Cursor
Date: Fri, 27 Nov 2026 17:15:32 +0000 [thread overview]
Message-ID: <20261127171532.2097157-1-aliceryhl@google.com> (raw)
In-Reply-To: <20261127124107.1782-1-AeeSec@126.com>
On Fri, Nov 27, 2026 at 08:41:07PM +0800, Bilal Hashim wrote:
> In drivers/gpu/drm/tyr/fw/parser.rs, the firmware binary parser `Cursor`
> has two bounds-checking bugs that can panic the kernel on malformed
> firmware images:
Note that neither of these can actually trigger a panic on malformed firmware
images today. `Cursor` is private to `parser.rs`, and its callers already
guarantee these conditions:
- `view()` is only called in `parse_entry()`, which already checks
`entry_size >= size_of::<EntryHeader>()` and computes
`entry_end = entry_start.checked_add(entry_size)?`, so
`self.cursor.pos() <= entry_end` always holds.
- `read()` is only called with `nbytes` in `{1, 2, 4}`, and `advance()` is
only called with `section_hdr_size <= 248` (since `EntryHeader::size()` is
an 8-bit field). Because `self.pos <= self.data.len() <= isize::MAX as
usize`, `self.pos + nbytes` cannot overflow `usize` even on 32-bit systems.
Hardening `Cursor` so its bounds checks are self-contained is still nice to
have, so please reword the commit message to describe this as defensive
hardening rather than fixing a reachable kernel panic (and no `Fixes:` tag
is needed).
> @@ -144,7 +144,7 @@ impl<'a> Cursor<'a> {
> ///
> /// Returns an error if the advance would exceed the data bounds.
> fn advance(&mut self, nbytes: usize) -> Result {
> - if self.pos + nbytes > self.data.len() {
> + let Some(end) = self.pos.checked_add(nbytes).filter(|&e| e <= self.data.len()) else {
This line fails `rustfmt --check` (please run `make LLVM=1 rustfmt`).
Alice
prev parent reply other threads:[~2026-11-27 17:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 12:41 Bilal Hashim
2026-11-27 17:15 ` Alice Ryhl [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=20261127171532.2097157-1-aliceryhl@google.com \
--to=aliceryhl@google.com \
--cc=AeeSec@126.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rust-for-linux@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®