fpga: zynqpl: fix bitstream header scan length checks
Subsystems (2)
Michal Simek
maintainercover fpga: zynqpl: fix bitstream header scan length checks
Hi,
This series fixes bitstream header scan length checks in check_data(), reachable from fpga load and fpga loadfs.
Patch 1 stops the bitstream header scan once there's no longer enough room left for a full header. The old scan kept checking positions near the end of the buffer that could never hold a complete header, and a match there caused an unbounded header read to go past the buffer end.
Patch 2 fixes zynq_loadfs() passing blocksize into zynq_validate_bitstream() after fs_read(), even when actread was smaller. Pass actread so the scan length matches the bytes actually written into the buffer.
Thanks,
Michal
Suraj Kakade (2):
fpga: zynqpl: use actread for bitstream scan in zynq_loadfs
fpga: zynqpl: stop header scan once a full header can't fit
drivers/fpga/zynqpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
---
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 1/2 fpga: zynqpl: use actread for bitstream scan in zynq_loadfs
From: Suraj Kakade <[email protected]>
zynq_loadfs() called zynq_validate_bitstream() with blocksize after fs_read(), even when actread was smaller. check_data() then scanned past the bytes actually written into the buffer.
Pass actread instead of blocksize so the header scan length matches what fs_read() wrote.
---
drivers/fpga/zynqpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/zynqpl.c +1 -1
@@ -445,7 +445,7 @@ static int zynq_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,if (fs_read (filename, (u32 ) buf, pos, blocksize, &actread) <0 )return FPGA_FAIL ; -if (zynq_validate_bitstream (desc, buf, bsize, blocksize, &swap, +if (zynq_validate_bitstream (desc, buf, bsize, actread, &swap, &partialbit))return FPGA_FAIL ;
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 2/2 fpga: zynqpl: stop header scan once a full header can't fit
In reply to Michal SimekFrom: Suraj Kakade <[email protected]>
The bitstream header scan didn't check whether enough bytes were left in the buffer before testing for a match. Near the end of the buffer this let it examine positions that could never hold a complete header, and a match there caused the subsequent header read to go past the end of the buffer.
Stop the scan once there isn't enough room left for a full header. This only bounds the scan, a buffer just big enough to match the header but with no data behind it would still pass, no minimum bitstream size is enforced here.
---
drivers/fpga/zynqpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/zynqpl.c +1 -1
@@ -135,7 +135,7 @@ static void *check_data(u8 *buf, size_t bsize, u32 *swap)u32 word, p =0 ;/* possition */ /* Because buf doesn't need to be aligned let's read it by chars */ -for (p =0 ; p < bsize; p++) { +for (p =0 ; p +sizeof (bin_format) <= bsize; p++) { word =load_word (&buf[p],SWAP_NO );debug ("%s: word %x %x/%x\n" , __func__, word, p, (u32)&buf[p]);
Signature · 1 line
2.43.0
Quoted 20 lines · Michal Simek
Hi,
This series fixes bitstream header scan length checks in
check_data(), reachable from fpga load and fpga loadfs.Patch 1 stops the bitstream header scan once there's no longer enough room left for a full header. The old scan kept checking positions near the end of the buffer that could never hold a complete header, and a match there caused an unbounded header read to go past the buffer end.
Patch 2 fixes
zynq_loadfs()passing blocksize intozynq_validate_bitstream()afterfs_read(), even when actread was smaller. Pass actread so the scan length matches the bytes actually written into the buffer.Thanks,
Michal
Quoted 9 lines
Suraj Kakade (2):
fpga: zynqpl: use actread for bitstream scan inzynq_loadfs
fpga: zynqpl: stop header scan once a full header can't fitdrivers/fpga/zynqpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)---
Applied.
M