Skip to contentSkip to conversation

Input: Annotate struct ff_device with __counted_by

PATCH Applied Kees Cook 3 participants 3 messages Oct 6, 2023 – Oct 14, 2023

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 Input: Annotate struct ff_device with __counted_by

Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

As found with Coccinelle[1], add __counted_by for struct ff_device.

---
 include/linux/input.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/input.h +1 -1
index 49790c1bd2c4..de6503c0edb8 100644
@@ -562,7 +562,7 @@ struct ff_device {
 
 	int max_effects;
 	struct ff_effect *effects;
-	struct file *effect_owners[];
+	struct file *effect_owners[] __counted_by(max_effects);
 };
 
 int input_ff_create(struct input_dev *dev, unsigned int max_effects);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Kees Cook

Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

Quoted 8 lines

As found with Coccinelle[1], add __counted_by for struct ff_device.

Thanks!

Signature · 1 line
Gustavo
Quoted 17 lines
---
  include/linux/input.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/input.h +1 -1
index 49790c1bd2c4..de6503c0edb8 100644
@@ -562,7 +562,7 @@ struct ff_device {
 
  	int max_effects;
  	struct ff_effect *effects;
-	struct file *effect_owners[];
+	struct file *effect_owners[] __counted_by(max_effects);
  };
 
  int input_ff_create(struct input_dev *dev, unsigned int max_effects);
maintainer Applied
#2 lore raw
In reply to Kees Cook
Quoted 6 lines · Kees Cook

Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

Quoted 8 lines

As found with Coccinelle[1], add __counted_by for struct ff_device.

Applied, thank you.

Signature · 1 line
Dmitry