All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: Annotate struct ff_device with __counted_by
@ 2023-10-06 20:17 Kees Cook
  2023-10-06 20:47 ` Gustavo A. R. Silva
  2023-10-14  3:04 ` Dmitry Torokhov
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2023-10-06 20:17 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Kees Cook, Gustavo A. R. Silva, linux-input, linux-hardening,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm

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

Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-input@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/input.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/input.h b/include/linux/input.h
index 49790c1bd2c4..de6503c0edb8 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -562,7 +562,7 @@ struct ff_device {
 
 	int max_effects;
 	struct ff_effect *effects;
-	struct file *effect_owners[];
+	struct file *effect_owners[] __counted_by(max_effects);
 };
 
 int input_ff_create(struct input_dev *dev, unsigned int max_effects);
-- 
2.34.1


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

* Re: [PATCH] Input: Annotate struct ff_device with __counted_by
  2023-10-06 20:17 [PATCH] Input: Annotate struct ff_device with __counted_by Kees Cook
@ 2023-10-06 20:47 ` Gustavo A. R. Silva
  2023-10-14  3:04 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-06 20:47 UTC (permalink / raw)
  To: Kees Cook, Dmitry Torokhov
  Cc: Gustavo A. R. Silva, linux-input, linux-hardening,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm



On 10/6/23 22:17, Kees Cook 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 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 ff_device.
> 
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-input@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>

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

Thanks!
-- 
Gustavo

> ---
>   include/linux/input.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/input.h b/include/linux/input.h
> index 49790c1bd2c4..de6503c0edb8 100644
> --- a/include/linux/input.h
> +++ b/include/linux/input.h
> @@ -562,7 +562,7 @@ struct ff_device {
>   
>   	int max_effects;
>   	struct ff_effect *effects;
> -	struct file *effect_owners[];
> +	struct file *effect_owners[] __counted_by(max_effects);
>   };
>   
>   int input_ff_create(struct input_dev *dev, unsigned int max_effects);

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

* Re: [PATCH] Input: Annotate struct ff_device with __counted_by
  2023-10-06 20:17 [PATCH] Input: Annotate struct ff_device with __counted_by Kees Cook
  2023-10-06 20:47 ` Gustavo A. R. Silva
@ 2023-10-14  3:04 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2023-10-14  3:04 UTC (permalink / raw)
  To: Kees Cook
  Cc: Gustavo A. R. Silva, linux-input, linux-hardening,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm

On Fri, Oct 06, 2023 at 01:17:39PM -0700, Kees Cook 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 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 ff_device.
> 
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-input@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>

Applied, thank you.

-- 
Dmitry

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

end of thread, other threads:[~2023-10-14  3:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 20:17 [PATCH] Input: Annotate struct ff_device with __counted_by Kees Cook
2023-10-06 20:47 ` Gustavo A. R. Silva
2023-10-14  3:04 ` Dmitry Torokhov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.