Re: [PATCH 0/2] Add __counted_by_ptr macro

From: Kees Cook

Date: Fri Nov 21 2025 - 18:25:31 EST


On Fri, Nov 21, 2025 at 07:39:42PM +0000, Bill Wendling wrote:
> These patches add the __counted_by_ptr macro and then uses it in
> mm/memblock.h. The name of the __counted_by_ptr attribute is the same as
> __counted_by, but two different macros are needed, because of feature
> skew in GCC and clang. Once the minmum versions of the compilers support
> 'counted_by' on both flexible array members and pointers in structs,
> this macro will become obsolete.
>
> Bill Wendling (2):
> Compiler Attributes: Add __counted_by_ptr macro
> memblock: annotate struct memblock_type with __counted_by_ptr

Based on this[1] thread, I think we'll need to wait for GCC and Clang to
release with the "void *" support first, and then push the counted_by up
to that version to cover flexible arrays, pointers, and void *.

-Kees

[1] https://lore.kernel.org/lkml/20251021095447.GL3245006@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

-Kees

--
Kees Cook