From: nwatters-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org
To: Auger Eric <eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] iommu/iova: validate iova_domain input to put_iova_domain
Date: Thu, 14 Jul 2016 13:55:32 -0400 [thread overview]
Message-ID: <333f4b4f52168db68250a447ef5db3f3@codeaurora.org> (raw)
In-Reply-To: <77bca715-36e1-eb11-a49b-5d389b6cc0e8-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
On 2016-07-14 07:21, Auger Eric wrote:
> Hi Robin, Nate,
> On 14/07/2016 12:36, Robin Murphy wrote:
>> On 14/07/16 09:34, Joerg Roedel wrote:
>>> On Wed, Jul 13, 2016 at 02:49:32PM -0400, Nate Watterson wrote:
>>>> Passing a NULL or uninitialized iova_domain into put_iova_domain
>>>> will currently crash the kernel when the unconfigured iova_domain
>>>> data members are accessed. To prevent this from occurring, this
>>>> patch
>>>> adds a check to make sure that the domain is non-NULL and that the
>>>> domain granule is non-zero. The granule can be used to check if the
>>>> domain was properly initialized because calling init_iova_domain
>>>> with a granule of zero would have already triggered a BUG statement
>>>> crashing the kernel.
>>>
>>> Have you seen real crashes happening because of this?
In my case, it was calling iommu_request_dm_for_dev() which triggered
the
"iommu_[get/put]_dma_cookie() without iommu_dma_init_domain()" issue
that
has Robin documented below.
>
> I also saw the crash happening with my PCIe passthrough series (not
> upstreamed)
> [PATCH v10 0/8] [PATCH v10 0/8] KVM PCIe/MSI passthrough on ARM/ARM64:
> kernel part 1/3: iommu changes https://lkml.org/lkml/2016/6/7/676
>
> patch [PATCH v10 8/8] iommu/arm-smmu: get/put the msi cookie
> also uses iommu_put_dma_cookie
>
>
> and the uninitialised lock crash happens if the group gets destroyed
> before the iommu_dma_init_domain is called, which can also happen for
> me.
>
>>
>> It _can_ happen via the iommu-dma code if something goes wrong
>> initialising a group - the IOVA domain gets allocated at the same time
>> as the default IOMMU domain, but isn't initialised until later once
>> the
>> device in question gets ity dma ops set up. If adding the device to
>> the
>> group fails, everything gets torn down again and
>> iommu_put_dma_cookie()
>> ends up trying to take an uninitialised lock .
> Cant' we allow the granule check also with UNMANAGED type?
>
> Thanks
>
> Eric
>
>>
>> However, I think the appropriate fix for that particular situation
>> would
>> be more like this:
>>
>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>> index ea5a9ebf0f78..d00d22930a6b 100644
>> --- a/drivers/iommu/dma-iommu.c
>> +++ b/drivers/iommu/dma-iommu.c
>> @@ -65,10 +65,11 @@ void iommu_put_dma_cookie(struct iommu_domain
>> *domain)
>> {
>> struct iova_domain *iovad = domain->iova_cookie;
>>
>> - if (!iovad)
>> + if (domain->type != IOMMU_DOMAIN_DMA || !iovad)
>> return;
>>
>> - put_iova_domain(iovad);
>> + if (iovad->granule)
>> + put_iova_domain(iovad);
>> kfree(iovad);
>> domain->iova_cookie = NULL;
>> }
>>
>> (It probably should have been that way from the start; mea culpa)
I originally put together a similar patch, but then thought that people
would
complain it didn't fix the root of the problem. Yet another instance
where
thinking was best avoided I guess.
>>
>> Robin.
>> _______________________________________________
>> iommu mailing list
>> iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
>> https://lists.linuxfoundation.org/mailman/listinfo/iommu
>>
--
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm
Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a
Linux Foundation Collaborative Project.
WARNING: multiple messages have this Message-ID (diff)
From: nwatters@codeaurora.org
To: Auger Eric <eric.auger@redhat.com>
Cc: Robin Murphy <robin.murphy@arm.com>,
Joerg Roedel <joro@8bytes.org>,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu/iova: validate iova_domain input to put_iova_domain
Date: Thu, 14 Jul 2016 13:55:32 -0400 [thread overview]
Message-ID: <333f4b4f52168db68250a447ef5db3f3@codeaurora.org> (raw)
In-Reply-To: <77bca715-36e1-eb11-a49b-5d389b6cc0e8@redhat.com>
On 2016-07-14 07:21, Auger Eric wrote:
> Hi Robin, Nate,
> On 14/07/2016 12:36, Robin Murphy wrote:
>> On 14/07/16 09:34, Joerg Roedel wrote:
>>> On Wed, Jul 13, 2016 at 02:49:32PM -0400, Nate Watterson wrote:
>>>> Passing a NULL or uninitialized iova_domain into put_iova_domain
>>>> will currently crash the kernel when the unconfigured iova_domain
>>>> data members are accessed. To prevent this from occurring, this
>>>> patch
>>>> adds a check to make sure that the domain is non-NULL and that the
>>>> domain granule is non-zero. The granule can be used to check if the
>>>> domain was properly initialized because calling init_iova_domain
>>>> with a granule of zero would have already triggered a BUG statement
>>>> crashing the kernel.
>>>
>>> Have you seen real crashes happening because of this?
In my case, it was calling iommu_request_dm_for_dev() which triggered
the
"iommu_[get/put]_dma_cookie() without iommu_dma_init_domain()" issue
that
has Robin documented below.
>
> I also saw the crash happening with my PCIe passthrough series (not
> upstreamed)
> [PATCH v10 0/8] [PATCH v10 0/8] KVM PCIe/MSI passthrough on ARM/ARM64:
> kernel part 1/3: iommu changes https://lkml.org/lkml/2016/6/7/676
>
> patch [PATCH v10 8/8] iommu/arm-smmu: get/put the msi cookie
> also uses iommu_put_dma_cookie
>
>
> and the uninitialised lock crash happens if the group gets destroyed
> before the iommu_dma_init_domain is called, which can also happen for
> me.
>
>>
>> It _can_ happen via the iommu-dma code if something goes wrong
>> initialising a group - the IOVA domain gets allocated at the same time
>> as the default IOMMU domain, but isn't initialised until later once
>> the
>> device in question gets ity dma ops set up. If adding the device to
>> the
>> group fails, everything gets torn down again and
>> iommu_put_dma_cookie()
>> ends up trying to take an uninitialised lock .
> Cant' we allow the granule check also with UNMANAGED type?
>
> Thanks
>
> Eric
>
>>
>> However, I think the appropriate fix for that particular situation
>> would
>> be more like this:
>>
>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>> index ea5a9ebf0f78..d00d22930a6b 100644
>> --- a/drivers/iommu/dma-iommu.c
>> +++ b/drivers/iommu/dma-iommu.c
>> @@ -65,10 +65,11 @@ void iommu_put_dma_cookie(struct iommu_domain
>> *domain)
>> {
>> struct iova_domain *iovad = domain->iova_cookie;
>>
>> - if (!iovad)
>> + if (domain->type != IOMMU_DOMAIN_DMA || !iovad)
>> return;
>>
>> - put_iova_domain(iovad);
>> + if (iovad->granule)
>> + put_iova_domain(iovad);
>> kfree(iovad);
>> domain->iova_cookie = NULL;
>> }
>>
>> (It probably should have been that way from the start; mea culpa)
I originally put together a similar patch, but then thought that people
would
complain it didn't fix the root of the problem. Yet another instance
where
thinking was best avoided I guess.
>>
>> Robin.
>> _______________________________________________
>> iommu mailing list
>> iommu@lists.linux-foundation.org
>> https://lists.linuxfoundation.org/mailman/listinfo/iommu
>>
--
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm
Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a
Linux Foundation Collaborative Project.
next prev parent reply other threads:[~2016-07-14 17:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-13 18:49 [PATCH] iommu/iova: validate iova_domain input to put_iova_domain Nate Watterson
2016-07-13 18:49 ` Nate Watterson
[not found] ` <1468435772-27905-1-git-send-email-nwatters-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-07-14 8:34 ` Joerg Roedel
2016-07-14 8:34 ` Joerg Roedel
2016-07-14 10:36 ` Robin Murphy
[not found] ` <57876B45.6010206-5wv7dgnIgG8@public.gmane.org>
2016-07-14 11:21 ` Auger Eric
2016-07-14 11:21 ` Auger Eric
[not found] ` <77bca715-36e1-eb11-a49b-5d389b6cc0e8-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-14 17:55 ` nwatters-sgV2jX0FEOL9JmXXK+q4OQ [this message]
2016-07-14 17:55 ` nwatters
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=333f4b4f52168db68250a447ef5db3f3@codeaurora.org \
--to=nwatters-sgv2jx0feol9jmxxk+q4oq@public.gmane.org \
--cc=eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 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.