Re: [PATCH RESEND] arm64: patching: Annotate text_addrs, new_insns with __counted_by_ptr()

From: Catalin Marinas

Date: Tue Nov 24 2026 - 07:13:26 EST


On Wed, Nov 11, 2026 at 05:45:14PM +0100, Thorsten Blum wrote:
> Add __counted_by_ptr() to aarch64_insn_patch::text_addrs and
> aarch64_insn_patch::new_insns to enable access bounds checking via
> CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.
[...]
> struct aarch64_insn_patch {
> - void **text_addrs;
> - u32 *new_insns;
> + void **text_addrs __counted_by_ptr(insn_cnt);
> + u32 *new_insns __counted_by_ptr(insn_cnt);

I'm not sure it buys us anything. The only accesses to these arrays are
in aarch64_insn_patch_text_cb() in a loop already bounded by
pp->insn_cnt. UBSAN just repeats the loop condition. There's no
mem*/str* use of these pointers either, so FORTIFY_SOURCE doesn't
matter.

The annotation can't catch a wrong count from the caller since insn_cnt
is taken directly from the cnt argument of aarch64_insn_patch_text().

So, I don't think this patch is needed.

--
Catalin