Skip to contentSkip to conversation

firewire: core: add __counted_by_ptr to struct fw_packet

PATCH Applied Bill Wendling 2 participants 2 messages Sep 25 – Sep 27 Firewire

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firewire: core: add __counted_by_ptr to struct fw_packet

In 'struct fw_packet', the 'payload' field points to a buffer of size 'payload_length' bytes. To enable compiler bounds checking (via KASAN and __builtin_dynamic_object_size), add the '__counted_by_ptr' attribute to the 'payload' pointer, associated with the 'payload_length' count.

A thorough analysis of all allocation and initialization points for 'struct fw_packet' was conducted. The pointer and its length are assigned together.

Because the count field is always correctly initialized before the pointer is accessed, the '__counted_by_ptr' attribute is fully safe and will not cause runtime false positives or panics.

---
 include/linux/firewire.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/firewire.h +1 -1
index fd35a6570cd8..9f313b47a694 100644
@@ -322,7 +322,7 @@ struct fw_packet {
 	int generation;
 	u32 header[4];
 	size_t header_length;
-	void *payload;
+	void *payload __counted_by_ptr(payload_length);
 	size_t payload_length;
 	dma_addr_t payload_bus;
 	bool payload_mapped;
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
maintainer Applied
#1 lore raw
Quoted 13 lines · Bill Wendling

In 'struct fw_packet', the 'payload' field points to a buffer of size 'payload_length' bytes. To enable compiler bounds checking (via KASAN and __builtin_dynamic_object_size), add the '__counted_by_ptr' attribute to the 'payload' pointer, associated with the 'payload_length' count.

A thorough analysis of all allocation and initialization points for 'struct fw_packet' was conducted. The pointer and its length are assigned together.

Because the count field is always correctly initialized before the pointer is accessed, the '__counted_by_ptr' attribute is fully safe and will not cause runtime false positives or panics.

Quoted 6 lines
---
 include/linux/firewire.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-next branch.

Thanks

Takashi Sakamoto