diff mbox series

[v3,1/1] ARM: kprobes: Explicitly reserve r7 for local variables

Message ID 20231120032909.19186-1-quic_aiquny@quicinc.com (mailing list archive)
State Not Applicable
Headers show
Series [v3,1/1] ARM: kprobes: Explicitly reserve r7 for local variables | expand

Commit Message

Aiqun Yu (Maria) Nov. 20, 2023, 3:29 a.m. UTC
Registers r7 is removed in clobber list, so compiler may choose r7 for
local variables usage, while r7 will be actually updated by the inline asm
code. This caused the runtime behavior wrong.
While those kind of reserved registers cannot be set to clobber list
because of error like "inline asm clobber list contains reserved
registers".
Explicitly reserve r7 by adding attribute no-omit-frame-pointer for this
file, then in T32 asm code r7 is used as a frame pointer and is not
available for use as a general-purpose register.
Note that "no-omit-frame-pointer" will make the code size a little bigger
to store the stack frame pointer.

Fixes: dd12e97f3c72 ("ARM: kprobes: treat R7 as the frame pointer register in Thumb2 builds")
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Maria Yu <quic_aiquny@quicinc.com>
Cc: stable@vger.kernel.org
---
 arch/arm/probes/kprobes/Makefile | 1 +
 1 file changed, 1 insertion(+)


base-commit: 98b1cc82c4affc16f5598d4fa14b1858671b2263

Comments

Ard Biesheuvel Nov. 21, 2023, 4:11 p.m. UTC | #1
On Sun, 19 Nov 2023 at 22:29, Maria Yu <quic_aiquny@quicinc.com> wrote:
>
> Registers r7 is removed in clobber list, so compiler may choose r7 for
> local variables usage, while r7 will be actually updated by the inline asm
> code. This caused the runtime behavior wrong.
> While those kind of reserved registers cannot be set to clobber list
> because of error like "inline asm clobber list contains reserved
> registers".
> Explicitly reserve r7 by adding attribute no-omit-frame-pointer for this
> file, then in T32 asm code r7 is used as a frame pointer and is not
> available for use as a general-purpose register.
> Note that "no-omit-frame-pointer" will make the code size a little bigger
> to store the stack frame pointer.
>
> Fixes: dd12e97f3c72 ("ARM: kprobes: treat R7 as the frame pointer register in Thumb2 builds")
> Suggested-by: Ard Biesheuvel <ardb@kernel.org>
> Signed-off-by: Maria Yu <quic_aiquny@quicinc.com>
> Cc: stable@vger.kernel.org
> ---
>  arch/arm/probes/kprobes/Makefile | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm/probes/kprobes/Makefile b/arch/arm/probes/kprobes/Makefile
> index 6159010dac4a..b1f21e78950b 100644
> --- a/arch/arm/probes/kprobes/Makefile
> +++ b/arch/arm/probes/kprobes/Makefile
> @@ -8,6 +8,7 @@ test-kprobes-objs               := test-core.o
>
>  ifdef CONFIG_THUMB2_KERNEL
>  obj-$(CONFIG_KPROBES)          += actions-thumb.o checkers-thumb.o
> +CFLAGS_actions-thumb.o         += -fno-omit-frame-pointer
>  test-kprobes-objs              += test-thumb.o
>  else
>  obj-$(CONFIG_KPROBES)          += actions-arm.o checkers-arm.o
>

If Nathan is happy with this, I think we can drop this into the patch tracker.
Nathan Chancellor Nov. 21, 2023, 4:38 p.m. UTC | #2
On Tue, Nov 21, 2023 at 11:11:56AM -0500, Ard Biesheuvel wrote:
> On Sun, 19 Nov 2023 at 22:29, Maria Yu <quic_aiquny@quicinc.com> wrote:
> >
> > Registers r7 is removed in clobber list, so compiler may choose r7 for
> > local variables usage, while r7 will be actually updated by the inline asm
> > code. This caused the runtime behavior wrong.
> > While those kind of reserved registers cannot be set to clobber list
> > because of error like "inline asm clobber list contains reserved
> > registers".
> > Explicitly reserve r7 by adding attribute no-omit-frame-pointer for this
> > file, then in T32 asm code r7 is used as a frame pointer and is not
> > available for use as a general-purpose register.
> > Note that "no-omit-frame-pointer" will make the code size a little bigger
> > to store the stack frame pointer.
> >
> > Fixes: dd12e97f3c72 ("ARM: kprobes: treat R7 as the frame pointer register in Thumb2 builds")
> > Suggested-by: Ard Biesheuvel <ardb@kernel.org>
> > Signed-off-by: Maria Yu <quic_aiquny@quicinc.com>
> > Cc: stable@vger.kernel.org
> > ---
> >  arch/arm/probes/kprobes/Makefile | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/arm/probes/kprobes/Makefile b/arch/arm/probes/kprobes/Makefile
> > index 6159010dac4a..b1f21e78950b 100644
> > --- a/arch/arm/probes/kprobes/Makefile
> > +++ b/arch/arm/probes/kprobes/Makefile
> > @@ -8,6 +8,7 @@ test-kprobes-objs               := test-core.o
> >
> >  ifdef CONFIG_THUMB2_KERNEL
> >  obj-$(CONFIG_KPROBES)          += actions-thumb.o checkers-thumb.o
> > +CFLAGS_actions-thumb.o         += -fno-omit-frame-pointer
> >  test-kprobes-objs              += test-thumb.o
> >  else
> >  obj-$(CONFIG_KPROBES)          += actions-arm.o checkers-arm.o
> >
> 
> If Nathan is happy with this, I think we can drop this into the patch tracker.

I have no qualms with this approach, there are no issues with the couple
of LLVM versions that I tested.

Cheers,
Nathan
diff mbox series

Patch

diff --git a/arch/arm/probes/kprobes/Makefile b/arch/arm/probes/kprobes/Makefile
index 6159010dac4a..b1f21e78950b 100644
--- a/arch/arm/probes/kprobes/Makefile
+++ b/arch/arm/probes/kprobes/Makefile
@@ -8,6 +8,7 @@  test-kprobes-objs		:= test-core.o
 
 ifdef CONFIG_THUMB2_KERNEL
 obj-$(CONFIG_KPROBES)		+= actions-thumb.o checkers-thumb.o
+CFLAGS_actions-thumb.o		+= -fno-omit-frame-pointer
 test-kprobes-objs		+= test-thumb.o
 else
 obj-$(CONFIG_KPROBES)		+= actions-arm.o checkers-arm.o