linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Hancock <hancockrwd@gmail.com>
To: Myron Stowe <myron.stowe@redhat.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	yuxiangl@marvell.com, yxlraid@gmail.com, greg@kroah.com,
	alex.williamson@redhat.com, kay@vrfy.org,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] PCI: Handle device quirks when accessing sysfs resource<N> entries
Date: Thu, 21 Mar 2013 18:51:31 -0600	[thread overview]
Message-ID: <514BAB13.3000101@gmail.com> (raw)
In-Reply-To: <20130321043502.7229.43877.stgit@amt.stowe>

On 03/20/2013 10:35 PM, Myron Stowe wrote:
> Sysfs includes entries to memory regions that back a PCI device's BARs.
> The pci-sysfs entries backing I/O Port BARs can be accessed by userspace,
> providing direct access to the device's registers.  File permissions
> prevent random users from accessing the device's registers through these
> files, but don't stop a privileged app that chooses to ignore the purpose
> of these files from doing so.
>
> There are devices with abnormally strict restrictions with respect to
> accessing their registers; aspects that are typically handled by the
> device's driver.  When these access restrictions are not followed - as
> when a userspace app such as "udevadm info --attribute-walk
> --path=/sys/..." parses though reading all the device's sysfs entries - it
> can cause such devices to fail.
>
> This patch introduces a quirking mechanism that can be used to detect
> accesses that do no meet the device's restrictions, letting a device
> specific method intervene and decide how to progress.
>
> Reported-by: Xiangliang Yu <yuxiangl@marvell.com>
> Signed-off-by: Myron Stowe <myron.stowe@redhat.com>

I honestly don't think there's much point in even attempting this 
strategy. This list of devices in the quirk can't possibly be complete. 
It would likely be easier to enumerate a white-list of devices that can 
deal with their IO ports being read willy-nilly than a blacklist of 
those that don't, as there's likely countless devices that fall into 
this category. Even if they don't choke as badly as these ones do, it's 
quite likely that bad behavior will result.

I think there's a few things that need to be done:

-Fix the bug in udevadm that caused it to trawl through these files 
willy-nilly,

-Fix the kernel so that access through these files complies with the 
kernel's mechanisms for claiming IO/memory regions to prevent access 
conflicts (i.e. opening these files should claim the resource region 
they refer to, and should fail with EBUSY or something if another 
process or a kernel driver is using it).

-Reconsider whether supporting read/write on the resource files for IO 
port regions like these makes any sense. Obviously mmap isn't very 
practical for IO port access on x86 but you could even do something like 
an ioctl for this purpose. Not very many pieces of software would need 
to access these files so it's likely OK if the API is a bit ugly. That 
would prevent something like grepping through sysfs from generating port 
accesses to random devices.

  reply	other threads:[~2013-03-22  0:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21  4:34 [PATCH 0/3] PCI: Handle device quirks when accessing sysfs resource<N> entries Myron Stowe
2013-03-21  4:34 ` [PATCH 1/3] PCI: Define macro for Marvell vendor ID Myron Stowe
2013-03-21  4:35 ` [PATCH 2/3] PCI: Handle device quirks when accessing sysfs resource<N> entries Myron Stowe
2013-03-22  0:51   ` Robert Hancock [this message]
2013-03-22  1:24     ` Greg KH
2013-03-22 15:39     ` Myron Stowe
2013-03-22 15:55       ` Robert Hancock
2013-03-22 16:46         ` Myron Stowe
2013-03-22 19:52           ` Elliott, Robert (Server Storage)
2013-04-04 18:06     ` Bjorn Helgaas
2013-04-06  8:49       ` James Bottomley
2013-04-08 17:29         ` Bjorn Helgaas
2013-03-21  4:35 ` [PATCH 3/3] PCI, scsi, ahci: Unify usages of 0x1b4b vendor ID to use PCI_VENDOR_ID_MARVELL_EXT Myron Stowe
2013-04-04 18:23   ` Bjorn Helgaas
2013-04-06  8:44     ` James Bottomley
2013-04-08 17:41       ` Bjorn Helgaas
2013-04-08 18:40     ` Jeff Garzik

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=514BAB13.3000101@gmail.com \
    --to=hancockrwd@gmail.com \
    --cc=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=greg@kroah.com \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=myron.stowe@redhat.com \
    --cc=yuxiangl@marvell.com \
    --cc=yxlraid@gmail.com \
    /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 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).