* [PATCH] PCI: imx6: Fix kernel oops on user-mode external aborts
@ 2026-11-24 13:14 Stefan Ghetu
2026-11-24 13:23 ` Daniel Baluta
2026-11-25 20:56 ` Frank Li
0 siblings, 2 replies; 3+ messages in thread
From: Stefan Ghetu @ 2026-11-24 13:14 UTC (permalink / raw)
To: linux-pci
Cc: imx, linux-arm-kernel, linux-kernel, Richard Zhu, Lucas Stach,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Frank Li,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Sahil Malhotra, Stefan Ghetu
From: Richard Zhu <hongxing.zhu@nxp.com>
When a user-space process (e.g., memtool) accesses an OP-TEE protected
memory region, the SoC raises an external abort (FSR code 8). The
imx6q_pcie_abort_handler() registered for this fault code attempts to
decode the faulting instruction by directly dereferencing the saved PC:
unsigned long instr = *(unsigned long *)pc;
However, for user-mode aborts, the PC points to user-space memory. This
unchecked dereference from kernel mode triggers a secondary domain fault,
which is not hooked by any handler. The fault then escalates to an
"Internal error: Oops" and crashes the kernel:
Unhandled fault: page domain fault (0x01b) at 0x006e3316
Internal error: : 1b [#1] SMP ARM
CPU: 0 UID: 0 PID: 1415 Comm: memtool
PC is at imx6q_pcie_abort_handler+0x4/0x7c
LR is at do_DataAbort+0x3c/0xb0
The abort handler was designed only for kernel-mode PCIe configuration or
I/O space accesses and never hardened for user-mode faults.
Fix this by:
1. Checking if the abort occurred in user mode and returning early to let
the normal fault path deliver SIGBUS to the faulting task (as already
specified in the hook_fault_code() registration).
2. Using get_kernel_nofault() to safely read the instruction for
kernel-mode aborts, preventing recursive faults if the kernel PC is
invalid.
This ensures user-mode aborts are handled gracefully without crashing the
kernel, while preserving the existing fixup behavior for legitimate
kernel-mode PCIe access faults.
Fixes: 415b6185c541 ("PCI: imx6: Fix config read timeout handling")
Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
Signed-off-by: Stefan Ghetu <stefan.ghetu@nxp.com>
---
drivers/pci/controller/dwc/pci-imx6.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 0377d72b54ea6..9a9cc35f6559f 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -669,8 +669,24 @@ static int imx6q_pcie_abort_handler(unsigned long addr,
unsigned int fsr, struct pt_regs *regs)
{
unsigned long pc = instruction_pointer(regs);
- unsigned long instr = *(unsigned long *)pc;
- int reg = (instr >> 12) & 15;
+ unsigned long instr;
+ int reg;
+
+ /*
+ * This handler is only for kernel-mode PCIe config/IO space accesses.
+ * User-mode aborts must be handled by the normal fault path, which will
+ * deliver SIGBUS to the faulting task. Dereferencing a user-mode PC
+ * from kernel context triggers a secondary fault that escalates to an
+ * unhandled kernel oops.
+ */
+ if (user_mode(regs))
+ return 1;
+
+ /* Safely read the faulting instruction to prevent recursive faults */
+ if (get_kernel_nofault(instr, (unsigned long *)pc))
+ return 1;
+
+ reg = (instr >> 12) & 15;
/*
* If the instruction being executed was a read,
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: imx6: Fix kernel oops on user-mode external aborts
2026-11-24 13:14 [PATCH] PCI: imx6: Fix kernel oops on user-mode external aborts Stefan Ghetu
@ 2026-11-24 13:23 ` Daniel Baluta
2026-11-25 20:56 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Baluta @ 2026-11-24 13:23 UTC (permalink / raw)
To: Stefan Ghetu, linux-pci
Cc: imx, linux-arm-kernel, linux-kernel, Richard Zhu, Lucas Stach,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Frank Li,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Sahil Malhotra
On 11/24/26 15:14, Stefan Ghetu wrote:
> From: Richard Zhu <hongxing.zhu@nxp.com>
>
> When a user-space process (e.g., memtool) accesses an OP-TEE protected
> memory region, the SoC raises an external abort (FSR code 8). The
> imx6q_pcie_abort_handler() registered for this fault code attempts to
> decode the faulting instruction by directly dereferencing the saved PC:
>
> unsigned long instr = *(unsigned long *)pc;
>
> However, for user-mode aborts, the PC points to user-space memory. This
> unchecked dereference from kernel mode triggers a secondary domain fault,
> which is not hooked by any handler. The fault then escalates to an
> "Internal error: Oops" and crashes the kernel:
>
> Unhandled fault: page domain fault (0x01b) at 0x006e3316
> Internal error: : 1b [#1] SMP ARM
> CPU: 0 UID: 0 PID: 1415 Comm: memtool
> PC is at imx6q_pcie_abort_handler+0x4/0x7c
> LR is at do_DataAbort+0x3c/0xb0
>
> The abort handler was designed only for kernel-mode PCIe configuration or
> I/O space accesses and never hardened for user-mode faults.
>
> Fix this by:
>
> 1. Checking if the abort occurred in user mode and returning early to let
> the normal fault path deliver SIGBUS to the faulting task (as already
> specified in the hook_fault_code() registration).
>
> 2. Using get_kernel_nofault() to safely read the instruction for
> kernel-mode aborts, preventing recursive faults if the kernel PC is
> invalid.
>
> This ensures user-mode aborts are handled gracefully without crashing the
> kernel, while preserving the existing fixup behavior for legitimate
> kernel-mode PCIe access faults.
>
> Fixes: 415b6185c541 ("PCI: imx6: Fix config read timeout handling")
> Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
> Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
> Signed-off-by: Stefan Ghetu <stefan.ghetu@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: imx6: Fix kernel oops on user-mode external aborts
2026-11-24 13:14 [PATCH] PCI: imx6: Fix kernel oops on user-mode external aborts Stefan Ghetu
2026-11-24 13:23 ` Daniel Baluta
@ 2026-11-25 20:56 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-11-25 20:56 UTC (permalink / raw)
To: Stefan Ghetu
Cc: linux-pci, imx, linux-arm-kernel, linux-kernel, Richard Zhu,
Lucas Stach, Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Frank Li,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Sahil Malhotra
On Tue, Nov 24, 2026 at 03:14:32PM +0200, Stefan Ghetu wrote:
> From: Richard Zhu <hongxing.zhu@nxp.com>
>
> When a user-space process (e.g., memtool) accesses an OP-TEE protected
> memory region, the SoC raises an external abort (FSR code 8). The
> imx6q_pcie_abort_handler() registered for this fault code attempts to
> decode the faulting instruction by directly dereferencing the saved PC:
>
> unsigned long instr = *(unsigned long *)pc;
>
> However, for user-mode aborts, the PC points to user-space memory. This
> unchecked dereference from kernel mode triggers a secondary domain fault,
> which is not hooked by any handler. The fault then escalates to an
> "Internal error: Oops" and crashes the kernel:
>
> Unhandled fault: page domain fault (0x01b) at 0x006e3316
> Internal error: : 1b [#1] SMP ARM
> CPU: 0 UID: 0 PID: 1415 Comm: memtool
> PC is at imx6q_pcie_abort_handler+0x4/0x7c
> LR is at do_DataAbort+0x3c/0xb0
>
> The abort handler was designed only for kernel-mode PCIe configuration or
> I/O space accesses and never hardened for user-mode faults.
>
> Fix this by:
>
> 1. Checking if the abort occurred in user mode and returning early to let
> the normal fault path deliver SIGBUS to the faulting task (as already
> specified in the hook_fault_code() registration).
>
> 2. Using get_kernel_nofault() to safely read the instruction for
> kernel-mode aborts, preventing recursive faults if the kernel PC is
> invalid.
>
> This ensures user-mode aborts are handled gracefully without crashing the
> kernel, while preserving the existing fixup behavior for legitimate
> kernel-mode PCIe access faults.
>
> Fixes: 415b6185c541 ("PCI: imx6: Fix config read timeout handling")
> Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
> Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
> Signed-off-by: Stefan Ghetu <stefan.ghetu@nxp.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/pci/controller/dwc/pci-imx6.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 0377d72b54ea6..9a9cc35f6559f 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -669,8 +669,24 @@ static int imx6q_pcie_abort_handler(unsigned long addr,
> unsigned int fsr, struct pt_regs *regs)
> {
> unsigned long pc = instruction_pointer(regs);
> - unsigned long instr = *(unsigned long *)pc;
> - int reg = (instr >> 12) & 15;
> + unsigned long instr;
> + int reg;
> +
> + /*
> + * This handler is only for kernel-mode PCIe config/IO space accesses.
> + * User-mode aborts must be handled by the normal fault path, which will
> + * deliver SIGBUS to the faulting task. Dereferencing a user-mode PC
> + * from kernel context triggers a secondary fault that escalates to an
> + * unhandled kernel oops.
> + */
> + if (user_mode(regs))
> + return 1;
> +
> + /* Safely read the faulting instruction to prevent recursive faults */
> + if (get_kernel_nofault(instr, (unsigned long *)pc))
> + return 1;
> +
> + reg = (instr >> 12) & 15;
>
> /*
> * If the instruction being executed was a read,
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 20:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 13:14 [PATCH] PCI: imx6: Fix kernel oops on user-mode external aborts Stefan Ghetu
2026-11-24 13:23 ` Daniel Baluta
2026-11-25 20:56 ` Frank Li
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®