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

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

Cc: Jorge Lopez <jorge.lop...@hp.com>
Cc: Hans de Goede <hdego...@redhat.com>
Cc: Mark Gross <markgr...@kernel.org>
Cc: Nathan Chancellor <nat...@kernel.org>
Cc: Nick Desaulniers <ndesaulni...@google.com>
Cc: Tom Rix <t...@redhat.com>
Cc: platform-driver-...@vger.kernel.org
Cc: l...@lists.linux.dev
Signed-off-by: Kees Cook <keesc...@chromium.org>
---
 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c 
b/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
index dea54f35b8b5..4da99cb7218d 100644
--- a/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
+++ b/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
@@ -19,7 +19,7 @@ struct bios_args {
        u32 command;
        u32 commandtype;
        u32 datasize;
-       u8 data[];
+       u8 data[] __counted_by(datasize);
 };
 
 /**
-- 
2.34.1


Reply via email to