Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Add logic for creating nonexisiting meltdown registry keys
Browse files Browse the repository at this point in the history
[#157323151]
  • Loading branch information
Kenny DuMez committed Oct 30, 2018
1 parent 8e94128 commit 17a9aa2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
25 changes: 19 additions & 6 deletions AutomationHelpers.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,25 @@ Describe "Create-VMPrepTaskAction" {

Describe "Set-MeltdownRegistryKeys" {

It "Successfully sets the meltdown registry keys " {
Mock Set-ItemProperty { }
It "Successfully sets the meltdown registry keys." {
Mock New-ItemProperty{ }
Mock Test-Path { $True }
{ Set-MeltdownRegKeys } | Should -Not -Throw
Assert-MockCalled Set-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat' -and $Value -eq 0 -and $Name -eq 'cadca5fe-87d3-4b96-b7fb-a231484277cc' }
Assert-MockCalled Set-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization' -and $Value -eq 1.0 -and $Name -eq 'MinVmVersionForCpuBasedMitigations' }
Assert-MockCalled Set-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -and $Value -eq 3 -and $Name -eq 'FeatureSettingsOverrideMask' }
Assert-MockCalled Set-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -and $Value -eq 0 -and $Name -eq 'FeatureSettingsOverride' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat' -and $Value -eq 0 -and $Name -eq 'cadca5fe-87d3-4b96-b7fb-a231484277cc' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization' -and $Value -eq 1.0 -and $Name -eq 'MinVmVersionForCpuBasedMitigations' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -and $Value -eq 3 -and $Name -eq 'FeatureSettingsOverrideMask' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -and $Value -eq 0 -and $Name -eq 'FeatureSettingsOverride' }
}

It "Successfully sets the meltdown registry keys including non-existing one. " {
Mock New-Item { }
Mock New-ItemProperty{ }
Mock Test-Path { $False }
{ Set-MeltdownRegKeys } | Should -Not -Throw
Assert-MockCalled New-Item -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat' } -Times 1
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat' -and $Value -eq 0 -and $Name -eq 'cadca5fe-87d3-4b96-b7fb-a231484277cc' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization' -and $Value -eq 1.0 -and $Name -eq 'MinVmVersionForCpuBasedMitigations' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -and $Value -eq 3 -and $Name -eq 'FeatureSettingsOverrideMask' }
Assert-MockCalled New-ItemProperty -ParameterFilter{ $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -and $Value -eq 0 -and $Name -eq 'FeatureSettingsOverride' }
}
}
17 changes: 11 additions & 6 deletions AutomationHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,26 @@ function InstallOpenSSH

function Set-MeltdownRegKeys
{
$PathExists = Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat'
try
{
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat' -Value 0 -Name 'cadca5fe-87d3-4b96-b7fb-a231484277cc'
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization' -Value 1.0 -Name 'MinVmVersionForCpuBasedMitigations'
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Value 3 -Name 'FeatureSettingsOverrideMask'
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Value 0 -Name 'FeatureSettingsOverride'
Write-Log "Meltdown registry keys successfully added"
if ($PathExists -eq $False)
{
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat'
}

New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat' -Value 0 -Name 'cadca5fe-87d3-4b96-b7fb-a231484277cc' -force
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization' -Value 1.0 -Name 'MinVmVersionForCpuBasedMitigations' -force
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Value 3 -Name 'FeatureSettingsOverrideMask' -force
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Value 0 -Name 'FeatureSettingsOverride' -force
Write-Log "Meltdown registry keys successfully added"
}
catch [Exception]
{
Write-Log $_.Exception.Message
Write-Log "Failed to set meltdown registry keys. See 'c:\provisions\log.log' for mor info."
throw $_.Exception
}

}


Expand Down

0 comments on commit 17a9aa2

Please sign in to comment.