|
34 | 34 | u64 hv_current_partition_id = HV_PARTITION_ID_SELF; |
35 | 35 | EXPORT_SYMBOL_GPL(hv_current_partition_id); |
36 | 36 |
|
| 37 | +enum hv_partition_type hv_curr_partition_type; |
| 38 | +EXPORT_SYMBOL_GPL(hv_curr_partition_type); |
| 39 | + |
37 | 40 | /* |
38 | | - * hv_root_partition, ms_hyperv and hv_nested are defined here with other |
| 41 | + * ms_hyperv and hv_nested are defined here with other |
39 | 42 | * Hyper-V specific globals so they are shared across all architectures and are |
40 | 43 | * built only when CONFIG_HYPERV is defined. But on x86, |
41 | 44 | * ms_hyperv_init_platform() is built even when CONFIG_HYPERV is not |
42 | 45 | * defined, and it uses these three variables. So mark them as __weak |
43 | 46 | * here, allowing for an overriding definition in the module containing |
44 | 47 | * ms_hyperv_init_platform(). |
45 | 48 | */ |
46 | | -bool __weak hv_root_partition; |
47 | | -EXPORT_SYMBOL_GPL(hv_root_partition); |
48 | | - |
49 | 49 | bool __weak hv_nested; |
50 | 50 | EXPORT_SYMBOL_GPL(hv_nested); |
51 | 51 |
|
@@ -283,7 +283,7 @@ static void hv_kmsg_dump_register(void) |
283 | 283 |
|
284 | 284 | static inline bool hv_output_page_exists(void) |
285 | 285 | { |
286 | | - return hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE); |
| 286 | + return hv_root_partition() || IS_ENABLED(CONFIG_HYPERV_VTL_MODE); |
287 | 287 | } |
288 | 288 |
|
289 | 289 | void __init hv_get_partition_id(void) |
@@ -594,7 +594,7 @@ EXPORT_SYMBOL_GPL(hv_setup_dma_ops); |
594 | 594 |
|
595 | 595 | bool hv_is_hibernation_supported(void) |
596 | 596 | { |
597 | | - return !hv_root_partition && acpi_sleep_state_supported(ACPI_STATE_S4); |
| 597 | + return !hv_root_partition() && acpi_sleep_state_supported(ACPI_STATE_S4); |
598 | 598 | } |
599 | 599 | EXPORT_SYMBOL_GPL(hv_is_hibernation_supported); |
600 | 600 |
|
@@ -717,3 +717,23 @@ int hv_result_to_errno(u64 status) |
717 | 717 | } |
718 | 718 | return -EIO; |
719 | 719 | } |
| 720 | + |
| 721 | +void hv_identify_partition_type(void) |
| 722 | +{ |
| 723 | + /* Assume guest role */ |
| 724 | + hv_curr_partition_type = HV_PARTITION_TYPE_GUEST; |
| 725 | + /* |
| 726 | + * Check partition creation and cpu management privileges |
| 727 | + * |
| 728 | + * Hyper-V should never specify running as root and as a Confidential |
| 729 | + * VM. But to protect against a compromised/malicious Hyper-V trying |
| 730 | + * to exploit root behavior to expose Confidential VM memory, ignore |
| 731 | + * the root partition setting if also a Confidential VM. |
| 732 | + */ |
| 733 | + if ((ms_hyperv.priv_high & HV_CREATE_PARTITIONS) && |
| 734 | + (ms_hyperv.priv_high & HV_CPU_MANAGEMENT) && |
| 735 | + !(ms_hyperv.priv_high & HV_ISOLATION)) { |
| 736 | + pr_info("Hyper-V: running as root partition\n"); |
| 737 | + hv_curr_partition_type = HV_PARTITION_TYPE_ROOT; |
| 738 | + } |
| 739 | +} |
0 commit comments