Skip to contentSkip to conversation

scsi: target: tcmu: Annotate struct tcmu_tmr with __counted_by

PATCH Applied Kees Cook 4 participants 5 messages Sep 22, 2023 – Oct 10, 2023

Subsystems (3)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 scsi: target: tcmu: Annotate struct tcmu_tmr 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 checking 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 tcmu_tmr.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

---
 drivers/target/target_core_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/target_core_user.c +1 -1
index 22cc6cac0ba2..7eb94894bd68 100644
@@ -201,7 +201,7 @@ struct tcmu_tmr {
 
 	uint8_t tmr_type;
 	uint32_t tmr_cmd_cnt;
-	int16_t tmr_cmd_ids[];
+	int16_t tmr_cmd_ids[] __counted_by(tmr_cmd_cnt);
 };
 
 /*
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 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 checking 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 tcmu_tmr.

Quoted 7 lines

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Thanks

Signature · 1 line
Gustavo
Quoted 17 lines
---
  drivers/target/target_core_user.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/target_core_user.c +1 -1
index 22cc6cac0ba2..7eb94894bd68 100644
@@ -201,7 +201,7 @@ struct tcmu_tmr {
 
  	uint8_t tmr_type;
  	uint32_t tmr_cmd_cnt;
-	int16_t tmr_cmd_ids[];
+	int16_t tmr_cmd_ids[] __counted_by(tmr_cmd_cnt);
  };
 
  /*
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Kees Cook
Quoted 24 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 checking 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 tcmu_tmr.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

---
  drivers/target/target_core_user.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/target_core_user.c +0 -0
index 22cc6cac0ba2..7eb94894bd68 100644

drivers/target/target_core_user.c struct tcmu_tmr { · line 207

Quoted 8 lines
drivers/target/target_core_user.c +1 -1
@@ -201,7 +201,7 @@ struct tcmu_tmr {
 
  	uint8_t tmr_type;
  	uint32_t tmr_cmd_cnt;
-	int16_t tmr_cmd_ids[];
+	int16_t tmr_cmd_ids[] __counted_by(tmr_cmd_cnt);
  };
 
  /*

Thank you,
Bodo

#3 lore raw
In reply to Kees Cook

Kees,

Quoted 5 lines

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 checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

Applied to 6.7/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
In reply to Kees Cook
Quoted 9 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 checking 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 tcmu_tmr.

[...]

Applied to 6.7/scsi-queue, thanks!

[1/1] scsi: target: tcmu: Annotate struct tcmu_tmr with __counted_by

      https://git.kernel.org/mkp/scsi/c/caf22c969ed1
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering