[PATCH] hpfs: Annotate struct hpfs_dirent with __counted_by

From: Bill Wendling
Date: Mon May 13 2024 - 19:46:23 EST


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).

Cc: Mikulas Patocka <mikulas@xxxxxxxxxxxxxxxxxxxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
Cc: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>
Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
Cc: Justin Stitt <justinstitt@xxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-hardening@xxxxxxxxxxxxxxx
Cc: llvm@xxxxxxxxxxxxxxx
Signed-off-by: Bill Wendling <morbo@xxxxxxxxxx>
---
fs/hpfs/hpfs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/hpfs/hpfs.h b/fs/hpfs/hpfs.h
index 281dec8f636b..ac137787f1f9 100644
--- a/fs/hpfs/hpfs.h
+++ b/fs/hpfs/hpfs.h
@@ -357,7 +357,7 @@ struct hpfs_dirent {
u8 ix; /* code page index (of filename), see
struct code_page_data */
u8 namelen; /* file name length */
- u8 name[]; /* file name */
+ u8 name[] __counted_by(namelen); /* file name */
/* dnode_secno down; btree down pointer, if present,
follows name on next word boundary, or maybe it
precedes next dirent, which is on a word boundary. */
--
2.45.0.rc1.225.g2a3ae87e7f-goog