Skip to contentSkip to conversation

ecryptfs: Annotate struct ecryptfs_message with __counted_by

PATCH Applied Thorsten Blum 3 participants 3 messages Jan 12 – Jan 13 Ecrypt file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ecryptfs: Annotate struct ecryptfs_message with __counted_by

Add the __counted_by() compiler attribute to the flexible array member 'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.

---
 fs/ecryptfs/ecryptfs_kernel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ecryptfs/ecryptfs_kernel.h +1 -1
index 62a2ea7f59ed..f58b12be8267 100644
@@ -359,7 +359,7 @@ struct ecryptfs_message {
 	/* Inherits from msg_ctx->index */
 	u32 index;
 	u32 data_len;
-	u8 data[];
+	u8 data[] __counted_by(data_len);
 };
 
 struct ecryptfs_msg_ctx {
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Thorsten Blum

Add the __counted_by() compiler attribute to the flexible array member 'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.

Nice! I wasn't aware of this attribute. I'm surprised it isn't documented under Documentation/.

Thank you!

Tyler

Quoted 21 lines
---
 fs/ecryptfs/ecryptfs_kernel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ecryptfs/ecryptfs_kernel.h +1 -1
index 62a2ea7f59ed..f58b12be8267 100644
@@ -359,7 +359,7 @@ struct ecryptfs_message {
 	/* Inherits from msg_ctx->index */
 	u32 index;
 	u32 data_len;
-	u8 data[];
+	u8 data[] __counted_by(data_len);
 };
 
 struct ecryptfs_msg_ctx {
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
Applied
#2 lore raw
In reply to Thorsten Blum
Quoted 5 lines · Thorsten Blum

Add the __counted_by() compiler attribute to the flexible array member 'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.

Applied to for-next/hardening, thanks!

[1/1] ecryptfs: Annotate struct ecryptfs_message with __counted_by

      https://git.kernel.org/kees/c/574d944d2ff3

Take care,

Signature · 1 line
Kees Cook