All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maria Yu <quic_aiquny@quicinc.com>
To: <linux@armlinux.org.uk>, <ardb@kernel.org>, <mhiramat@kernel.org>
Cc: Maria Yu <quic_aiquny@quicinc.com>, <kernel@quicinc.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<quic_lijuang@quicinc.com>, <stable@vger.kernel.org>
Subject: [PATCH v2 1/1] ARM: kprobes: Explicitly reserve r7 for local variables
Date: Wed, 15 Nov 2023 17:58:30 +0800	[thread overview]
Message-ID: <20231115095830.20607-1-quic_aiquny@quicinc.com> (raw)

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 needed
function, 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. So limited to needed functions can have
the less impact than the full source file.

Fixes: dd12e97f3c72 ("ARM: kprobes: treat R7 as the frame pointer register in Thumb2 builds")
Signed-off-by: Maria Yu <quic_aiquny@quicinc.com>
Cc: stable@vger.kernel.org
---
 arch/arm/probes/kprobes/actions-thumb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/probes/kprobes/actions-thumb.c b/arch/arm/probes/kprobes/actions-thumb.c
index 51624fc263fc..c2fdaf9f6dba 100644
--- a/arch/arm/probes/kprobes/actions-thumb.c
+++ b/arch/arm/probes/kprobes/actions-thumb.c
@@ -438,7 +438,7 @@ t16_simulate_branch(probes_opcode_t insn,
 	regs->ARM_pc = pc + (offset * 2);
 }
 
-static unsigned long __kprobes
+static unsigned long __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_loregs(probes_opcode_t insn,
 		   struct arch_probes_insn *asi, struct pt_regs *regs)
 {
@@ -521,7 +521,7 @@ t16_decode_hiregs(probes_opcode_t insn, struct arch_probes_insn *asi,
 	return INSN_GOOD;
 }
 
-static void __kprobes
+static void __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_push(probes_opcode_t insn,
 		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
@@ -557,7 +557,7 @@ t16_decode_push(probes_opcode_t insn, struct arch_probes_insn *asi,
 	return INSN_GOOD;
 }
 
-static void __kprobes
+static void __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_pop_nopc(probes_opcode_t insn,
 		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
@@ -576,7 +576,7 @@ t16_emulate_pop_nopc(probes_opcode_t insn,
 		);
 }
 
-static void __kprobes
+static void __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_pop_pc(probes_opcode_t insn,
 		struct arch_probes_insn *asi, struct pt_regs *regs)
 {

base-commit: 9bacdd8996c77c42ca004440be610692275ff9d0
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: Maria Yu <quic_aiquny@quicinc.com>
To: <linux@armlinux.org.uk>, <ardb@kernel.org>, <mhiramat@kernel.org>
Cc: Maria Yu <quic_aiquny@quicinc.com>, <kernel@quicinc.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<quic_lijuang@quicinc.com>, <stable@vger.kernel.org>
Subject: [PATCH v2 1/1] ARM: kprobes: Explicitly reserve r7 for local variables
Date: Wed, 15 Nov 2023 17:58:30 +0800	[thread overview]
Message-ID: <20231115095830.20607-1-quic_aiquny@quicinc.com> (raw)

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 needed
function, 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. So limited to needed functions can have
the less impact than the full source file.

Fixes: dd12e97f3c72 ("ARM: kprobes: treat R7 as the frame pointer register in Thumb2 builds")
Signed-off-by: Maria Yu <quic_aiquny@quicinc.com>
Cc: stable@vger.kernel.org
---
 arch/arm/probes/kprobes/actions-thumb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/probes/kprobes/actions-thumb.c b/arch/arm/probes/kprobes/actions-thumb.c
index 51624fc263fc..c2fdaf9f6dba 100644
--- a/arch/arm/probes/kprobes/actions-thumb.c
+++ b/arch/arm/probes/kprobes/actions-thumb.c
@@ -438,7 +438,7 @@ t16_simulate_branch(probes_opcode_t insn,
 	regs->ARM_pc = pc + (offset * 2);
 }
 
-static unsigned long __kprobes
+static unsigned long __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_loregs(probes_opcode_t insn,
 		   struct arch_probes_insn *asi, struct pt_regs *regs)
 {
@@ -521,7 +521,7 @@ t16_decode_hiregs(probes_opcode_t insn, struct arch_probes_insn *asi,
 	return INSN_GOOD;
 }
 
-static void __kprobes
+static void __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_push(probes_opcode_t insn,
 		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
@@ -557,7 +557,7 @@ t16_decode_push(probes_opcode_t insn, struct arch_probes_insn *asi,
 	return INSN_GOOD;
 }
 
-static void __kprobes
+static void __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_pop_nopc(probes_opcode_t insn,
 		struct arch_probes_insn *asi, struct pt_regs *regs)
 {
@@ -576,7 +576,7 @@ t16_emulate_pop_nopc(probes_opcode_t insn,
 		);
 }
 
-static void __kprobes
+static void __kprobes __attribute__((optimize("no-omit-frame-pointer")))
 t16_emulate_pop_pc(probes_opcode_t insn,
 		struct arch_probes_insn *asi, struct pt_regs *regs)
 {

base-commit: 9bacdd8996c77c42ca004440be610692275ff9d0
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2023-11-15  9:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15  9:58 Maria Yu [this message]
2023-11-15  9:58 ` [PATCH v2 1/1] ARM: kprobes: Explicitly reserve r7 for local variables Maria Yu
2023-11-16 11:11 ` Ard Biesheuvel
2023-11-16 11:11   ` Ard Biesheuvel
2023-11-16 17:24 ` Nathan Chancellor
2023-11-16 17:24   ` Nathan Chancellor
2023-11-16 17:36   ` Ard Biesheuvel
2023-11-16 17:36     ` Ard Biesheuvel
2023-11-20  2:00     ` Aiqun(Maria) Yu
2023-11-20  2:00       ` Aiqun(Maria) Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231115095830.20607-1-quic_aiquny@quicinc.com \
    --to=quic_aiquny@quicinc.com \
    --cc=ardb@kernel.org \
    --cc=kernel@quicinc.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mhiramat@kernel.org \
    --cc=quic_lijuang@quicinc.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.