Skip to contentSkip to conversation

iommufd: Initialize batch->kind in batch_clear()

PATCH Applied Deepanshu Kartikey 3 participants 3 messages Jan 24 – Jan 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Reported-by [email protected]
Fixes f394576eb11db ("iommufd: PFN handling for iopt_pages")
---
 drivers/iommu/iommufd/pages.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/iommufd/pages.c +1 -0
index dbe51ecb9a20..f606148920fa 100644
@@ -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
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines

From: Deepanshu Kartikey <[email protected]>
Sent: Saturday, January 24, 2026 9:22 PM

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.

Quoted 8 lines

Initialize batch->kind to zero in batch_clear() to ensure the field always starts in a known state.

Reported-by [email protected]
Fixes f394576eb11db ("iommufd: PFN handling for iopt_pages")
#2 lore raw
In reply to Deepanshu Kartikey
Quoted 12 lines · Deepanshu Kartikey

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.

Quoted 8 lines
Reported-by [email protected]
Fixes f394576eb11db ("iommufd: PFN handling for iopt_pages")
---
 drivers/iommu/iommufd/pages.c | 1 +
 1 file changed, 1 insertion(+)

Applied to for-rc, thanks

Jason