From 5db50db7a96b257ec50c5fd2a212aa6b5008b62f Mon Sep 17 00:00:00 2001 From: Wren Turkal Date: Fri, 31 Jul 2020 21:21:09 -0700 Subject: [PATCH] Fix buggy assertion in pcid capability parser. The pcid capability parsing code has an assertion that checks for dword alignment. Unfortunately, the check was previously checking for alignment to qwords. This fixes that. I found this issue by using qemu to emulate adding different pci devices. I managed to come across a device that had a capability aligned on dword, but not qword. That exposed the bug. Signed-off-by: Wren Turkal --- pcid/src/pci/cap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcid/src/pci/cap.rs b/pcid/src/pci/cap.rs index 8d5682079d..2e4f946a70 100644 --- a/pcid/src/pci/cap.rs +++ b/pcid/src/pci/cap.rs @@ -197,7 +197,7 @@ impl Capability { }) } unsafe fn parse(reader: &R, offset: u8) -> Self { - assert_eq!(offset & 0xF8, offset, "capability must be dword aligned"); + assert_eq!(offset & 0xFC, offset, "capability must be dword aligned"); let dword = reader.read_u32(u16::from(offset)); let capability_id = (dword & 0xFF) as u8;