Skip to content

Commit 16cbec2

Browse files
Stanislav Kinsburskiiliuw
authored andcommitted
mshv: Fix infinite fault loop on permission-denied GPA intercepts
Prevent infinite fault loops when guests access memory regions without proper permissions. Currently, mshv_handle_gpa_intercept() attempts to remap pages for all faults on movable memory regions, regardless of whether the access type is permitted. When a guest writes to a read-only region, the remap succeeds but the region remains read-only, causing immediate re-fault and spinning the vCPU indefinitely. Validate intercept access type against region permissions before attempting remaps. Reject writes to non-writable regions and executes to non-executable regions early, returning false to let the VMM handle the intercept appropriately. This also closes a potential DoS vector where malicious guests could intentionally trigger these fault loops to consume host resources. Fixes: b9a66cd ("mshv: Add support for movable memory regions") Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Reviewed-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent b6422df commit 16cbec2

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

drivers/hv/mshv_root_main.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static bool mshv_handle_gpa_intercept(struct mshv_vp *vp)
630630
{
631631
struct mshv_partition *p = vp->vp_partition;
632632
struct mshv_mem_region *region;
633-
bool ret;
633+
bool ret = false;
634634
u64 gfn;
635635
#if defined(CONFIG_X86_64)
636636
struct hv_x64_memory_intercept_message *msg =
@@ -641,19 +641,28 @@ static bool mshv_handle_gpa_intercept(struct mshv_vp *vp)
641641
(struct hv_arm64_memory_intercept_message *)
642642
vp->vp_intercept_msg_page->u.payload;
643643
#endif
644+
enum hv_intercept_access_type access_type =
645+
msg->header.intercept_access_type;
644646

645647
gfn = HVPFN_DOWN(msg->guest_physical_address);
646648

647649
region = mshv_partition_region_by_gfn_get(p, gfn);
648650
if (!region)
649651
return false;
650652

653+
if (access_type == HV_INTERCEPT_ACCESS_WRITE &&
654+
!(region->hv_map_flags & HV_MAP_GPA_WRITABLE))
655+
goto put_region;
656+
657+
if (access_type == HV_INTERCEPT_ACCESS_EXECUTE &&
658+
!(region->hv_map_flags & HV_MAP_GPA_EXECUTABLE))
659+
goto put_region;
660+
651661
/* Only movable memory ranges are supported for GPA intercepts */
652662
if (region->mreg_type == MSHV_REGION_TYPE_MEM_MOVABLE)
653663
ret = mshv_region_handle_gfn_fault(region, gfn);
654-
else
655-
ret = false;
656664

665+
put_region:
657666
mshv_region_put(region);
658667

659668
return ret;

include/hyperv/hvgdk_mini.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,4 +1533,10 @@ struct hv_mmio_write_input {
15331533
u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH];
15341534
} __packed;
15351535

1536+
enum hv_intercept_access_type {
1537+
HV_INTERCEPT_ACCESS_READ = 0,
1538+
HV_INTERCEPT_ACCESS_WRITE = 1,
1539+
HV_INTERCEPT_ACCESS_EXECUTE = 2
1540+
};
1541+
15361542
#endif /* _HV_HVGDK_MINI_H */

include/hyperv/hvhdk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ struct hv_x64_intercept_message_header {
779779
u32 vp_index;
780780
u8 instruction_length:4;
781781
u8 cr8:4; /* Only set for exo partitions */
782-
u8 intercept_access_type;
782+
u8 intercept_access_type; /* enum hv_intercept_access_type */
783783
union hv_x64_vp_execution_state execution_state;
784784
struct hv_x64_segment_register cs_segment;
785785
u64 rip;
@@ -825,7 +825,7 @@ union hv_arm64_vp_execution_state {
825825
struct hv_arm64_intercept_message_header {
826826
u32 vp_index;
827827
u8 instruction_length;
828-
u8 intercept_access_type;
828+
u8 intercept_access_type; /* enum hv_intercept_access_type */
829829
union hv_arm64_vp_execution_state execution_state;
830830
u64 pc;
831831
u64 cpsr;

0 commit comments

Comments
 (0)