]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Mar 2026 10:13:31 +0000 (11:13 +0100)
[ Upstream commit 6922db250422a0dfee34de322f86b7a73d713d33 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hv/mshv_root_main.c

index d3e8a66443ad63d9dd06ff669fe5dee82d274e4a..45cf086ad430d40f43bddc6240bd0de8ca76a83d 100644 (file)
@@ -1334,7 +1334,7 @@ mshv_map_user_memory(struct mshv_partition *partition,
        return 0;
 
 errout:
-       vfree(region);
+       mshv_region_put(region);
        return ret;
 }