iommufd: Initialize batch->kind in batch_clear()
PATCH 1/1 iommufd: Initialize batch->kind in batch_clear()
KMSAN reported an uninitialized value when batch_add_pfn_num() reads batch->kind. This occurs because batch_clear() does not initialize the kind field, leaving it with garbage data when a struct pfn_batch is declared on the stack.
When batch_add_pfn_num() checks "if (batch->kind != kind)", it reads this uninitialized value, triggering KMSAN warnings.
Initialize batch->kind to zero in batch_clear() to ensure the field always starts in a known state.
--- drivers/iommu/iommufd/pages.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/iommufd/pages.c +1 -0
@@ -289,6 +289,7 @@ static void batch_clear(struct pfn_batch *batch) batch->end =0 ; batch->pfns[0 ] =0 ; batch->npfns[0 ] =0 ; + batch->kind =0 ; }/*
Signature · 1 line
2.43.0
Quoted 12 lines
From: Deepanshu Kartikey <[email protected]>
Sent: Saturday, January 24, 2026 9:22 PMKMSAN reported an uninitialized value when
batch_add_pfn_num()readsbatch->kind. This occurs becausebatch_clear()does not initialize the kind field, leaving it with garbage data when a structpfn_batchis declared on the stack.When
batch_add_pfn_num()checks "if (batch->kind!= kind)", it reads this uninitialized value, triggering KMSAN warnings.
Quoted 8 lines
Initialize
batch->kindto zero inbatch_clear()to ensure the field always starts in a known state.Reported-by [email protected]Fixes f394576eb11db ("iommufd: PFN handling for iopt_pages")Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>
Jason Gunthorpe
AppliedQuoted 12 lines · Deepanshu Kartikey
KMSAN reported an uninitialized value when
batch_add_pfn_num()readsbatch->kind. This occurs becausebatch_clear()does not initialize the kind field, leaving it with garbage data when a structpfn_batchis declared on the stack.When
batch_add_pfn_num()checks "if (batch->kind!= kind)", it reads this uninitialized value, triggering KMSAN warnings.Initialize
batch->kindto zero inbatch_clear()to ensure the field always starts in a known state.
Quoted 8 lines
Reported-by [email protected]Fixes f394576eb11db ("iommufd: PFN handling for iopt_pages")Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- drivers/iommu/iommufd/pages.c | 1 + 1 file changed, 1 insertion(+)
Applied to for-rc, thanks
Jason