mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	David Woodhouse <dwmw2@infradead.org>,
	Joerg Roedel <jroedel@suse.de>
Subject: Re: [PATCH 1/2] iommu: Make iommu_group_get_for_dev() more robust
Date: Thu, 21 Aug 2014 15:54:17 -0600	[thread overview]
Message-ID: <1408658057.2906.20.camel@ul30vt.home> (raw)
In-Reply-To: <1408657045-4979-2-git-send-email-joro@8bytes.org>

On Thu, 2014-08-21 at 23:37 +0200, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> When a non-PCI device is passed to that function it might
> pass group == NULL to iommu_group_add_device() which then
> dereferences it and cause a crash this way. Fix it by
> just returning an error for non-PCI devices.
> 
> Fixes: 104a1c13ac66e40cf8c6ae74d76ff14ff24b9b01
> Cc: Alex Williamson <alex.williamson@redhat.com>
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
>  drivers/iommu/iommu.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 1698360..ef8da12 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -678,15 +678,17 @@ static struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev)
>   */
>  struct iommu_group *iommu_group_get_for_dev(struct device *dev)
>  {
> -	struct iommu_group *group = ERR_PTR(-EIO);
> +	struct iommu_group *group;
>  	int ret;
>  
>  	group = iommu_group_get(dev);
>  	if (group)
>  		return group;

Hmm, I bet I had a second pointer for this case but mistakenly optimized
it out refining the patch.  This solution works too though.

Acked-by: Alex Williamson <alex.williamson@redhat.com>

Thanks!
Alex

>  
> -	if (dev_is_pci(dev))
> -		group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
> +	if (!dev_is_pci(dev))
> +		return ERR_PTR(-EINVAL);
> +
> +	group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
>  
>  	if (IS_ERR(group))
>  		return group;




  reply	other threads:[~2014-08-21 21:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-21 21:37 [PATCH 0/2] More IOMMU Fixes Joerg Roedel
2014-08-21 21:37 ` [PATCH 1/2] iommu: Make iommu_group_get_for_dev() more robust Joerg Roedel
2014-08-21 21:54   ` Alex Williamson [this message]
2014-08-21 21:37 ` [PATCH 2/2] iommu/vt-d: Check return value of acpi_bus_get_device() Joerg Roedel
2014-08-21 21:57   ` Alex Williamson

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=1408658057.2906.20.camel@ul30vt.home \
    --to=alex.williamson@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®