]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mshv: Fix use-after-free in mshv_map_user_memory error path
authorStanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Thu, 12 Mar 2026 16:02:53 +0000 (16:02 +0000)
committerWei Liu <wei.liu@kernel.org>
Fri, 13 Mar 2026 21:11:18 +0000 (21:11 +0000)
In the error path of mshv_map_user_memory(), calling vfree() directly on
the region leaves the MMU notifier registered. When userspace later unmaps
the memory, the notifier fires and accesses the freed region, causing a
use-after-free and potential kernel panic.

Replace vfree() with mshv_partition_put() to properly unregister
the MMU notifier before freeing the region.

Fixes: b9a66cd5ccbb9 ("mshv: Add support for movable memory regions")
Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
drivers/hv/mshv_root_main.c

index e281311b6a9d7b1e2432fc33a25c0144999ed676..6f42423f7faa8c956935abfee35e6217e40756a3 100644 (file)
@@ -1347,7 +1347,7 @@ mshv_map_user_memory(struct mshv_partition *partition,
        return 0;
 
 errout:
-       vfree(region);
+       mshv_region_put(region);
        return ret;
 }