iommufd: Fix NULL deref of area->pages in ioas_change_process
PATCH 1/1 iommufd: Fix NULL deref of area->pages in ioas_change_process
Areas are inserted into the area_itree before area->pages is assigned, so an area with a NULL pages pointer is briefly visible to readers. iommufd_ioas_change_process() walks every area and dereferences area->pages unconditionally, which oopses when racing with a concurrent IOMMU_IOAS_MAP_FILE.
Reject the racing case with -EBUSY, matching how iopt_unmap_iova_range() handles the same window. Checking in the first loop covers the whole function since all iova_rwsems are held for write across the call.
--- drivers/iommu/iommufd/ioas.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iommu/iommufd/ioas.c +4 -0
@@ -535,6 +535,10 @@ int iommufd_ioas_change_process(struct iommufd_ucmd *ucmd)return rc;for_each_ioas_area (&ioas_list, index, ioas, area) { +if (!area->pages) { + rc = -EBUSY ; + goto out; + }if (area->pages->type !=IOPT_ADDRESS_FILE ) { rc = -EINVAL ; goto out;
Signature · 1 line
2.34.1
Hey Kartikey,
Quoted 11 lines · Deepanshu Kartikey
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Areas are inserted into the
area_itreebeforearea->pagesis assigned, so an area with a NULL pages pointer is briefly visible to readers.iommufd_ioas_change_process()walks every area and dereferencesarea->pagesunconditionally, which oopses when racing with a concurrentIOMMU_IOAS_MAP_FILE.
Quoted 4 lines
Reject the racing case with
-EBUSY, matching howiopt_unmap_iova_range()handles the same window. Checking in the first loop covers the whole function since alliova_rwsemsare held for write across the call.
This is same as submitted by Peiyang
https://lore.kernel.org/all/7344B7A7B9957A65+20260806045059.1884737-1-peiyang_he@smail.nju.edu.cn/
- tushar
Quoted 28 lines
Fixes 829ed626499c ("iommufd: Add IOMMU_IOAS_CHANGE_PROCESS")Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- drivers/iommu/iommufd/ioas.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iommu/iommufd/ioas.c +4
-1@@ -535,6 +535,10 @@ int iommufd_ioas_change_process(struct iommufd_ucmd *ucmd)return rc;for_each_ioas_area (&ioas_list, index, ioas, area) { +if (!area->pages) { + rc = -EBUSY ; + goto out; + }if (area->pages->type !=IOPT_ADDRESS_FILE ) { rc = -EINVAL ; goto out; --2.34.1