mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: dakr@kernel.org, simona@ffwll.ch, airlied@gmail.com,
	 aliceryhl@google.com
Cc: Sami Tolvanen <samitolvanen@google.com>,
	 dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	 rust-for-linux@vger.kernel.org,
	 Daniel Almeida <daniel.almeida@collabora.com>
Subject: [PATCH RESEND 3/3] drm/tyr: reject firmware sections with oversized data
Date: Fri, 27 Nov 2026 15:01:39 -0300	[thread overview]
Message-ID: <20261127-tyr-fw-parser-v1-3-8aab2a711f9b@collabora.com> (raw)
In-Reply-To: <20261127-tyr-fw-parser-v1-0-8aab2a711f9b@collabora.com>

Firmware::new() creates a BO of the size of a section's VA range and
copies the section's data into it. Data larger than the range is only
caught at the copy, after the BO is created and mapped, and the data of
a section with an empty VA range is dropped without a message.

Reject both in FwParser::parse_section_entry(), as panthor does, and add
a test for each case.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
 drivers/gpu/drm/tyr/fw/parser.rs | 44 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/gpu/drm/tyr/fw/parser.rs b/drivers/gpu/drm/tyr/fw/parser.rs
index 133b63c5cff1..43e7599f6622 100644
--- a/drivers/gpu/drm/tyr/fw/parser.rs
+++ b/drivers/gpu/drm/tyr/fw/parser.rs
@@ -374,6 +374,14 @@ fn parse_section_entry(
             return Err(EINVAL);
         }
 
+        if section_hdr.data.len() > section_hdr.va.len() {
+            dev_err!(
+                entry_cursor.dev,
+                "Firmware corrupted, section data exceeds section size"
+            );
+            return Err(EINVAL);
+        }
+
         if section_hdr.va.is_empty() {
             return Ok(None);
         }
@@ -859,6 +867,8 @@ fn section_va_end_before_start() {
         let mut image = Image::new();
         // The VA range ends at 0x1000.
         image.entries[0].va.start = 0x2000;
+        // Without data, the VA range is the section's only defect.
+        image.entries[0].data.end = 68;
         assert_eq!(image.parse().err(), Some(EINVAL));
     }
 
@@ -920,4 +930,38 @@ fn overlapping_sections() {
         image.entries[1].va = second..second + 0x3000;
         assert_eq!(image.parse().err(), Some(EINVAL));
     }
+
+    /// Section data that is larger than the VA range of the section is rejected.
+    #[test]
+    fn section_data_larger_than_va_range() {
+        let mut image = Image::new();
+        // The first section spans one page and its data starts at byte 68. The file holds one page
+        // and one byte of data.
+        image.data_size = 0x1001;
+
+        // One page of data fits.
+        image.entries[0].data.end = 68 + 0x1000;
+        assert!(image.parse().is_ok());
+
+        // One more byte does not.
+        image.entries[0].data.end = 68 + 0x1001;
+        assert_eq!(image.parse().err(), Some(EINVAL));
+    }
+
+    /// Section data in a section with an empty VA range is rejected.
+    #[test]
+    fn section_data_in_empty_va_range() -> Result {
+        let mut image = Image::new();
+        image.entries[0].va.end = 0x0;
+
+        // Without data, the section is skipped.
+        image.entries[0].data.end = 68;
+        assert_eq!(image.parse()?.len(), 1);
+
+        // With 4 bytes of data, it is rejected.
+        image.entries[0].data.end = 72;
+        assert_eq!(image.parse().err(), Some(EINVAL));
+
+        Ok(())
+    }
 }

-- 
2.56.0


  parent reply	other threads:[~2026-11-27 18:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 18:01 [PATCH RESEND 0/3] drm/tyr: KUnit tests and fixes for the firmware parser Daniel Almeida
2026-11-27 18:01 ` [PATCH RESEND 1/3] drm/tyr: add KUnit tests " Daniel Almeida
2026-11-27 18:01 ` [PATCH RESEND 2/3] drm/tyr: reject firmware sections that overlap Daniel Almeida
2026-11-27 18:01 ` Daniel Almeida [this message]
2026-11-27 19:40 ` [PATCH RESEND 0/3] drm/tyr: KUnit tests and fixes for the firmware parser Daniel Almeida

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=20261127-tyr-fw-parser-v1-3-8aab2a711f9b@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=samitolvanen@google.com \
    --cc=simona@ffwll.ch \
    /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®