* [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning
@ 2020-01-20 22:10 Tyrel Datwyler
2020-01-21 3:45 ` Alexey Kardashevskiy
2020-01-29 5:17 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Tyrel Datwyler @ 2020-01-20 22:10 UTC (permalink / raw)
To: mpe; +Cc: Tyrel Datwyler, aik, Tyrel Datwyler, drt, linuxppc-dev, david
From: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
Commit e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to
iommu_table") missed an iommu_table allocation in the pseries vio code.
The iommu_table is allocated with kzalloc and as a result the associated
kref gets a value of zero. This has the side effect that during a DLPAR
remove of the associated virtual IOA the iommu_tce_table_put() triggers
a use-after-free underflow warning.
Call Trace:
[c0000002879e39f0] [c00000000071ecb4] refcount_warn_saturate+0x184/0x190
(unreliable)
[c0000002879e3a50] [c0000000000500ac] iommu_tce_table_put+0x9c/0xb0
[c0000002879e3a70] [c0000000000f54e4] vio_dev_release+0x34/0x70
[c0000002879e3aa0] [c00000000087cfa4] device_release+0x54/0xf0
[c0000002879e3b10] [c000000000d64c84] kobject_cleanup+0xa4/0x240
[c0000002879e3b90] [c00000000087d358] put_device+0x28/0x40
[c0000002879e3bb0] [c0000000007a328c] dlpar_remove_slot+0x15c/0x250
[c0000002879e3c50] [c0000000007a348c] remove_slot_store+0xac/0xf0
[c0000002879e3cd0] [c000000000d64220] kobj_attr_store+0x30/0x60
[c0000002879e3cf0] [c0000000004ff13c] sysfs_kf_write+0x6c/0xa0
[c0000002879e3d10] [c0000000004fde4c] kernfs_fop_write+0x18c/0x260
[c0000002879e3d60] [c000000000410f3c] __vfs_write+0x3c/0x70
[c0000002879e3d80] [c000000000415408] vfs_write+0xc8/0x250
[c0000002879e3dd0] [c0000000004157dc] ksys_write+0x7c/0x120
[c0000002879e3e20] [c00000000000b278] system_call+0x5c/0x68
Further, since the refcount was always zero the iommu_tce_table_put()
fails to call the iommu_table release function resulting in a leak.
Fix this issue be initilizing the iommu_table kref immediately after
allocation.
Fixes: e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to iommu_table")
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
---
arch/powerpc/platforms/pseries/vio.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c
index 79e2287..f682b7b 100644
--- a/arch/powerpc/platforms/pseries/vio.c
+++ b/arch/powerpc/platforms/pseries/vio.c
@@ -1176,6 +1176,8 @@ static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
if (tbl == NULL)
return NULL;
+ kref_init(&tbl->it_kref);
+
of_parse_dma_window(dev->dev.of_node, dma_window,
&tbl->it_index, &offset, &size);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning
2020-01-20 22:10 [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning Tyrel Datwyler
@ 2020-01-21 3:45 ` Alexey Kardashevskiy
2020-01-29 5:17 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Alexey Kardashevskiy @ 2020-01-21 3:45 UTC (permalink / raw)
To: Tyrel Datwyler, mpe; +Cc: drt, linuxppc-dev, Tyrel Datwyler, david
On 21/01/2020 09:10, Tyrel Datwyler wrote:
> From: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
>
> Commit e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to
> iommu_table") missed an iommu_table allocation in the pseries vio code.
> The iommu_table is allocated with kzalloc and as a result the associated
> kref gets a value of zero. This has the side effect that during a DLPAR
> remove of the associated virtual IOA the iommu_tce_table_put() triggers
> a use-after-free underflow warning.
>
> Call Trace:
> [c0000002879e39f0] [c00000000071ecb4] refcount_warn_saturate+0x184/0x190
> (unreliable)
> [c0000002879e3a50] [c0000000000500ac] iommu_tce_table_put+0x9c/0xb0
> [c0000002879e3a70] [c0000000000f54e4] vio_dev_release+0x34/0x70
> [c0000002879e3aa0] [c00000000087cfa4] device_release+0x54/0xf0
> [c0000002879e3b10] [c000000000d64c84] kobject_cleanup+0xa4/0x240
> [c0000002879e3b90] [c00000000087d358] put_device+0x28/0x40
> [c0000002879e3bb0] [c0000000007a328c] dlpar_remove_slot+0x15c/0x250
> [c0000002879e3c50] [c0000000007a348c] remove_slot_store+0xac/0xf0
> [c0000002879e3cd0] [c000000000d64220] kobj_attr_store+0x30/0x60
> [c0000002879e3cf0] [c0000000004ff13c] sysfs_kf_write+0x6c/0xa0
> [c0000002879e3d10] [c0000000004fde4c] kernfs_fop_write+0x18c/0x260
> [c0000002879e3d60] [c000000000410f3c] __vfs_write+0x3c/0x70
> [c0000002879e3d80] [c000000000415408] vfs_write+0xc8/0x250
> [c0000002879e3dd0] [c0000000004157dc] ksys_write+0x7c/0x120
> [c0000002879e3e20] [c00000000000b278] system_call+0x5c/0x68
>
> Further, since the refcount was always zero the iommu_tce_table_put()
> fails to call the iommu_table release function resulting in a leak.
>
> Fix this issue be initilizing the iommu_table kref immediately after
> allocation.
>
> Fixes: e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to iommu_table")
> Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> arch/powerpc/platforms/pseries/vio.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c
> index 79e2287..f682b7b 100644
> --- a/arch/powerpc/platforms/pseries/vio.c
> +++ b/arch/powerpc/platforms/pseries/vio.c
> @@ -1176,6 +1176,8 @@ static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
> if (tbl == NULL)
> return NULL;
>
> + kref_init(&tbl->it_kref);
> +
> of_parse_dma_window(dev->dev.of_node, dma_window,
> &tbl->it_index, &offset, &size);
>
>
--
Alexey
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning
2020-01-20 22:10 [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning Tyrel Datwyler
2020-01-21 3:45 ` Alexey Kardashevskiy
@ 2020-01-29 5:17 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2020-01-29 5:17 UTC (permalink / raw)
To: Tyrel Datwyler
Cc: Tyrel Datwyler, aik, Tyrel Datwyler, drt, linuxppc-dev, david
On Mon, 2020-01-20 at 22:10:02 UTC, Tyrel Datwyler wrote:
> From: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
>
> Commit e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to
> iommu_table") missed an iommu_table allocation in the pseries vio code.
> The iommu_table is allocated with kzalloc and as a result the associated
> kref gets a value of zero. This has the side effect that during a DLPAR
> remove of the associated virtual IOA the iommu_tce_table_put() triggers
> a use-after-free underflow warning.
>
> Call Trace:
> [c0000002879e39f0] [c00000000071ecb4] refcount_warn_saturate+0x184/0x190
> (unreliable)
> [c0000002879e3a50] [c0000000000500ac] iommu_tce_table_put+0x9c/0xb0
> [c0000002879e3a70] [c0000000000f54e4] vio_dev_release+0x34/0x70
> [c0000002879e3aa0] [c00000000087cfa4] device_release+0x54/0xf0
> [c0000002879e3b10] [c000000000d64c84] kobject_cleanup+0xa4/0x240
> [c0000002879e3b90] [c00000000087d358] put_device+0x28/0x40
> [c0000002879e3bb0] [c0000000007a328c] dlpar_remove_slot+0x15c/0x250
> [c0000002879e3c50] [c0000000007a348c] remove_slot_store+0xac/0xf0
> [c0000002879e3cd0] [c000000000d64220] kobj_attr_store+0x30/0x60
> [c0000002879e3cf0] [c0000000004ff13c] sysfs_kf_write+0x6c/0xa0
> [c0000002879e3d10] [c0000000004fde4c] kernfs_fop_write+0x18c/0x260
> [c0000002879e3d60] [c000000000410f3c] __vfs_write+0x3c/0x70
> [c0000002879e3d80] [c000000000415408] vfs_write+0xc8/0x250
> [c0000002879e3dd0] [c0000000004157dc] ksys_write+0x7c/0x120
> [c0000002879e3e20] [c00000000000b278] system_call+0x5c/0x68
>
> Further, since the refcount was always zero the iommu_tce_table_put()
> fails to call the iommu_table release function resulting in a leak.
>
> Fix this issue be initilizing the iommu_table kref immediately after
> allocation.
>
> Fixes: e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to iommu_table")
> Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/aff8c8242bc638ba57247ae1ec5f272ac3ed3b92
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-29 6:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 22:10 [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning Tyrel Datwyler
2020-01-21 3:45 ` Alexey Kardashevskiy
2020-01-29 5:17 ` Michael Ellerman
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).