Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2300035pxb; Sun, 30 Jan 2022 11:13:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuUc+6PZHQwu5cmt2B3rCVLQYKnP4Z8bLTM7fR9u46RJp+a8Vo7eHqTlrJ3iZ9oDyYMxXN X-Received: by 2002:a17:906:7316:: with SMTP id di22mr14924940ejc.505.1643570032092; Sun, 30 Jan 2022 11:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643570032; cv=none; d=google.com; s=arc-20160816; b=VcHOZSPgZTSRL80u/0WuOmlHu5AKJzA8fiVtOt2HCYLiHbltdk6RLjE1uB6ZG2ZeGi lEqfEL1Y/vzocCkjoQKifj4o7/DvRLkEWBiwkYvu5iZ4sQ4M57TB4iyUjCrBoQi4tptK zCybIsmgsQE0vim5Ol9V2bw31X57Eq4qIpqB2YCtXPw4mDhSgYk40kAh3k3W9nEfd1Ic iBeyrOG2YEvJVPFojt483YHcgAGNtalHjWTgAQeEn9GovSBozcdX6U2QqKXPtNDuMvPo /pl9ooswCqkCRrX42POtHokI2u1TfX4vAxwGMskmqfdwcwuBAhlzzi1Yhnz02toYwE8b 5Zhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=yEcs3U41FOMDW0VkpsvuasSme1dUsQou8/jX2UbmnaE=; b=BledIAxD6Va1udG4e895Y0yi0Ewe4tj8KKWyS0C5MVPv2bYPeCCafvaoUGC2LZFao4 90pbKGMYAczYXiB1AEfzNd/IUU1UBXgTEuPXRrcRWKKn0Er2rAplKQIuGRAFPgXX9QRa 9woqJFUCpq/G8IUHxsb0g+tRqg8UKWb2Fi2S2Gpx2hUdnYA/PJz314GQ8OypBuvcqMBK iY68LhJHF7Qs4fheV/uS1Za87jQyyqVtQxeSEtgLNz+Jw9HjvSZLRksm2rw7xbQqbwxi pDmhWyL2XBWawDdVMOgaXQ06C8oxfmKRd7J46J1TpAgqR3ixTbAFTX1+IL6PNzbp+vPU Gvuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qw25si7363192ejc.496.2022.01.30.11.13.27; Sun, 30 Jan 2022 11:13:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243205AbiA1JIQ (ORCPT + 99 others); Fri, 28 Jan 2022 04:08:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232481AbiA1JIP (ORCPT ); Fri, 28 Jan 2022 04:08:15 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09379C061714 for ; Fri, 28 Jan 2022 01:08:15 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDNEg-00082M-Vr; Fri, 28 Jan 2022 10:08:03 +0100 Message-ID: Subject: Re: [RFC PATCH] PCI: imx6: Handle the abort from user-space From: Lucas Stach To: Francesco Dolcini , Richard Zhu , Lorenzo Pieralisi , Rob Herring , Krzysztof =?UTF-8?Q?Wilczy=C5=84ski?= , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Jason Liu Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , Shawn Guo Date: Fri, 28 Jan 2022 10:07:58 +0100 In-Reply-To: <20220128082920.591115-1-francesco.dolcini@toradex.com> References: <20220128082920.591115-1-francesco.dolcini@toradex.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Freitag, dem 28.01.2022 um 09:29 +0100 schrieb Francesco Dolcini: > From: Jason Liu > > 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 > Signed-off-by: Jason Liu > Reviewed-by: Richard Zhu > Signed-off-by: Francesco Dolcini > --- > 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 > #include > #include > +#include > #include > #include > #include > @@ -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,