vmap_pages_range_noflush() sets up the KMSAN metadata for the whole range before it starts mapping. If the mapping fails, the page tables undo themselves now, but the metadata stays behind, and the next attempt to map the same range hits the leftover shadow PTEs. Tear the metadata down on the error path, it was fully set up before the mapping failed. The teardown follows the page tables and skips cond_resched() when the caller's gfp mask cannot block. Signed-off-by: Hao Ge --- mm/vmalloc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 4f3c320a4849..28e65073624a 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -801,8 +801,18 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end, if (ret) return ret; - return __vmap_pages_range_noflush(addr, end, prot, pages, page_shift, - gfp_mask); + + ret = __vmap_pages_range_noflush(addr, end, prot, pages, page_shift, + gfp_mask); + /* + * The page tables undo themselves on failure. Tear down the + * metadata that was fully set up before the mapping failed. + */ + if (ret) + kmsan_vunmap_range_noflush(addr, end, + gfpflags_allow_blocking(gfp_mask)); + + return ret; } static int __vmap_pages_range(unsigned long addr, unsigned long end, -- 2.25.1