[PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by

Javier Carrasco posted 2 patches 1 year, 7 months ago
[PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by
Posted by Javier Carrasco 1 year, 7 months ago
Use the __counted_by compiler attribute for the data[] flexible array
member to improve the results of array bound sanitizers.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/input/misc/ims-pcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
index 408a586f8c36..91f8ad826238 100644
--- a/drivers/input/misc/ims-pcu.c
+++ b/drivers/input/misc/ims-pcu.c
@@ -761,7 +761,7 @@ static int ims_pcu_switch_to_bootloader(struct ims_pcu *pcu)
 struct ims_pcu_flash_fmt {
 	__le32 addr;
 	u8 len;
-	u8 data[];
+	u8 data[] __counted_by(len);
 };
 
 static unsigned int ims_pcu_count_fw_records(const struct firmware *fw)

-- 
2.40.1
Re: [PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by
Posted by Dmitry Torokhov 1 year, 7 months ago
On Wed, Jun 19, 2024 at 11:13:21PM +0200, Javier Carrasco wrote:
> Use the __counted_by compiler attribute for the data[] flexible array
> member to improve the results of array bound sanitizers.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Applied, thank you.

-- 
Dmitry
Re: [PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by
Posted by Gustavo A. R. Silva 1 year, 7 months ago

On 19/06/24 23:13, Javier Carrasco wrote:
> Use the __counted_by compiler attribute for the data[] flexible array
> member to improve the results of array bound sanitizers.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/input/misc/ims-pcu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
> index 408a586f8c36..91f8ad826238 100644
> --- a/drivers/input/misc/ims-pcu.c
> +++ b/drivers/input/misc/ims-pcu.c
> @@ -761,7 +761,7 @@ static int ims_pcu_switch_to_bootloader(struct ims_pcu *pcu)
>   struct ims_pcu_flash_fmt {
>   	__le32 addr;
>   	u8 len;
> -	u8 data[];
> +	u8 data[] __counted_by(len);
>   };
>   
>   static unsigned int ims_pcu_count_fw_records(const struct firmware *fw)
>
Re: [PATCH 1/2] Input: ims-pcu - annotate struct ims_pcu_flash_fmt with __counted_by
Posted by Kees Cook 1 year, 7 months ago
On Wed, Jun 19, 2024 at 11:13:21PM +0200, Javier Carrasco wrote:
> Use the __counted_by compiler attribute for the data[] flexible array
> member to improve the results of array bound sanitizers.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Looks good to me. Thanks!

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook