[PATCH RESEND 2/3] drm/tyr: reject firmware sections that overlap
From: Daniel Almeida
Date: Fri Nov 27 2026 - 13:02:11 EST
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@xxxxxxxxxxxxx>
---
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