fpga: Add __counted_by_ptr annotation to fpga_image_info
PATCH 1/1 fpga: Add __counted_by_ptr annotation to fpga_image_info
The 'const char *buf' pointer in 'struct fpga_image_info' is used to hold the FPGA image data, and its element count is stored in 'size_t count'. To strengthen runtime boundary checks via KASAN and '__builtin_dynamic_object_size', annotate the 'buf' field with the '__counted_by_ptr' attribute, pointing to 'count'.
All allocation and assignment paths of 'struct fpga_image_info' have been verified to ensure that 'count' is initialized before or alongside 'buf', and 'buf' is never accessed before 'count' is set.
--- include/linux/fpga/fpga-mgr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fpga/fpga-mgr.h +1 -1
@@ -103,7 +103,7 @@ struct fpga_image_info {u32 config_complete_timeout_us;char *firmware_name;struct sg_table *sgt; -const char *buf; + const char *buf __counted_by_ptr(count);size_t count;size_t header_size;size_t data_size;
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog