* [PATCH] iommu/apple-dart: Properly check the error
@ 2026-11-27 9:51 Anton Protopopov
2026-11-30 10:04 ` Joerg Roedel
0 siblings, 1 reply; 2+ messages in thread
From: Anton Protopopov @ 2026-11-27 9:51 UTC (permalink / raw)
To: Sven Peter, Joerg Roedel, Will Deacon, Janne Grunau, Neal Gompa,
Robin Murphy, iommu, asahi, linux-arm-kernel
Cc: Anton Protopopov
The apple_dart_device_group() function expects pci_device_group()
(or generic_device_group() for a non-PCI device) to return NULL on
failure. However, both of them return an error pointer instead of
NULL. The error pointer then is immediately dereferenced by the
iommu_group_get_iommudata() function.
Check for an error pointer instead of NULL and return the error.
Fixes: f0b636804c7c ("iommu/dart: Clear sid2group entry when a group is freed")
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
(Found accidentally, while working on BPF stuff.)
drivers/iommu/apple-dart.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index d8302128b465..36ce5ac39b7b 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -981,8 +981,8 @@ static struct iommu_group *apple_dart_device_group(struct device *dev)
#endif
group = generic_device_group(dev);
- res = ERR_PTR(-ENOMEM);
- if (!group)
+ res = group;
+ if (IS_ERR(group))
goto out;
group_master_cfg = iommu_group_get_iommudata(group);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iommu/apple-dart: Properly check the error
2026-11-27 9:51 [PATCH] iommu/apple-dart: Properly check the error Anton Protopopov
@ 2026-11-30 10:04 ` Joerg Roedel
0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2026-11-30 10:04 UTC (permalink / raw)
To: Anton Protopopov
Cc: Sven Peter, Will Deacon, Janne Grunau, Neal Gompa, Robin Murphy,
iommu, asahi, linux-arm-kernel
On Fri, Nov 27, 2026 at 09:51:18AM +0000, Anton Protopopov wrote:
> The apple_dart_device_group() function expects pci_device_group()
> (or generic_device_group() for a non-PCI device) to return NULL on
> failure. However, both of them return an error pointer instead of
> NULL. The error pointer then is immediately dereferenced by the
> iommu_group_get_iommudata() function.
>
> Check for an error pointer instead of NULL and return the error.
>
> Fixes: f0b636804c7c ("iommu/dart: Clear sid2group entry when a group is freed")
> Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
> ---
>
> (Found accidentally, while working on BPF stuff.)
>
> drivers/iommu/apple-dart.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index d8302128b465..36ce5ac39b7b 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -981,8 +981,8 @@ static struct iommu_group *apple_dart_device_group(struct device *dev)
> #endif
> group = generic_device_group(dev);
>
> - res = ERR_PTR(-ENOMEM);
> - if (!group)
> + res = group;
> + if (IS_ERR(group))
> goto out;
Assigning `group` to `res` seems problematic, here is what AI found:
Return -ENOMEM when copying the DART group configuration fails —
/home/joro/src/iommu/linux/drivers/iommu/apple-dart.c:984-984 If kmemdup()
fails in apple_dart_device_group(), the error path drops the group reference
with iommu_group_put() but returns res, which now holds the group pointer.
iommu_init_device() treats that pointer as success and stores it in
dev->iommu_group, so the probe can use a freed group. Preserve ERR_PTR(-ENOMEM)
on the copy-failure path while still propagating errors from the group
lookup.
-Joerg
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 10:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 9:51 [PATCH] iommu/apple-dart: Properly check the error Anton Protopopov
2026-11-30 10:04 ` Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox