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 2/3] drm/tyr: reject firmware sections that overlap
Date: Fri, 27 Nov 2026 15:01:38 -0300	[thread overview]
Message-ID: <20261127-tyr-fw-parser-v1-2-8aab2a711f9b@collabora.com> (raw)
In-Reply-To: <20261127-tyr-fw-parser-v1-0-8aab2a711f9b@collabora.com>

Firmware::new() maps each loadable section at the VA range given in its
section header. When two ranges overlap, GPUVM unmaps or splits the part
of the earlier mapping that the later one covers. The MCU then sees the
later section's pages there, and nothing reports the overlap.

Reject an image whose loadable sections overlap in FwParser::parse(),
and add a test for it.

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

diff --git a/drivers/gpu/drm/tyr/fw/parser.rs b/drivers/gpu/drm/tyr/fw/parser.rs
index de5881f1bf47..133b63c5cff1 100644
--- a/drivers/gpu/drm/tyr/fw/parser.rs
+++ b/drivers/gpu/drm/tyr/fw/parser.rs
@@ -188,6 +188,18 @@ pub(super) fn parse(&mut self) -> Result<KVec<ParsedSection>> {
             let entry_section = self.parse_entry(header_end)?;
 
             if let Some(inner) = entry_section.inner {
+                if parsed_sections.iter().any(|other: &ParsedSection| {
+                    inner.va.start < other.va.end && other.va.start < inner.va.end
+                }) {
+                    dev_err!(
+                        self.cursor.dev,
+                        "Firmware virtual address range {:#x}..{:#x} overlaps another section",
+                        inner.va.start,
+                        inner.va.end
+                    );
+                    return Err(EINVAL);
+                }
+
                 parsed_sections.push(inner, GFP_KERNEL)?;
             }
         }
@@ -883,4 +895,29 @@ fn shared_region_not_shared() {
         image.entries[1].flags = SectionFlags::READ_MASK;
         assert_eq!(image.parse().err(), Some(EINVAL));
     }
+
+    /// Loadable sections with overlapping VA ranges are rejected.
+    #[test]
+    fn overlapping_sections() {
+        let mut image = Image::new();
+        // The second section is the page at `second`.
+        let second = image.entries[1].va.start;
+
+        // The first section ends where the second one starts.
+        image.entries[0].va = second - 0x1000..second;
+        assert!(image.parse().is_ok());
+
+        // The first section starts where the second one ends.
+        image.entries[0].va = second + 0x1000..second + 0x2000;
+        assert!(image.parse().is_ok());
+
+        // The first section covers the page below the second one and the second one.
+        image.entries[0].va = second - 0x1000..second + 0x1000;
+        assert_eq!(image.parse().err(), Some(EINVAL));
+
+        // The second section covers three pages, and the first one is the page in the middle.
+        image.entries[0].va = second + 0x1000..second + 0x2000;
+        image.entries[1].va = second..second + 0x3000;
+        assert_eq!(image.parse().err(), Some(EINVAL));
+    }
 }

-- 
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 ` Daniel Almeida [this message]
2026-11-27 18:01 ` [PATCH RESEND 3/3] drm/tyr: reject firmware sections with oversized data Daniel Almeida
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-2-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®