microsoft / DevSkim

DevSkim is a set of IDE plugins, language analyzers, and rules that provide security "linting" capabilities.
MIT License
910 stars 116 forks source link

DevSkim entering infinite loop in wild causing Visual Studio responsiveness issues #580

Closed davkean closed 1 year ago

davkean commented 1 year ago

Describe the bug Visual Studio CPU telemetry has caught an issue in the wild where DevSkimFixMessageTarget is entering an infinite loop due to overlapped reads and writes to a HashSet. This is described in this article:https://frugalcafe.beehiiv.com/p/selfinflicted-dos-attack-dictionary-corruption. The specified lambda argument for the updateValueFactory parameter to AddOrUpdate can overlap on multiple threads at the same time, causing curruption to the hashset.

At the time we caught this, the lambda in CodeFixMappingEventAsync was consuming 3 CPU cores for over 6 minutes, but would never have broken out of the loop.

Replace the HashSet with an immutable structure such as ImmutableHashSet.

To Reproduce There is no repro, this was caught by automatic CPU tracing, akin to Watson crash reporting.

Expected behavior Don't overlap read/writes to a HashSet

Versions(please complete the following information):

gfs commented 1 year ago

Thanks for the report. I have a PR open that will switch the backing store to concurrent dictionary.

davkean commented 1 year ago

@gfs Thanks!