Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell .net class loads slow since MS-Security Update April 2019 #9884

Closed
fadanner opened this issue Jun 13, 2019 · 15 comments
Closed

Powershell .net class loads slow since MS-Security Update April 2019 #9884

fadanner opened this issue Jun 13, 2019 · 15 comments
Assignees
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Fixed The issue is fixed. WG-Interactive-Debugging debugging PowerShell script
Milestone

Comments

@fadanner
Copy link

fadanner commented Jun 13, 2019

Since May 2019 Security Rollup for Windows Server 2016, access to .net object via powershell is very slow, when a powershell variable breakpoint is set in the powershell.

For example loading speed of [System.Environment] takes over ten times with breakpoint set against no breakpoint set.

Since the behavior only occurs with latest security updates installed (May 2019 (KB4494440) or June 2019 (KB4503267)) i think it is related to the update.

Did some troubleshooting with procmon until now. For me it looks like when PSBreakpoint is set, there are multiple reads from HKLM\System\CurrentControlSet\Control\Session Manager\Environment\__PSLockdownPolicy can't repoduce this when there is no breakpoint set and can't reproduce this effect without one of the updates installed.

Following powershell code runs more than 10 times slower when i install Windows Security Rollup update Mai / June 2019 on my Windows Server 2016.


$measure1 = measure-command{
  foreach($i in 1..10000){
    [System.Environment]
  }
} |select -ExpandProperty TotalSeconds

Set-PSBreakpoint -Variable "test" -Action {$null}

$measure2 = measure-command{
  foreach($i in 1..10000){
    [System.Environment]
  }
} |select -ExpandProperty TotalSeconds

Write-Host "First measurement took $measure1 seconds, Second measurement took $measure2"

>>First measurement took 0.0482474 seconds, Second measurement took 0.8722697

Tested on:

PSVersion: 5.1.14393.2969
PSEdition: Desktop
PSCompatibleVersions: {1.0, 2.0, 3.0, 4.0...}
BuildVersion:10.0.14393.2969
CLRVersion:4.0.30319.42000
WSManStackVersion:3.0
PSRemotingProtocolVersion:2.3
SerializationVersion:1.1.0.1

Can anyone observe this behavior as well?

Do you have any suggestions to workaround this problem?

Is it related to some settings or installed software?

@fadanner fadanner added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Jun 13, 2019
@bergmeister
Copy link
Contributor

Please fill in the issue template as things like the PS Version are very relevant to this.

@iSazonov
Copy link
Collaborator

/cc @KirkMunro @PaulHigin

@iSazonov iSazonov added the WG-Interactive-Debugging debugging PowerShell script label Jun 14, 2019
@fadanner
Copy link
Author

Added $PSVersionTable to the issue

@bergmeister
Copy link
Contributor

@fadanner This repository is not for Windows PowerShell as the issue template says, I assume the issue does not apply for PowerShell Core?

@KirkMunro
Copy link
Contributor

@fadanner Thank you for explaining the issue you were seeing so clearly. I love it when someone indicates they took the time to isolate the problem, in this case trying with/without the OS updates, using procmon, etc. That is very much appreciated.

As @bergmeister suggested, it would be most helpful to know if this is an issue for PowerShell Core or not. Are you able to try that out on a test server, with PowerShell 6.2 installed? It can be installed side-by-side with PowerShell 5.1.

Also, you suggested that you don't see the slowdown without the OS updates. Using the same PowerShell versions, can you share those times as well to illustrate how much of a difference we're looking at before/after the update, based on your tests?

@nohwnd
Copy link
Contributor

nohwnd commented Jul 25, 2019

@bergmeister @KirkMunro I think we are seeing the same bug in pester/Pester#1318. The impact does not seem to be limited to accessing classes, but instead all code slows down when even a single breakpoint is present.

I can see that the problem impacts both Windows PowerShell 5.1 and PowerShell Core 6.2.2 and have a simple repro and measurements.

I was able to replicate this on Windows 10 Bussiness version 1903 (updated July 2019), straight from MSDN (gwmi win32_operatingsystem -> version 10.0.18362).

I can make more tests in case you need them, to confirm what the problem is, and to try possible solutions.

@iSazonov
Copy link
Collaborator

iSazonov commented Jul 25, 2019

@nohwnd If you have a test environment you could collect traces (before appling the security patch and after) with PerfView utility and share traces - I expect that it will very simple to find the expensive system call.
Update: Perhaps it is more easy to get traces for Windows PowerShell - we can use WPR/WPA from Windows Performance Toolkit

@DavidGibsonNorth
Copy link

Can anyone observe this behavior as well?
@fadanner Yes, replicated by me

First measurement took 0.0102665 seconds, Second measurement took 1.6129433

$PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14393.3053
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.3053
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

.

@nohwnd
Copy link
Contributor

nohwnd commented Jul 25, 2019

@iSazonov I never used PerfView is there anything specific that I should setup / measure. Or just running Collect > Run with Powershell.exe -f repro.ps1 and then sharing the merged logs is enough?

I don't have a version of the vm before patches becasue I was never able to update from a clean station, and so I was able to replicate only on the build that I mention above, that already has the patch installed. But I have a second workstation that does not have the problem, will collecting the same thing on both be useful for you?

@iSazonov
Copy link
Collaborator

@nohwnd We need compare two traces to find regression.

Or just running Collect > Run with Powershell.exe -f repro.ps1

No need start PowerShell every time. You can start PowerShell, prepare test, then start collect by Collect > Collect, run test, after the test done press Stop collection, save zip file and repeat all steps for new test in the same PowerShell session.

@SteveL-MSFT SteveL-MSFT added this to the 7.0-Consider milestone Jul 25, 2019
@iSazonov
Copy link
Collaborator

iSazonov commented Jul 26, 2019

Tracing says a lot:
image

image

@bergmeister
Copy link
Contributor

I suspect this was the fix for CVE-2018-12130, a.k.a. the Zombie Load Attack, that was fixed as part of the May Security update. Details about the specific KB numbers in which it was included can be found here: https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/adv190013
It was mentioned that this fix brings a performance degradation of up to 40%, so I'm not surprised that one can generate more extreme outliers.

@Glober777
Copy link

@SteveL-MSFT, will the fix for the issue be back-ported to Windows PowerShell as is, or should a related record still be created in UserVoice?

@SteveL-MSFT
Copy link
Member

@Glober777 I expect #10269 to be back-ported to 5.1. The root issue of the general perf impact isn't understood yet so can't comment on that.

@SteveL-MSFT SteveL-MSFT added the Resolution-Fixed The issue is fixed. label Dec 10, 2019
@ghost
Copy link

ghost commented Dec 12, 2019

This issue has been marked as fixed and has not had any activity for 1 day. It has been closed for housekeeping purposes.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Fixed The issue is fixed. WG-Interactive-Debugging debugging PowerShell script
Projects
None yet
Development

No branches or pull requests

9 participants