Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH] iommufd: Initialize batch->kind in batch_clear()
@ 2026-01-24 13:22 Deepanshu Kartikey
  2026-01-26  7:56 ` Tian, Kevin
  2026-01-28 16:55 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Deepanshu Kartikey @ 2026-01-24 13:22 UTC (permalink / raw)
  To: jgg, kevin.tian, joro, will, robin.murphy
  Cc: iommu, Deepanshu Kartikey, syzbot+df28076a30d726933015


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: syzbot+df28076a30d726933015@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=df28076a30d726933015
Fixes: f394576eb11db ("iommufd: PFN handling for iopt_pages")
Tested-by: syzbot+df28076a30d726933015@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 drivers/iommu/iommufd/pages.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
index dbe51ecb9a20..f606148920fa 100644
--- a/drivers/iommu/iommufd/pages.c
+++ b/drivers/iommu/iommufd/pages.c
@@ -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;
 }
 
 /*
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] iommufd: Initialize batch->kind in batch_clear()
  2026-01-24 13:22 [PATCH] iommufd: Initialize batch->kind in batch_clear() Deepanshu Kartikey
@ 2026-01-26  7:56 ` Tian, Kevin
  2026-01-28 16:55 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Tian, Kevin @ 2026-01-26  7:56 UTC (permalink / raw)
  To: Deepanshu Kartikey, jgg@ziepe.ca, joro@8bytes.org,
	will@kernel.org, robin.murphy@arm.com
  Cc: iommu@lists.linux.dev,
	syzbot+df28076a30d726933015@syzkaller.appspotmail.com

> From: Deepanshu Kartikey <kartikey406@gmail.com>
> 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.
> 
> Initialize batch->kind to zero in batch_clear() to ensure the field
> always starts in a known state.
> 
> Reported-by: syzbot+df28076a30d726933015@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=df28076a30d726933015
> Fixes: f394576eb11db ("iommufd: PFN handling for iopt_pages")
> Tested-by: syzbot+df28076a30d726933015@syzkaller.appspotmail.com
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommufd: Initialize batch->kind in batch_clear()
  2026-01-24 13:22 [PATCH] iommufd: Initialize batch->kind in batch_clear() Deepanshu Kartikey
  2026-01-26  7:56 ` Tian, Kevin
@ 2026-01-28 16:55 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2026-01-28 16:55 UTC (permalink / raw)
  To: Deepanshu Kartikey
  Cc: kevin.tian, joro, will, robin.murphy, iommu,
	syzbot+df28076a30d726933015

On Sat, Jan 24, 2026 at 06:52:14PM +0530, Deepanshu Kartikey wrote:
> 
> 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: syzbot+df28076a30d726933015@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=df28076a30d726933015
> Fixes: f394576eb11db ("iommufd: PFN handling for iopt_pages")
> Tested-by: syzbot+df28076a30d726933015@syzkaller.appspotmail.com
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> ---
>  drivers/iommu/iommufd/pages.c | 1 +
>  1 file changed, 1 insertion(+)

Applied to for-rc, thanks

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-28 16:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-24 13:22 [PATCH] iommufd: Initialize batch->kind in batch_clear() Deepanshu Kartikey
2026-01-26  7:56 ` Tian, Kevin
2026-01-28 16:55 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox