mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RESEND] arm64: patching: Annotate text_addrs, new_insns with __counted_by_ptr()
@ 2026-11-11 16:45 Thorsten Blum
  2026-11-24 12:13 ` Catalin Marinas
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-11-11 16:45 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Mark Rutland, Kees Cook,
	Gustavo A. R. Silva, Thorsten Blum
  Cc: linux-arm-kernel, linux-kernel, linux-hardening

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.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/arm64/kernel/patching.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c
index 09f019c6547a..5fc7805a93f0 100644
--- a/arch/arm64/kernel/patching.c
+++ b/arch/arm64/kernel/patching.c
@@ -194,8 +194,8 @@ int __kprobes aarch64_insn_patch_text_nosync(void *addr, u32 insn)
 }
 
 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);
 	int		insn_cnt;
 	atomic_t	cpu_count;
 };

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

* Re: [PATCH RESEND] arm64: patching: Annotate text_addrs, new_insns with __counted_by_ptr()
  2026-11-11 16:45 [PATCH RESEND] arm64: patching: Annotate text_addrs, new_insns with __counted_by_ptr() Thorsten Blum
@ 2026-11-24 12:13 ` Catalin Marinas
  2026-11-24 17:43   ` Thorsten Blum
  0 siblings, 1 reply; 3+ messages in thread
From: Catalin Marinas @ 2026-11-24 12:13 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Will Deacon, Mark Rutland, Kees Cook, Gustavo A. R. Silva,
	linux-arm-kernel, linux-kernel, linux-hardening

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

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

* Re: [PATCH RESEND] arm64: patching: Annotate text_addrs, new_insns with __counted_by_ptr()
  2026-11-24 12:13 ` Catalin Marinas
@ 2026-11-24 17:43   ` Thorsten Blum
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-11-24 17:43 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Will Deacon, Mark Rutland, Kees Cook, Gustavo A. R. Silva,
	linux-arm-kernel, linux-kernel, linux-hardening

On Tue, Nov 24, 2026 at 12:13:14PM +0000, Catalin Marinas wrote:
> 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.

Fair points. It was meant as a hardening change to prevent future errors
and document the relationship, but since nothing is gained today, I'm
happy to drop it.

Thanks,
Thorsten

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

end of thread, other threads:[~2026-11-24 17:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 16:45 [PATCH RESEND] arm64: patching: Annotate text_addrs, new_insns with __counted_by_ptr() Thorsten Blum
2026-11-24 12:13 ` Catalin Marinas
2026-11-24 17:43   ` Thorsten Blum

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

all inboxes | Powered by JetHome®