GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Some more changes and cleanup to reduce the startup time by daxian-dbw · Pull Request #8396 · PowerShell/PowerShell

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Dec 4, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR Summary

This PR includes some changes and cleanups that will reduce the startup time. Each commit is self-contained, and the commit message serves as a summary of the changes in the commit.

  • Rename s_wasSystemPolicyDebugPolicy to s_allowDebugOverridePolicy to make it less confusing. Also slightly refactor HelperSecurity.psm1 and ConstrainedLanguageDebugger.Tests.ps1 to remove unneeded code. There is no functional change in this commit.
  • Remove the unneeded static property IsInbox, as PowerShell Core won't be shipped in-box with Windows in the foreseeable feature. Even if we do in future, we won't be needing it because Windows PowerShell will probably be gone by that time.
    • This static property was hit at startup time when constructing the value for $env:PSModulePath, and it will in turn cause IsNanoServer and IsIoT to be evaluated, all of which will trigger access to the Registry. By removing IsInbox, that can be all avoided.
  • Update 'BindRunspace' to avoid getting all commands and unneeded method calls.
    • BindRunspace retrieves all available commands from the session state, but for the most common scenario of creating/opening a Runspace, the retrieved commands are never get used afterwards. The method is updated to avoid retrieving all commands unless it's necessary.
    • The method is also updated to add check before calling into a ProcessXXX method, so that we can avoid some unneeded method calls.
  • Avoid creating a IsSafeValueVisitor every time when IsScriptBlockInFactASafeHashtable runs.
    • The static method IsSafeValueVisitor.IsAstSafe creates an instance of IsSafeValueVisitor every time it runs. Given that IsScriptBlockInFactASafeHashtable gets called relatively frequently in PerformSecurityCheck, this will result in some GC pressure as it will generate transient objects. This is updated to reuse a IsSafeValueVisitor singleton with the default SafeValueContext.
    • The Default and _safeValueContext fields are made readonly, so it cannot be changed by reflection.
    • The _visitCount is changed to uint type, so an attacker cannot change the value of it to a negative number in order to practically increase the max visit count limit.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Documentation needed
      • Issue filed - Issue link:
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Dongbo Wang (daxian-dbw) added 3 commits December 4, 2018 11:56
@daxian-dbw
Rename 's_wasSystemPolicyDebugPolicy' to make it less confusing and s…
ad51846
…implify 'HelperSecurity.psm1'
@daxian-dbw
Remove the unneeded 'IsInbox' to avoid running 'IsNanoServer' and 'Is…
3613372
…IoT' at startup time
@daxian-dbw
Update 'BindRunspace' to avoid getting all commands and unneeded meth…
f7bae06
…od calls
@daxian-dbw
Dongbo Wang (daxian-dbw) requested review from Paul Higinbotham (PaulHigin), Travis Plunk (TravisEz13), Aditya Patwardhan (adityapatwardhan) and Ilya (iSazonov) December 4, 2018 21:50
@daxian-dbw
Dongbo Wang (daxian-dbw) requested review from Bruce Payette (BrucePay) and Andrew (anmenaga) as code owners December 4, 2018 21:50
@daxian-dbw
[Feature] Avoid creating a 'IsSafeValueVisitor' every time when 'IsSc…
d32458e
…riptBlockInFactASafeHashtable' runs
@daxian-dbw
Dongbo Wang (daxian-dbw) force-pushed the debugsyspolicy branch from 9f718e0 to d32458e Compare December 4, 2018 21:52
@daxian-dbw Dongbo Wang (daxian-dbw) self-assigned this Dec 4, 2018
@iSazonov

Ilya (iSazonov) commented Dec 5, 2018

Copy link
Copy Markdown
Collaborator

The _visitCount is changed to uint type, so an attacker cannot change the value of it to a negative number in order to practically increase the max visit count limit.

Currently runtime has Unsafe.As method and similar others. Can these methods be used to change the value with reflection?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) approved these changes Dec 5, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/InitialSessionState.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin
Paul Higinbotham (PaulHigin) suggested changes Dec 5, 2018
View reviewed changes
Comment thread src/System.Management.Automation/security/wldpNativeMethods.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin
Paul Higinbotham (PaulHigin) suggested changes Dec 5, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/InitialSessionState.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
[Feature] Rename the overload methods 'ProcessImportModule' and updat…
a2625b5
…e comment
PaulHigin
Paul Higinbotham (PaulHigin) approved these changes Dec 5, 2018
View reviewed changes

@PaulHigin Paul Higinbotham (PaulHigin) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Dec 6, 2018

Copy link
Copy Markdown
Member Author

Currently runtime has Unsafe.As method and similar others. Can these methods be used to change the value with reflection?

Ilya (@iSazonov) I don't think uint field can be set with a negative value by reflection.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit c1e1716 into PowerShell:master Dec 6, 2018
@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the debugsyspolicy branch December 6, 2018 02:29
@daxian-dbw Dongbo Wang (daxian-dbw) added CL-Engine Indicates that a PR should be marked as an engine change in the Change Log CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log and removed CL-Engine Indicates that a PR should be marked as an engine change in the Change Log labels Dec 6, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@daxian-dbw
More changes and cleanup to reduce the startup time (PowerShell#8396)
d0192e6
Major changes are:
- Rename `s_wasSystemPolicyDebugPolicy` to `s_allowDebugOverridePolicy` to make it less confusing. Also slightly refactor `HelperSecurity.psm1` and `ConstrainedLanguageDebugger.Tests.ps1` to remove unneeded code. There is no functional change in this commit.
- Remove the unneeded static property `IsInbox`, as PowerShell Core won't be shipped in-box with Windows in the foreseeable feature. Even if we do in future, we won't be needing it because Windows PowerShell will probably be gone by that time.
- Update 'BindRunspace' to avoid getting all commands and unneeded method calls.
- Avoid creating a `IsSafeValueVisitor` every time when `IsScriptBlockInFactASafeHashtable` runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov approved these changes
@TravisEz13 Travis Plunk (TravisEz13) Awaiting requested review from TravisEz13 TravisEz13 is a code owner
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) Awaiting requested review from adityapatwardhan
@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
+1 more reviewer
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@daxian-dbw @iSazonov @PaulHigin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.