linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] PCI: imx6: Handle the abort from user-space
@ 2022-01-28  8:29 Francesco Dolcini
  2022-01-28  9:07 ` Lucas Stach
  2022-01-28  9:25 ` Hongxing Zhu
  0 siblings, 2 replies; 4+ messages in thread
From: Francesco Dolcini @ 2022-01-28  8:29 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.

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>
---
We have this patch from NXP downstream kernel [1] in our kernel branch [2]
since a long time, to me it would make sense to upstream it. Any concern?

[1] https://source.codeaurora.org/external/imxsupport/linux-imx/commit/?id=62dfb2fb953463dd1b6710567c9e174672a98f24
[2] https://git.toradex.com/cgit/linux-toradex.git/commit/?id=2b42547cf659f979be2defdff6a99f921b33d0f1
---
 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..6b178a29e253 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -27,6 +27,7 @@
 #include <linux/resource.h>
 #include <linux/signal.h>
 #include <linux/types.h>
+#include <linux/uaccess.h>
 #include <linux/interrupt.h>
 #include <linux/reset.h>
 #include <linux/phy/phy.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

* Re: [RFC PATCH] PCI: imx6: Handle the abort from user-space
  2022-01-28  8:29 [RFC PATCH] PCI: imx6: Handle the abort from user-space Francesco Dolcini
@ 2022-01-28  9:07 ` Lucas Stach
  2022-01-28  9:25 ` Hongxing Zhu
  1 sibling, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2022-01-28  9:07 UTC (permalink / raw)
  To: Francesco Dolcini, Richard Zhu, 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

Am Freitag, dem 28.01.2022 um 09:29 +0100 schrieb 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.
> 
I'm not sure how userspace would be able to trigger this abort. Maybe
invalid access to a device cfg space via sysfs?

However the patch seems to do the right thing in that case.

Acked-by: Lucas Stach <l.stach@pengutronix.de>
 
> 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>
> ---
> We have this patch from NXP downstream kernel [1] in our kernel branch [2]
> since a long time, to me it would make sense to upstream it. Any concern?
> 
> [1] https://source.codeaurora.org/external/imxsupport/linux-imx/commit/?id=62dfb2fb953463dd1b6710567c9e174672a98f24
> [2] https://git.toradex.com/cgit/linux-toradex.git/commit/?id=2b42547cf659f979be2defdff6a99f921b33d0f1
> ---
>  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..6b178a29e253 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -27,6 +27,7 @@
>  #include <linux/resource.h>
>  #include <linux/signal.h>
>  #include <linux/types.h>
> +#include <linux/uaccess.h>
>  #include <linux/interrupt.h>
>  #include <linux/reset.h>
>  #include <linux/phy/phy.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,



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

* RE: [RFC PATCH] PCI: imx6: Handle the abort from user-space
  2022-01-28  8:29 [RFC PATCH] PCI: imx6: Handle the abort from user-space Francesco Dolcini
  2022-01-28  9:07 ` Lucas Stach
@ 2022-01-28  9:25 ` Hongxing Zhu
  2022-01-28 10:18   ` (EXT) " Alexander Stein
  1 sibling, 1 reply; 4+ messages in thread
From: Hongxing Zhu @ 2022-01-28  9:25 UTC (permalink / raw)
  To: Francesco Dolcini, Lucas Stach, Lorenzo Pieralisi, Rob Herring,
	Krzysztof Wilczy��ski, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx, Jason Liu
  Cc: linux-pci, linux-arm-kernel, linux-kernel, Bjorn Helgaas, Shawn Guo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb2312", Size: 4046 bytes --]

> -----Original Message-----
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> Sent: 2022Äê1ÔÂ28ÈÕ 16:29
> To: Hongxing Zhu <hongxing.zhu@nxp.com>; Lucas Stach
> <l.stach@pengutronix.de>; Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>; Rob
> Herring <robh@kernel.org>; Krzysztof Wilczy¨½ski <kw@linux.com>; Sascha
> Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>;
> dl-linux-imx <linux-imx@nxp.com>; Jason Liu <jason.hui.liu@nxp.com>
> Cc: linux-pci@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org; Bjorn Helgaas <bhelgaas@google.com>; Shawn
> Guo <shawnguo@kernel.org>; Francesco Dolcini
> <francesco.dolcini@toradex.com>
> Subject: [RFC PATCH] PCI: imx6: Handle the abort from user-space
> 
> 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.
> 
> 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>
> ---
> We have this patch from NXP downstream kernel [1] in our kernel branch [2]
> since a long time, to me it would make sense to upstream it. Any concern?
> 
> [1]
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsource.
> codeaurora.org%2Fexternal%2Fimxsupport%2Flinux-imx%2Fcommit%2F%3Fid
> %3D62dfb2fb953463dd1b6710567c9e174672a98f24&amp;data=04%7C01%7
> Chongxing.zhu%40nxp.com%7Ccbe193ab4c3e4ad11bcb08d9e2384a1f%7C68
> 6ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637789553659549198%7
> CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBT
> iI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Mwhx8DFF7EDJdpqTsHT
> %2BBAGzhQadDOqcgJnVjeoi1yk%3D&amp;reserved=0
> [2]
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.tora
> dex.com%2Fcgit%2Flinux-toradex.git%2Fcommit%2F%3Fid%3D2b42547cf659f
> 979be2defdff6a99f921b33d0f1&amp;data=04%7C01%7Chongxing.zhu%40nx
> p.com%7Ccbe193ab4c3e4ad11bcb08d9e2384a1f%7C686ea1d3bc2b4c6fa92c
> d99c5c301635%7C0%7C0%7C637789553659549198%7CUnknown%7CTWFp
> bGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI
> 6Mn0%3D%7C3000&amp;sdata=QEW1frh8WacCzniWo4ng1cy3Z1UZ9uMRFw
> GBKuIh7zE%3D&amp;reserved=0
> ---
>  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..6b178a29e253 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -27,6 +27,7 @@
>  #include <linux/resource.h>
>  #include <linux/signal.h>
>  #include <linux/types.h>
> +#include <linux/uaccess.h>

[Richard Zhu] Thanks for your kindly help.
This header include is not required actually, please remove it.
Best Regards
Richard

>  #include <linux/interrupt.h>
>  #include <linux/reset.h>
>  #include <linux/phy/phy.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	[flat|nested] 4+ messages in thread

* Re: (EXT) RE: [RFC PATCH] PCI: imx6: Handle the abort from user-space
  2022-01-28  9:25 ` Hongxing Zhu
@ 2022-01-28 10:18   ` Alexander Stein
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Stein @ 2022-01-28 10:18 UTC (permalink / raw)
  To: Francesco Dolcini, Hongxing Zhu
  Cc: Lucas Stach, Lorenzo Pieralisi, Rob Herring,
	Krzysztof Wilczyński, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, dl-linux-imx, Jason Liu, linux-arm-kernel,
	linux-pci, linux-arm-kernel, linux-kernel, Bjorn Helgaas,
	Shawn Guo

Am Freitag, 28. Januar 2022, 10:25:11 CET schrieb Hongxing Zhu:
> > -----Original Message-----
> > From: Francesco Dolcini <francesco.dolcini@toradex.com>
> > Sent: 2022年1月28日 16:29
> > To: Hongxing Zhu <hongxing.zhu@nxp.com>; Lucas Stach
> > <l.stach@pengutronix.de>; Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>;
> > Rob
 Herring <robh@kernel.org>; Krzysztof Wilczyński <kw@linux.com>;
> > Sascha Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> > <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>;
> > dl-linux-imx <linux-imx@nxp.com>; Jason Liu <jason.hui.liu@nxp.com>
> > Cc: linux-pci@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org; Bjorn Helgaas <bhelgaas@google.com>; Shawn
> > Guo <shawnguo@kernel.org>; Francesco Dolcini
> > <francesco.dolcini@toradex.com>
> > Subject: [RFC PATCH] PCI: imx6: Handle the abort from user-space
> > 
> > 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.
> > 
> > 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>
> > ---
> > We have this patch from NXP downstream kernel [1] in our kernel branch
> > [2]
> > since a long time, to me it would make sense to upstream it. Any concern?
> > 
> > [1]
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsource.
> > codeaurora.org%2Fexternal%2Fimxsupport%2Flinux-imx%2Fcommit%2F%3Fid
> > %3D62dfb2fb953463dd1b6710567c9e174672a98f24&amp;data=04%7C01%7
> > Chongxing.zhu%40nxp.com%7Ccbe193ab4c3e4ad11bcb08d9e2384a1f%7C68
> > 6ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637789553659549198%7
> > CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBT
> > iI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Mwhx8DFF7EDJdpqTsHT
> > %2BBAGzhQadDOqcgJnVjeoi1yk%3D&amp;reserved=0
> > [2]
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.tora
> > 
> > dex.com%2Fcgit%2Flinux-toradex.git%2Fcommit%2F%3Fid%3D2b42547cf659f
> > 979be2defdff6a99f921b33d0f1&amp;data=04%7C01%7Chongxing.zhu%40nx
> > p.com%7Ccbe193ab4c3e4ad11bcb08d9e2384a1f%7C686ea1d3bc2b4c6fa92c
> > d99c5c301635%7C0%7C0%7C637789553659549198%7CUnknown%7CTWFp
> > bGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI
> > 6Mn0%3D%7C3000&amp;sdata=QEW1frh8WacCzniWo4ng1cy3Z1UZ9uMRFw
> > GBKuIh7zE%3D&amp;reserved=0
> > ---
> > 
> >  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..6b178a29e253 100644
> > --- a/drivers/pci/controller/dwc/pci-imx6.c
> > +++ b/drivers/pci/controller/dwc/pci-imx6.c
> > @@ -27,6 +27,7 @@
> > 
> >  #include <linux/resource.h>
> >  #include <linux/signal.h>
> >  #include <linux/types.h>
> > 
> > +#include <linux/uaccess.h>
> 
> 
> [Richard Zhu] Thanks for your kindly help.
> This header include is not required actually, please remove it.

It should be <linux/ptrace.h> instead, for using user_mode().
Best regards,
Alexander


> >  #include <linux/interrupt.h>
> >  #include <linux/reset.h>
> >  #include <linux/phy/phy.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	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-28 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28  8:29 [RFC PATCH] PCI: imx6: Handle the abort from user-space Francesco Dolcini
2022-01-28  9:07 ` Lucas Stach
2022-01-28  9:25 ` Hongxing Zhu
2022-01-28 10:18   ` (EXT) " Alexander Stein

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).