kmsan: fix kmsan_handle_dma() to avoid false positives
Subsystems (2)
PATCH 1/1 kmsan: fix kmsan_handle_dma() to avoid false positives
KMSAN reports an uninitialized value issue in dma_map_phys()[1]. This is a false positive caused by the way the virtual address is handled in kmsan_handle_dma(). Fix it by translating the physical address to a virtual address using phys_to_virt().
[1]
BUG: KMSAN: uninit-value in dma_map_phys+0xdc5/0x1060 dma_map_phys+0xdc5/0x1060 dma_map_page_attrs+0xcf/0x130 e1000_xmit_frame+0x3c51/0x78f0 dev_hard_start_xmit+0x22f/0xa30 sch_direct_xmit+0x3b2/0xcf0 __dev_queue_xmit+0x3588/0x5e60 neigh_resolve_output+0x9c5/0xaf0 ip6_finish_output2+0x24e0/0x2d30 ip6_finish_output+0x903/0x10d0 ip6_output+0x331/0x600 mld_sendpack+0xb4a/0x1770 mld_ifc_work+0x1328/0x19b0 process_scheduled_works+0xb91/0x1d80 worker_thread+0xedf/0x1590 kthread+0xd5c/0xf00 ret_from_fork+0x1f5/0x4c0 ret_from_fork_asm+0x1a/0x30
Uninit was created at:
__kmalloc_cache_noprof+0x8f5/0x16b0 syslog_print+0x9a/0xef0 do_syslog+0x849/0xfe0 __x64_sys_syslog+0x97/0x100 x64_sys_call+0x3cf8/0x3e30 do_syscall_64+0xd9/0xfa0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Bytes 0-89 of 90 are uninitialized
Memory access of size 90 starts at ffff8880367ed000
CPU: 1 UID: 0 PID: 1552 Comm: kworker/1:2 Not tainted 6.17.0-next-20250929 #26 PREEMPT(none) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-5.fc42 04/01/2014 Workqueue: mld mld_ifc_work
---
The hash in the "Fixes" tag comes from the linux-next tree (next-20250929), as it has not yet been included in the mainline tree.
--- mm/kmsan/hooks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/kmsan/hooks.c +1 -2
@@ -339,13 +339,12 @@ static void kmsan_handle_dma_page(const void *addr, size_t size,void kmsan_handle_dma (phys_addr_t phys,size_t size,enum dma_data_direction dir) { -struct page *page =phys_to_page (phys);u64 page_offset, to_go;void *addr;if (PhysHighMem (phys))return ; - addr =page_to_virt (page); + addr =phys_to_virt (phys);/* * The kernel may occasionally give us adjacent DMA pages not belonging * to the same allocation. Process them separately to avoid triggering
Signature · 1 line
2.51.0
Quoted 4 lines · Shigeru Yoshida
KMSAN reports an uninitialized value issue in dma_map_phys()[1]. This is a false positive caused by the way the virtual address is handled in
kmsan_handle_dma(). Fix it by translating the physical address to a virtual address usingphys_to_virt().
This is the same sort of thinko as was found on the alpha patch, it is tricky!
mm/kmsan/hooks.c static void kmsan_handle_dma_page(const void *addr, size_t size, · line 342
Quoted 5 lines
mm/kmsan/hooks.c +0
-1@@ -339,13 +339,12 @@ static void kmsan_handle_dma_page(const void *addr, size_t size,void kmsan_handle_dma (phys_addr_t phys,size_t size,enum dma_data_direction dir) { -struct page *page =phys_to_page (phys);
This throws away the page_offset encoded in phys
mm/kmsan/hooks.c static void kmsan_handle_dma_page(const void *addr, size_t size, · line 348
Quoted 6 lines
mm/kmsan/hooks.c +0
-1u64 page_offset, to_go;void *addr;if (PhysHighMem (phys))return ; - addr =page_to_virt (page);
And this gives an addr that is now 0 page_offset, which is not right.
mm/kmsan/hooks.c static void kmsan_handle_dma_page(const void *addr, size_t size, · line 347
Quoted 1 line
mm/kmsan/hooks.c +1
-0+ addr =phys_to_virt (phys);
Make more sense anyhow when combined with PhysHighMem() and gives the right page_offset.
Jason
Marek Szyprowski
AppliedQuoted 37 lines · Shigeru Yoshida
KMSAN reports an uninitialized value issue in dma_map_phys()[1]. This is a false positive caused by the way the virtual address is handled in
kmsan_handle_dma(). Fix it by translating the physical address to a virtual address usingphys_to_virt().[1]
BUG: KMSAN: uninit-value in dma_map_phys+0xdc5/0x1060 dma_map_phys+0xdc5/0x1060 dma_map_page_attrs+0xcf/0x130 e1000_xmit_frame+0x3c51/0x78f0 dev_hard_start_xmit+0x22f/0xa30 sch_direct_xmit+0x3b2/0xcf0 __dev_queue_xmit+0x3588/0x5e60 neigh_resolve_output+0x9c5/0xaf0 ip6_finish_output2+0x24e0/0x2d30 ip6_finish_output+0x903/0x10d0 ip6_output+0x331/0x600 mld_sendpack+0xb4a/0x1770 mld_ifc_work+0x1328/0x19b0 process_scheduled_works+0xb91/0x1d80 worker_thread+0xedf/0x1590 kthread+0xd5c/0xf00 ret_from_fork+0x1f5/0x4c0 ret_from_fork_asm+0x1a/0x30Uninit was created at:
__kmalloc_cache_noprof+0x8f5/0x16b0 syslog_print+0x9a/0xef0 do_syslog+0x849/0xfe0 __x64_sys_syslog+0x97/0x100 x64_sys_call+0x3cf8/0x3e30 do_syscall_64+0xd9/0xfa0 entry_SYSCALL_64_after_hwframe+0x77/0x7fBytes 0-89 of 90 are uninitialized
Memory access of size 90 starts atffff8880367ed000
Quoted 6 lines
CPU: 1 UID: 0 PID: 1552 Comm: kworker/1:2 Not tainted 6.17.0-next-20250929 #26 PREEMPT(none) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-5.fc42 04/01/2014 Workqueue: mld mld_ifc_workFixes 6eb1e769b2c1 ("kmsan: convert kmsan_handle_dma to use physical addresses")Signed-off-by Shigeru Yoshida <[email protected]>
Applied to dma-mapping-for-next (for v6.18-rc1) branch. Thanks!
Quoted 16 lines
---
The hash in the "Fixes" tag comes from the linux-next tree (next-20250929), as it has not yet been included in the mainline tree.--- mm/kmsan/hooks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/kmsan/hooks.c +0
-1@@ -339,13 +339,12 @@ static void kmsan_handle_dma_page(const void *addr, size_t size,void kmsan_handle_dma (phys_addr_t phys,size_t size,enum dma_data_direction dir) { -struct page *page =phys_to_page (phys);
mm/kmsan/hooks.c static void kmsan_handle_dma_page(const void *addr, size_t size, · line 350
Quoted 10 lines
mm/kmsan/hooks.c +1
-1u64 page_offset, to_go;void *addr;if (PhysHighMem (phys))return ; - addr =page_to_virt (page); + addr =phys_to_virt (phys);/* * The kernel may occasionally give us adjacent DMA pages not belonging * to the same allocation. Process them separately to avoid triggering
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland