public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] comedi: Annotate struct comedi_lrange with __counted_by
@ 2023-09-30  9:14 Christophe JAILLET
  2023-09-30 20:57 ` Kees Cook
  2023-10-01  6:43 ` Gustavo A. R. Silva
  0 siblings, 2 replies; 14+ messages in thread
From: Christophe JAILLET @ 2023-09-30  9:14 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Kees Cook, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-hardening, 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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is part of a work done in parallel of what is currently worked
on by Kees Cook.

My patches are only related to corner cases that do NOT match the
semantic of his Coccinelle script[1].

In this case, it is been spotted because of comedi_alloc_spriv().
All other usages of struct comedi_lrange seem to be static definition of
the structure that explicitly set the .length field.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
---
 include/linux/comedi/comedidev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/comedi/comedidev.h b/include/linux/comedi/comedidev.h
index 0a1150900ef3..c08416a7364b 100644
--- a/include/linux/comedi/comedidev.h
+++ b/include/linux/comedi/comedidev.h
@@ -633,7 +633,7 @@ extern const struct comedi_lrange range_unknown;
  */
 struct comedi_lrange {
 	int length;
-	struct comedi_krange range[];
+	struct comedi_krange range[] __counted_by(length);
 };
 
 /**
-- 
2.34.1


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

end of thread, other threads:[~2023-11-05 21:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-30  9:14 [PATCH] comedi: Annotate struct comedi_lrange with __counted_by Christophe JAILLET
2023-09-30 20:57 ` Kees Cook
2023-10-01  7:25   ` Julia Lawall
2023-10-01  7:50     ` Christophe JAILLET
2023-10-01  7:45   ` Julia Lawall
2023-10-01 15:26     ` Kees Cook
2023-10-01 19:14       ` Julia Lawall
2023-10-01 21:05         ` Kees Cook
2023-10-01 21:22           ` Kees Cook
2023-10-01 22:21             ` Kees Cook
2023-10-02  5:38               ` Julia Lawall
2023-10-02  7:36                 ` Kees Cook
2023-11-05 21:27             ` Christophe JAILLET
2023-10-01  6:43 ` Gustavo A. R. Silva

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