* [PATCH] iommu: Avoid NULL group dereference
@ 2017-08-17 10:40 Robin Murphy
2017-08-17 10:51 ` Marc Zyngier
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Robin Murphy @ 2017-08-17 10:40 UTC (permalink / raw)
To: joro-zLv9SwRftAIdnm+yROfE0A
Cc: marc.zyngier-5wv7dgnIgG8,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
shawn.lin-TNX95d0MmH7DzftRWevZcw,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
The recently-removed FIXME in iommu_get_domain_for_dev() turns out to
have been a little misleading, since that check is still worthwhile even
when groups *are* universal. We have a few IOMMU-aware drivers which
only care whether their device is already attached to an existing domain
or not, for which the previous behaviour of iommu_get_domain_for_dev()
was ideal, and who now crash if their device does not have an IOMMU.
With IOMMU groups now serving as a reliable indicator of whether a
device has an IOMMU or not (barring false-positives from VFIO no-IOMMU
mode), drivers could arguably do this:
group = iommu_group_get(dev);
if (group) {
domain = iommu_get_domain_for_dev(dev);
iommu_group_put(group);
}
However, rather than duplicate that code across multiple callsites,
particularly when it's still only the domain they care about, let's skip
straight to the next step and factor out the check into the common place
it applies - in iommu_get_domain_for_dev() itself. Sure, it ends up
looking rather familiar, but now it's backed by the reasoning of having
a robust API able to do the expected thing for all devices regardless.
Fixes: 05f80300dc8b ("iommu: Finish making iommu_group support mandatory")
Reported-by: Shawn Lin <shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
---
As well as dma-iommu, there are at least the Cavium ThunderX and
Freescale DPAA2 ethernet drivers expecting this to work too.
drivers/iommu/iommu.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index af69bf7e035a..5499a0387349 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1352,6 +1352,8 @@ struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
struct iommu_group *group;
group = iommu_group_get(dev);
+ if (!group)
+ return NULL;
domain = group->domain;
--
2.13.4.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] iommu: Avoid NULL group dereference
2017-08-17 10:40 [PATCH] iommu: Avoid NULL group dereference Robin Murphy
@ 2017-08-17 10:51 ` Marc Zyngier
[not found] ` <59a6c4f0a790eea40e2b2f2be840b63317dd44e4.1502966326.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2017-08-18 0:49 ` Shawn Lin
2 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2017-08-17 10:51 UTC (permalink / raw)
To: Robin Murphy, joro; +Cc: iommu, shawn.lin, linux-kernel
On 17/08/17 11:40, Robin Murphy wrote:
> The recently-removed FIXME in iommu_get_domain_for_dev() turns out to
> have been a little misleading, since that check is still worthwhile even
> when groups *are* universal. We have a few IOMMU-aware drivers which
> only care whether their device is already attached to an existing domain
> or not, for which the previous behaviour of iommu_get_domain_for_dev()
> was ideal, and who now crash if their device does not have an IOMMU.
>
> With IOMMU groups now serving as a reliable indicator of whether a
> device has an IOMMU or not (barring false-positives from VFIO no-IOMMU
> mode), drivers could arguably do this:
>
> group = iommu_group_get(dev);
> if (group) {
> domain = iommu_get_domain_for_dev(dev);
> iommu_group_put(group);
> }
>
> However, rather than duplicate that code across multiple callsites,
> particularly when it's still only the domain they care about, let's skip
> straight to the next step and factor out the check into the common place
> it applies - in iommu_get_domain_for_dev() itself. Sure, it ends up
> looking rather familiar, but now it's backed by the reasoning of having
> a robust API able to do the expected thing for all devices regardless.
>
> Fixes: 05f80300dc8b ("iommu: Finish making iommu_group support mandatory")
> Reported-by: Shawn Lin <shawn.lin@rock-chips.com>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Thanks,
M.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 6+ messages in thread[parent not found: <59a6c4f0a790eea40e2b2f2be840b63317dd44e4.1502966326.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH] iommu: Avoid NULL group dereference
[not found] ` <59a6c4f0a790eea40e2b2f2be840b63317dd44e4.1502966326.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
@ 2017-08-17 15:41 ` Joerg Roedel
[not found] ` <20170817154101.GL16908-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Joerg Roedel @ 2017-08-17 15:41 UTC (permalink / raw)
To: Robin Murphy
Cc: marc.zyngier-5wv7dgnIgG8,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
shawn.lin-TNX95d0MmH7DzftRWevZcw,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Thu, Aug 17, 2017 at 11:40:08AM +0100, Robin Murphy wrote:
> The recently-removed FIXME in iommu_get_domain_for_dev() turns out to
> have been a little misleading, since that check is still worthwhile even
> when groups *are* universal. We have a few IOMMU-aware drivers which
> only care whether their device is already attached to an existing domain
> or not, for which the previous behaviour of iommu_get_domain_for_dev()
> was ideal, and who now crash if their device does not have an IOMMU.
>
> With IOMMU groups now serving as a reliable indicator of whether a
> device has an IOMMU or not (barring false-positives from VFIO no-IOMMU
> mode), drivers could arguably do this:
>
> group = iommu_group_get(dev);
> if (group) {
> domain = iommu_get_domain_for_dev(dev);
> iommu_group_put(group);
> }
Okay, so just to check I got it right: Drivers do the above to check
whether a device is managed by an IOMMU, and that crashes now because
the 'group == NULL' check was removed?
Regards,
Joerg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iommu: Avoid NULL group dereference
2017-08-17 10:40 [PATCH] iommu: Avoid NULL group dereference Robin Murphy
2017-08-17 10:51 ` Marc Zyngier
[not found] ` <59a6c4f0a790eea40e2b2f2be840b63317dd44e4.1502966326.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
@ 2017-08-18 0:49 ` Shawn Lin
2 siblings, 0 replies; 6+ messages in thread
From: Shawn Lin @ 2017-08-18 0:49 UTC (permalink / raw)
To: Robin Murphy, joro; +Cc: shawn.lin, iommu, marc.zyngier, linux-kernel
Hi
On 2017/8/17 18:40, Robin Murphy wrote:
> The recently-removed FIXME in iommu_get_domain_for_dev() turns out to
> have been a little misleading, since that check is still worthwhile even
> when groups *are* universal. We have a few IOMMU-aware drivers which
> only care whether their device is already attached to an existing domain
> or not, for which the previous behaviour of iommu_get_domain_for_dev()
> was ideal, and who now crash if their device does not have an IOMMU.
>
It works, thanks!
Tested-by: Shawn Lin <shawn.lin@rock-chips.com>
> With IOMMU groups now serving as a reliable indicator of whether a
> device has an IOMMU or not (barring false-positives from VFIO no-IOMMU
> mode), drivers could arguably do this:
>
> group = iommu_group_get(dev);
> if (group) {
> domain = iommu_get_domain_for_dev(dev);
> iommu_group_put(group);
> }
>
> However, rather than duplicate that code across multiple callsites,
> particularly when it's still only the domain they care about, let's skip
> straight to the next step and factor out the check into the common place
> it applies - in iommu_get_domain_for_dev() itself. Sure, it ends up
> looking rather familiar, but now it's backed by the reasoning of having
> a robust API able to do the expected thing for all devices regardless.
>
> Fixes: 05f80300dc8b ("iommu: Finish making iommu_group support mandatory")
> Reported-by: Shawn Lin <shawn.lin@rock-chips.com>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>
> As well as dma-iommu, there are at least the Cavium ThunderX and
> Freescale DPAA2 ethernet drivers expecting this to work too.
>
> drivers/iommu/iommu.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index af69bf7e035a..5499a0387349 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -1352,6 +1352,8 @@ struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
> struct iommu_group *group;
>
> group = iommu_group_get(dev);
> + if (!group)
> + return NULL;
>
> domain = group->domain;
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-08-18 9:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-17 10:40 [PATCH] iommu: Avoid NULL group dereference Robin Murphy
2017-08-17 10:51 ` Marc Zyngier
[not found] ` <59a6c4f0a790eea40e2b2f2be840b63317dd44e4.1502966326.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2017-08-17 15:41 ` Joerg Roedel
[not found] ` <20170817154101.GL16908-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2017-08-17 16:56 ` Robin Murphy
2017-08-18 9:42 ` Joerg Roedel
2017-08-18 0:49 ` Shawn Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox