linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] PCI: imx6: Handle the abort from user-space
@ 2022-01-31  7:52 Francesco Dolcini
  2022-02-10  8:00 ` Francesco Dolcini
  0 siblings, 1 reply; 4+ messages in thread
From: Francesco Dolcini @ 2022-01-31  7:52 UTC (permalink / raw)
  To: Richard Zhu, Lucas Stach, Lorenzo Pieralisi, Rob Herring,
	Krzysztof Wilczyński, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, NXP Linux Team, Jason Liu
  Cc: linux-pci, linux-arm-kernel, linux-kernel, Bjorn Helgaas,
	Shawn Guo, Francesco Dolcini

From: Jason Liu <jason.hui.liu@nxp.com>

The driver install one hook to handle the external abort, but issue
is that if the abort introduced from user space code, the following
code unsigned long instr = *(unsigned long *)pc; which will created
another data-abort(page domain fault) if CONFIG_CPU_SW_DOMAIN_PAN.

The patch does not intent to use copy_from_user and then do the hack
due to the security consideration. In fact, we can just return and
report the external abort to user-space.

Link: https://lore.kernel.org/all/20220128082920.591115-1-francesco.dolcini@toradex.com
Signed-off-by: Jason Liu <jason.hui.liu@nxp.com>
Reviewed-by: Richard Zhu <hongxing.zhu@nxp.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Acked-by: Lucas Stach <l.stach@pengutronix.de>
---
rfc -> v1:
 * added Acked-by Lucas Stach
 * include correct header for user_mode()
---
 drivers/pci/controller/dwc/pci-imx6.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 6974bd5aa116..c47a05332a94 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -22,6 +22,7 @@
 #include <linux/of_address.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/ptrace.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/resource.h>
@@ -297,8 +298,15 @@ 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;
+
+	/* if the abort from user-space, just return and report it */
+	if (user_mode(regs))
+		return 1;
+
+	instr = *(unsigned long *)pc;
+	reg = (instr >> 12) & 15;
 
 	/*
 	 * If the instruction being executed was a read,
-- 
2.25.1


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

end of thread, other threads:[~2022-02-23 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31  7:52 [PATCH v1] PCI: imx6: Handle the abort from user-space Francesco Dolcini
2022-02-10  8:00 ` Francesco Dolcini
2022-02-23 13:00   ` Lorenzo Pieralisi
2022-02-23 17:46     ` Francesco Dolcini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).