mirror of
https://github.com/torvalds/linux.git
synced 2026-05-29 17:43:52 +02:00
gpu: nova-core: use checked arithmetic in Booter signature parsing
Use checked_add() when computing signature offsets from firmware- provided values in signatures_iter(). Without checked arithmetic, overflow could wrap to a small plausible offset that points to entirely wrong data. Reviewed-by: Zhi Wang <zhiw@nvidia.com> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260126202305.2526618-3-joelagnelf@nvidia.com [acourbot@nvidia.com: remove obvious computation comments.] Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
This commit is contained in:
parent
0568b376a0
commit
4f26096854
|
|
@ -119,14 +119,21 @@ fn signatures_iter(&'a self) -> Result<impl Iterator<Item = BooterSignature<'a>>
|
|||
Some(sig_size) => {
|
||||
let patch_sig =
|
||||
frombytes_at::<u32>(self.fw, self.hdr.patch_sig_offset.into_safe_cast())?;
|
||||
let signatures_start = usize::from_safe_cast(self.hdr.sig_prod_offset + patch_sig);
|
||||
|
||||
let signatures_start = self
|
||||
.hdr
|
||||
.sig_prod_offset
|
||||
.checked_add(patch_sig)
|
||||
.map(usize::from_safe_cast)
|
||||
.ok_or(EINVAL)?;
|
||||
|
||||
let signatures_end = signatures_start
|
||||
.checked_add(usize::from_safe_cast(self.hdr.sig_prod_size))
|
||||
.ok_or(EINVAL)?;
|
||||
|
||||
self.fw
|
||||
// Get signatures range.
|
||||
.get(
|
||||
signatures_start
|
||||
..signatures_start + usize::from_safe_cast(self.hdr.sig_prod_size),
|
||||
)
|
||||
.get(signatures_start..signatures_end)
|
||||
.ok_or(EINVAL)?
|
||||
.chunks_exact(sig_size.into_safe_cast())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user