All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Don Dutile <ddutile@redhat.com>
Cc: Myron Stowe <mstowe@redhat.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	Myron Stowe <myron.stowe@redhat.com>,
	kay@vrfy.org, linux-hotplug@vger.kernel.org,
	linux-pci@vger.kernel.org, yuxiangl@marvell.com,
	yxlraid@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] udevadm-info: Don't access sysfs 'resource<N>' files
Date: Mon, 18 Mar 2013 10:34:32 -0600	[thread overview]
Message-ID: <1363624472.24132.358.camel@bling.home> (raw)
In-Reply-To: <514729C2.3080308@redhat.com>

On Mon, 2013-03-18 at 10:50 -0400, Don Dutile wrote:
> On 03/17/2013 06:28 PM, Alex Williamson wrote:
> > On Sun, 2013-03-17 at 08:33 -0600, Myron Stowe wrote:
> >> On Sun, 2013-03-17 at 07:38 -0600, Alex Williamson wrote:
> >>> On Sat, 2013-03-16 at 22:36 -0700, Greg KH wrote:
> >>>> On Sat, Mar 16, 2013 at 10:11:22PM -0600, Alex Williamson wrote:
> >>>>> On Sat, 2013-03-16 at 18:03 -0700, Greg KH wrote:
> >>>>>> On Sat, Mar 16, 2013 at 05:50:53PM -0600, Myron Stowe wrote:
> >>>>>>> On Sat, 2013-03-16 at 15:11 -0700, Greg KH wrote:
> >>>>>>>> On Sat, Mar 16, 2013 at 03:35:19PM -0600, Myron Stowe wrote:
> >>>>>>>>> Sysfs includes entries to memory that backs a PCI device's BARs, both I/O
> >>>>>>>>> Port space and MMIO.  This memory regions correspond to the device's
> >>>>>>>>> internal status and control registers used to drive the device.
> >>>>>>>>>
> >>>>>>>>> Accessing these registers from userspace such as "udevadm info
> >>>>>>>>> --attribute-walk --path=/sys/devices/..." does can not be allowed as
> >>>>>>>>> such accesses outside of the driver, even just reading, can yield
> >>>>>>>>> catastrophic consequences.
> >>>>>>>>>
> >>>>>>>>> Udevadm-info skips parsing a specific set of sysfs entries including
> >>>>>>>>> 'resource'.  This patch extends the set to include the additional
> >>>>>>>>> 'resource<N>' entries that correspond to a PCI device's BARs.
> >>>>>>>>
> >>>>>>>> Nice, are you also going to patch bash to prevent a user from reading
> >>>>>>>> these sysfs files as well?  :)
> >>>>>>>>
> >>>>>>>> And pciutils?
> >>>>>>>>
> >>>>>>>> You get my point here, right?  The root user just asked to read all of
> >>>>>>>> the data for this device, so why wouldn't you allow it?  Just like
> >>>>>>>> 'lspci' does.  Or bash does.
> >>>>>>>
> >>>>>>> Yes :P , you raise a very good point, there are a lot of way a user can
> >>>>>>> poke around in those BARs.  However, there is a difference between
> >>>>>>> shooting yourself in the foot and getting what you deserve versus
> >>>>>>> unknowingly executing a common command such as udevadm and having the
> >>>>>>> system hang.
> >>>>>>>>
> >>>>>>>> If this hardware has a problem, then it needs to be fixed in the kernel,
> >>>>>>>> not have random band-aids added to various userspace programs to paper
> >>>>>>>> over the root problem here.  Please fix the kernel driver and all should
> >>>>>>>> be fine.  No need to change udevadm.
> >>>>>>>
> >>>>>>> Xiangliang initially proposed a patch within the PCI core.  Ignoring the
> >>>>>>> specific issue with the proposal which I pointed out in the
> >>>>>>> https://lkml.org/lkml/2013/3/7/242 thread, that just doesn't seem like
> >>>>>>> the right place to effect a change either as PCI's core isn't concerned
> >>>>>>> with the contents or access limitations of those regions, those are
> >>>>>>> issues that the driver concerns itself with.
> >>>>>>>
> >>>>>>> So things seem to be gravitating towards the driver.  I'm fairly
> >>>>>>> ignorant of this area but as Robert succinctly pointed out in the
> >>>>>>> originating thread - the AHCI driver only uses the device's MMIO region.
> >>>>>>> The I/O related regions are for legacy SFF-compatible ATA ports and are
> >>>>>>> not used to driver the device.  This, coupled with the observance that
> >>>>>>> userspace accesses such as udevadm, and others like you additionally
> >>>>>>> point out, do not filter through the device's driver for seems to
> >>>>>>> suggest that changes to the driver will not help here either.
> >>>>>>
> >>>>>> A PCI quirk should handle this properly, right?  Why not do that?  Worse
> >>>>>> thing, the quirk could just not expose these sysfs files for this
> >>>>>> device, which would solve all userspace program issues, right?
> >>>>>
> >>>>> Not exactly.  I/O port access through pci-sysfs was added for userspace
> >>>>> programs, specifically qemu-kvm device assignment.  We use the I/O port
> >>>>> resource# files to access device owned I/O port registers using file
> >>>>> permissions rather than global permissions such as iopl/ioperm.  File
> >>>>> permissions also prevent random users from accessing device registers
> >>>>> through these files, but of course can't stop a privileged app that
> >>>>> chooses to ignore the purpose of these files.  A quirk would therefore
> >>>>> remove a file that actually has a useful purpose for one app just so
> >>>>> another app that has no particular reason for dumping the contents can
> >>>>> run unabated.  Thanks,
> >>>>
> >>>> The quirk would only be for this one specific device, which obviously
> >>>> can't handle this type of access, so why would you want the sysfs files
> >>>> even present for it at all?
> >>>
> >>> I'm assuming that the device only breaks because udevadm is dumping the
> >>> full I/O port register space of the device and that if an actual driver
> >>> was interacting with it through this interface that it would work.
> >>
> >> Correct:
> >>          the AHCI driver only uses the device's MMIO region.  The I/O
> >>          related regions are for legacy SFF-compatible ATA ports and are
> >>          not used to driver the device.  This, coupled with the
> >>          observance that userspace accesses such as udevadm, and others
> >>          like Greg additionally pointed out, do not filter through the
> >>          device's driver seems to suggest that changes to the driver will
> >>          not help here either.
> >
> > That may be true of our AHCI driver, but when it's assigned to a guest
> > we're potentially using a completely different stack and cannot make
> > that assumption.  A guest running in compatibility mode or the option
> > ROM for the device may still use I/O port regions.  Thanks,
> >
> > Alex
> >
> >
> 
> In quick summary:
> (1)reading a device's registers may have side effects
>      on the device operation, e.g., a register maps to a device's FIFO register.
> (2) Having two threads read such device registers can cause unknown results,
>       i.e., driver & user-app.
> (3) It may be valid for a user-app to read device regs, e.g.,
>      qemu-kvm assigned device
> 
> So, can't it be solved by:
> (a) if no driver is configured for the device, than it's valid for a user-app
>      to read the device regs ?
>       -- although diff. user apps doing so still exposes the problem, and
>          can't be distinguished, e.g.,  	qemu-kvm + udevadm
> 		-- or can file permissions (set by libvirt driving qemu-kvm
> 		   device assignment) block multiple user-app reading ?
> 		   i.e., basically, a user-level version of a driver allocating
> 			 the device, which in the case of qemu-kvm device-assignment,
> 			 is what is actually happening! :)
> (b) if driver is configured, need a quirk-registration, or generic, optional,
> 	driver function to check for user-app reading approval.
> 
> ok, bash away...


I think concurrency is a secondary issue.  The primary issue is whether
read() is somehow so special in sysfs that all files need to be regarded
as o+r.  If that's true, then indeed there are concurrency issues.
Thanks,

Alex


WARNING: multiple messages have this Message-ID (diff)
From: Alex Williamson <alex.williamson@redhat.com>
To: Don Dutile <ddutile@redhat.com>
Cc: Myron Stowe <mstowe@redhat.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	Myron Stowe <myron.stowe@redhat.com>,
	kay@vrfy.org, linux-hotplug@vger.kernel.org,
	linux-pci@vger.kernel.org, yuxiangl@marvell.com,
	yxlraid@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] udevadm-info: Don't access sysfs 'resource<N>' files
Date: Mon, 18 Mar 2013 16:34:32 +0000	[thread overview]
Message-ID: <1363624472.24132.358.camel@bling.home> (raw)
In-Reply-To: <514729C2.3080308@redhat.com>

On Mon, 2013-03-18 at 10:50 -0400, Don Dutile wrote:
> On 03/17/2013 06:28 PM, Alex Williamson wrote:
> > On Sun, 2013-03-17 at 08:33 -0600, Myron Stowe wrote:
> >> On Sun, 2013-03-17 at 07:38 -0600, Alex Williamson wrote:
> >>> On Sat, 2013-03-16 at 22:36 -0700, Greg KH wrote:
> >>>> On Sat, Mar 16, 2013 at 10:11:22PM -0600, Alex Williamson wrote:
> >>>>> On Sat, 2013-03-16 at 18:03 -0700, Greg KH wrote:
> >>>>>> On Sat, Mar 16, 2013 at 05:50:53PM -0600, Myron Stowe wrote:
> >>>>>>> On Sat, 2013-03-16 at 15:11 -0700, Greg KH wrote:
> >>>>>>>> On Sat, Mar 16, 2013 at 03:35:19PM -0600, Myron Stowe wrote:
> >>>>>>>>> Sysfs includes entries to memory that backs a PCI device's BARs, both I/O
> >>>>>>>>> Port space and MMIO.  This memory regions correspond to the device's
> >>>>>>>>> internal status and control registers used to drive the device.
> >>>>>>>>>
> >>>>>>>>> Accessing these registers from userspace such as "udevadm info
> >>>>>>>>> --attribute-walk --path=/sys/devices/..." does can not be allowed as
> >>>>>>>>> such accesses outside of the driver, even just reading, can yield
> >>>>>>>>> catastrophic consequences.
> >>>>>>>>>
> >>>>>>>>> Udevadm-info skips parsing a specific set of sysfs entries including
> >>>>>>>>> 'resource'.  This patch extends the set to include the additional
> >>>>>>>>> 'resource<N>' entries that correspond to a PCI device's BARs.
> >>>>>>>>
> >>>>>>>> Nice, are you also going to patch bash to prevent a user from reading
> >>>>>>>> these sysfs files as well?  :)
> >>>>>>>>
> >>>>>>>> And pciutils?
> >>>>>>>>
> >>>>>>>> You get my point here, right?  The root user just asked to read all of
> >>>>>>>> the data for this device, so why wouldn't you allow it?  Just like
> >>>>>>>> 'lspci' does.  Or bash does.
> >>>>>>>
> >>>>>>> Yes :P , you raise a very good point, there are a lot of way a user can
> >>>>>>> poke around in those BARs.  However, there is a difference between
> >>>>>>> shooting yourself in the foot and getting what you deserve versus
> >>>>>>> unknowingly executing a common command such as udevadm and having the
> >>>>>>> system hang.
> >>>>>>>>
> >>>>>>>> If this hardware has a problem, then it needs to be fixed in the kernel,
> >>>>>>>> not have random band-aids added to various userspace programs to paper
> >>>>>>>> over the root problem here.  Please fix the kernel driver and all should
> >>>>>>>> be fine.  No need to change udevadm.
> >>>>>>>
> >>>>>>> Xiangliang initially proposed a patch within the PCI core.  Ignoring the
> >>>>>>> specific issue with the proposal which I pointed out in the
> >>>>>>> https://lkml.org/lkml/2013/3/7/242 thread, that just doesn't seem like
> >>>>>>> the right place to effect a change either as PCI's core isn't concerned
> >>>>>>> with the contents or access limitations of those regions, those are
> >>>>>>> issues that the driver concerns itself with.
> >>>>>>>
> >>>>>>> So things seem to be gravitating towards the driver.  I'm fairly
> >>>>>>> ignorant of this area but as Robert succinctly pointed out in the
> >>>>>>> originating thread - the AHCI driver only uses the device's MMIO region.
> >>>>>>> The I/O related regions are for legacy SFF-compatible ATA ports and are
> >>>>>>> not used to driver the device.  This, coupled with the observance that
> >>>>>>> userspace accesses such as udevadm, and others like you additionally
> >>>>>>> point out, do not filter through the device's driver for seems to
> >>>>>>> suggest that changes to the driver will not help here either.
> >>>>>>
> >>>>>> A PCI quirk should handle this properly, right?  Why not do that?  Worse
> >>>>>> thing, the quirk could just not expose these sysfs files for this
> >>>>>> device, which would solve all userspace program issues, right?
> >>>>>
> >>>>> Not exactly.  I/O port access through pci-sysfs was added for userspace
> >>>>> programs, specifically qemu-kvm device assignment.  We use the I/O port
> >>>>> resource# files to access device owned I/O port registers using file
> >>>>> permissions rather than global permissions such as iopl/ioperm.  File
> >>>>> permissions also prevent random users from accessing device registers
> >>>>> through these files, but of course can't stop a privileged app that
> >>>>> chooses to ignore the purpose of these files.  A quirk would therefore
> >>>>> remove a file that actually has a useful purpose for one app just so
> >>>>> another app that has no particular reason for dumping the contents can
> >>>>> run unabated.  Thanks,
> >>>>
> >>>> The quirk would only be for this one specific device, which obviously
> >>>> can't handle this type of access, so why would you want the sysfs files
> >>>> even present for it at all?
> >>>
> >>> I'm assuming that the device only breaks because udevadm is dumping the
> >>> full I/O port register space of the device and that if an actual driver
> >>> was interacting with it through this interface that it would work.
> >>
> >> Correct:
> >>          the AHCI driver only uses the device's MMIO region.  The I/O
> >>          related regions are for legacy SFF-compatible ATA ports and are
> >>          not used to driver the device.  This, coupled with the
> >>          observance that userspace accesses such as udevadm, and others
> >>          like Greg additionally pointed out, do not filter through the
> >>          device's driver seems to suggest that changes to the driver will
> >>          not help here either.
> >
> > That may be true of our AHCI driver, but when it's assigned to a guest
> > we're potentially using a completely different stack and cannot make
> > that assumption.  A guest running in compatibility mode or the option
> > ROM for the device may still use I/O port regions.  Thanks,
> >
> > Alex
> >
> >
> 
> In quick summary:
> (1)reading a device's registers may have side effects
>      on the device operation, e.g., a register maps to a device's FIFO register.
> (2) Having two threads read such device registers can cause unknown results,
>       i.e., driver & user-app.
> (3) It may be valid for a user-app to read device regs, e.g.,
>      qemu-kvm assigned device
> 
> So, can't it be solved by:
> (a) if no driver is configured for the device, than it's valid for a user-app
>      to read the device regs ?
>       -- although diff. user apps doing so still exposes the problem, and
>          can't be distinguished, e.g.,  	qemu-kvm + udevadm
> 		-- or can file permissions (set by libvirt driving qemu-kvm
> 		   device assignment) block multiple user-app reading ?
> 		   i.e., basically, a user-level version of a driver allocating
> 			 the device, which in the case of qemu-kvm device-assignment,
> 			 is what is actually happening! :)
> (b) if driver is configured, need a quirk-registration, or generic, optional,
> 	driver function to check for user-app reading approval.
> 
> ok, bash away...


I think concurrency is a secondary issue.  The primary issue is whether
read() is somehow so special in sysfs that all files need to be regarded
as o+r.  If that's true, then indeed there are concurrency issues.
Thanks,

Alex


  reply	other threads:[~2013-03-18 16:34 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-16 21:35 [PATCH] udevadm-info: Don't access sysfs entries backing device I/O port space Myron Stowe
2013-03-16 21:35 ` Myron Stowe
2013-03-16 21:35 ` [PATCH] udevadm-info: Don't access sysfs 'resource<N>' files Myron Stowe
2013-03-16 21:35   ` Myron Stowe
2013-03-16 22:11   ` Greg KH
2013-03-16 22:11     ` Greg KH
2013-03-16 22:55     ` Bjorn Helgaas
2013-03-16 22:55       ` Bjorn Helgaas
2013-03-16 23:50     ` Myron Stowe
2013-03-16 23:50       ` Myron Stowe
2013-03-17  1:03       ` Greg KH
2013-03-17  1:03         ` Greg KH
2013-03-17  4:11         ` Alex Williamson
2013-03-17  4:11           ` Alex Williamson
2013-03-17  5:36           ` Greg KH
2013-03-17  5:36             ` Greg KH
2013-03-17 13:38             ` Alex Williamson
2013-03-17 13:38               ` Alex Williamson
2013-03-17 14:00               ` Kay Sievers
2013-03-17 14:00                 ` Kay Sievers
2013-03-17 14:20                 ` Myron Stowe
2013-03-17 14:20                   ` Myron Stowe
2013-03-17 14:29                   ` Kay Sievers
2013-03-17 14:29                     ` Kay Sievers
2013-03-17 14:36                     ` Myron Stowe
2013-03-17 14:36                       ` Myron Stowe
2013-03-17 14:43                       ` Kay Sievers
2013-03-17 14:43                         ` Kay Sievers
2013-03-18 16:24                 ` Alex Williamson
2013-03-18 16:24                   ` Alex Williamson
2013-03-18 16:41                   ` Greg KH
2013-03-18 16:41                     ` Greg KH
2013-03-18 16:51                     ` Alex Williamson
2013-03-18 16:51                       ` Alex Williamson
2013-03-18 17:20                       ` Bjørn Mork
2013-03-18 17:20                         ` Bjørn Mork
2013-03-18 17:54                         ` Alex Williamson
2013-03-18 17:54                           ` Alex Williamson
2013-03-18 18:02                           ` Robert Brown
2013-03-18 18:02                             ` Robert Brown
2013-03-18 18:25                           ` Bjørn Mork
2013-03-18 18:25                             ` Bjørn Mork
2013-03-18 18:59                             ` Alex Williamson
2013-03-18 18:59                               ` Alex Williamson
2013-03-19 16:57                               ` Myron Stowe
2013-03-19 16:57                                 ` Myron Stowe
2013-03-19 17:06                                 ` Myron Stowe
2013-03-19 17:06                                   ` Myron Stowe
2013-03-17 14:33               ` Myron Stowe
2013-03-17 14:33                 ` Myron Stowe
2013-03-17 22:28                 ` Alex Williamson
2013-03-17 22:28                   ` Alex Williamson
2013-03-18 14:50                   ` Don Dutile
2013-03-18 14:50                     ` Don Dutile
2013-03-18 16:34                     ` Alex Williamson [this message]
2013-03-18 16:34                       ` Alex Williamson
2013-03-17 14:12         ` Myron Stowe
2013-03-17 14:12           ` Myron Stowe
2013-03-19  1:54         ` Robert Hancock
2013-03-19  1:54           ` Robert Hancock
2013-03-19  2:03           ` Greg KH
2013-03-19  2:03             ` Greg KH
2013-03-19  2:09             ` Robert Hancock
2013-03-19  2:09               ` Robert Hancock
2013-03-19  2:35               ` Greg KH
2013-03-19  2:35                 ` Greg KH
2013-03-19  3:08                 ` Robert Hancock
2013-03-19  3:08                   ` Robert Hancock

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=1363624472.24132.358.camel@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=ddutile@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kay@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mstowe@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.