public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] hpfs: Annotate struct hpfs_dirent with __counted_by
@ 2024-05-13 23:45 Bill Wendling
  2024-05-14  1:29 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Bill Wendling @ 2024-05-13 23:45 UTC (permalink / raw)
  To: Mikulas Patocka, Kees Cook, Gustavo A . R . Silva,
	Nathan Chancellor, Nick Desaulniers, Justin Stitt, LKML,
	linux-hardening, clang-built-linux

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@artax.karlin.mff.cuni.cz>
Cc: Kees Cook <keescook@chromium.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
Cc: llvm@lists.linux.dev
Signed-off-by: Bill Wendling <morbo@google.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hpfs: Annotate struct hpfs_dirent with __counted_by
  2024-05-13 23:45 [PATCH] hpfs: Annotate struct hpfs_dirent with __counted_by Bill Wendling
@ 2024-05-14  1:29 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2024-05-14  1:29 UTC (permalink / raw)
  To: Bill Wendling
  Cc: Mikulas Patocka, Gustavo A . R . Silva, Nathan Chancellor,
	Nick Desaulniers, Justin Stitt, LKML, linux-hardening,
	clang-built-linux

On Mon, May 13, 2024 at 04:45:54PM -0700, Bill Wendling wrote:
> 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@artax.karlin.mff.cuni.cz>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Justin Stitt <justinstitt@google.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Signed-off-by: Bill Wendling <morbo@google.com>
> ---
>  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. */

Looking through struct hpfs_dirent::name uses, I think everything checks
out. I do see some confusing manipulations in hpfs_add_de(), though. I
*think* it'll be okay, though.

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-14  1:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-13 23:45 [PATCH] hpfs: Annotate struct hpfs_dirent with __counted_by Bill Wendling
2024-05-14  1:29 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox