By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
Sécurité Helvétique News | AmyrisSécurité Helvétique News | AmyrisSécurité Helvétique News | Amyris
  • Home
  • Compliance
    Compliance
    Show More
    Top News
    McDonald’s Delaware Court Decision Will Change CCO World Forever
    21 February 2023
    Health Equity: Board Directors’ Most Important ESG Measure
    7 May 2023
    News Roundup: 75% of US Companies Mention Climate Risk in 10-Ks
    15 June 2024
    Latest News
    How 2025 Redefined Telemarketing Compliance
    1 December 2025
    Advice for the AI Boom: Use the Tools, Not Too Much, Stay in Charge
    25 November 2025
    Strange Bedfellows: How a Supreme Court Ruling Found Its Perfect Match in the Trump Administration
    19 November 2025
    Where in the Loop? Testing AI Across 120 Compliance Tasks to Find Out Where Humans Are Most Needed
    13 November 2025
  • Cyber Security
    Cyber Security
    Show More
    Top News
    Scandinavian Airlines website hit by cyber attack, customer details exposed
    21 February 2023
    Planet Ice hacked! 240,000 skating fans’ details stolen
    22 February 2023
    North Korea’s APT37 Targeting Southern Counterpart with New M2RAT Malware
    23 February 2023
    Latest News
    North Korean Hackers Target Developers with Malicious npm Packages
    30 August 2024
    Russian Hackers Exploit Safari and Chrome Flaws in High-Profile Cyberattack
    29 August 2024
    Vietnamese Human Rights Group Targeted in Multi-Year Cyberattack by APT32
    29 August 2024
    2.5 Million Reward Offered For Cyber Criminal Linked To Notorious Angler Exploit Kit
    29 August 2024
  • Technology
    Technology
    Show More
    Top News
    Meta Quest’s New Hand-Tracking Update Adds Button Tapping, Maybe Better Typing
    21 February 2023
    Spotify’s new AI-powered DJ builds and commentates on custom playlists
    23 February 2023
    Batteries Are Ukraine’s Secret Weapon Against Russia
    24 February 2023
    Latest News
    Why XSS still matters: MSRC’s perspective on a 25-year-old threat  | MSRC Blog
    9 September 2025
    Microsoft Bug Bounty Program Year in Review: $13.8M in Rewards | MSRC Blog
    28 August 2025
    Microsoft Bounty Program Year in Review: $16.6M in Rewards  | MSRC Blog
    27 August 2025
    postMessaged and Compromised | MSRC Blog
    26 August 2025
  • Businness
    Businness
    Show More
    Top News
    Missing Chinese banker was working to set up Singapore family office
    22 February 2023
    European countries step up delivery of tanks to Ukraine
    23 February 2023
    Borealis Foods to Go Public via Merger with Oxus Acquisition Corp
    24 February 2023
    Latest News
    AI labs like Meta, Deepseek, and Xai earned worst grades possible on an existential safety index
    6 December 2025
    Visa is moving its European headquarters to London’s Canary Wharf, FT reports
    5 December 2025
    Client Challenge
    4 December 2025
    Binance names cofounder Yi He as new co-CEO
    3 December 2025
  • ÉmissionN
    Émission
    Cyber Security Podcasts
    Show More
    Top News
    Stream episode Cybercrime Wire For Feb. 25-26, 2023. Weekend Update. WCYB Digital Radio. by Cybercrime Magazine podcast
    25 February 2023
    Cyberwarfare Report, Week Of Mar. 3, 2023. Theresa Payton Reporting.
    5 March 2023
    Global CISO Report. The Human Side Of Security. Mary Rose Martinez, Marathon Petroleum Corporation.
    14 March 2023
    Latest News
    Stream episode Cybercrime Magazine Update: Cybercrime In India. Sheer Volume Overwhelming Police Forces. by Cybercrime Magazine podcast
    3 March 2025
    Autonomous SOC. Why It’s A Breakthrough For The Mid-Market. Subo Guha, SVP of Product, Stellar Cyber
    2 March 2025
    Cyber Safety. Protecting Families From Smart Toy Risks. Scott Schober, Author, "Hacked Again."
    2 March 2025
    Cybercrime News For Feb. 25, 2025. Hackers Steal $49M from Infini Crypto Fintech. WCYB Digital Radio
    2 March 2025
Search
Cyber Security
  • Application Security
  • Darknet
  • Data Protection
  • network vulnerability
  • Pentesting
Compliance
  • LPD
  • RGPD
  • Finance
  • Medical
Technology
  • AI
  • MICROSOFT
  • VERACODE
  • CHECKMARKX
  • WITHSECURE
  • Amyris
  • Contact
  • Disclaimer
  • Privacy Policy
  • About us
© 2023 Sécurité Helvétique NEWS par Amyris Sarl. Tous droits réservés
Reading: GS cookie protection – effectiveness and limitations | MSRC Blog
Share
Sign In
Notification Show More
Font ResizerAa
Sécurité Helvétique News | AmyrisSécurité Helvétique News | Amyris
Font ResizerAa
  • Home
  • Compliance
  • Cyber Security
  • Technology
  • Business
Search
  • Home
    • Compliance
    • Cyber Security
    • Technology
    • Businness
  • Legal Docs
    • Contact us
    • Disclaimer
    • Privacy Policy
    • About us
Have an existing account? Sign In
Follow US
  • Amyris
  • Contact
  • Disclaimer
  • Privacy Policy
  • About us
© 2023 Sécurité Helvétique par Amyris Sarl.
Sécurité Helvétique News | Amyris > Blog > Application Security > GS cookie protection – effectiveness and limitations | MSRC Blog
Application SecurityBackup and recoveryData securityDevice SecurityMICROSOFTNetwork securitynetwork vulnerabilityTechnology

GS cookie protection – effectiveness and limitations | MSRC Blog

webmaster
Last updated: 2024/02/02 at 1:17 PM
webmaster
Share
9 Min Read
SHARE

The Microsoft C/C++ compiler supports the GS switch which aims to detect stack buffer overruns at runtime and terminate the process, thus in most cases preventing an attacker from gaining control of the vulnerable machine. This post will not go into detail about how GS works, so it may be helpful to refer to these MSDN articles for an overview and loads of detail on how GS works and what a GS cookie is. It’s important to note that depending on the exact vulnerability, even if a function is protected by a GS cookie, a stack-based buffer overrun may still be exploitable – for example if the attacker can gain control prior to the cookie check. However even in these circumstances, GS can often be a significant obstacle to exploitation and/or reliability of exploitation. There have been some stack-based attacks recently that were not mitigated by GS – this post takes a couple of examples and looks at why that was.

This companion post looks at how Visual Studio 2010 improves GS in light of some of the limitations covered in this post.

MS08-067 – netapi32 vulnerability in parsing path name

In MS08-067 (see also associated SDL blog entry), there is a fixed size buffer on the stack and the vulnerability is in the code that parses the path for “\..” substrings, replacing them with the explicit directory name as required. For example \\server\A\B\C\..\D\..\..\E” would be resolved to “\\server\A\E”. The vulnerability lies in the fact that when searching backwards through the path string buffer for a ‘\’ character the pointer returned by this search can sometimes end up being before the start of the path buffer.

Let’s look at how this key fact impacts the effectiveness of GS when data is then copied into memory starting at that address. The call stack looks like:

netapi32!ConvertPathMacros+0x101
netapi32!CanonicalizePathName+0x102

The path string buffer is defined in CanonicalizePathNames and that function is GS-protected. The ConvertPathMacros function is not GS-protected: it takes a pointer to the path buffer defined in CanonicalizePathNames as one of its arguments and has itself no local variables that would lead to it being GS-protected.

The initial stack layout is as below, with the ConvertPathMacros function having a pointer to the pathBuffer variable defined in CanonicalizePathName:

image

Step 1: the search for ‘\’ character causes a pointer to reference address before the start of path buffer.

image

Step 2: attacker-controlled data is then written starting at that address, overwriting ConvertPathMacro’s stack frame data:

image

Step 3: ConvertPathMacro function returns, but its return address has been overwritten so that the attacker gains control. In the diagram above the GS cookie in CanonicalizePathName is not overwritten. Note that it is irrelevant whether the overflow overwrote the GS cookie in CanonicalizePathName or not: this is because the cookie in CanonicalizePathName’s stack frame is only checked when CanonicalizePathName returns. And the attacker gains control long before that, when ConvertPathMacros returns.

This is an example of a stack-based vulnerability and attack that GS is simply not designed to mitigate: GS will only protect against an overflow if:

1. The cookie is overwritten as part of the overflow.

2. The cookie check at function return is reached.

In this example neither of the two criteria above need apply.

MS07-017 – ANI file parsing vulnerability

By way of contrast, compare this with the ANI vulnerability in MS07-017 (see also associated SDL blog entry). The corresponding call stack was:

user32!ReadChunk
user32!LoadAniIcon

ReadChunk was effectively just copying data from the ANI file to a pointer provided by LoadAniIcon. The attacker could not control this pointer so exploiting MS07-017 could not be achieved by overwriting ReadChunk’s stack frame as in the previous case. However the LoadAniIcon function where the buffer vulnerable to overflow was defined was not GS-protected at all! So a traditional overflow targeting LoadAniIcon’s return address was feasible.

image

The ANIHEADER local variable overflowed in the ANI vulnerability was a pure data structure:

typedef struct _ANIHEADER {
DWORD cbSizeof;
DWORD cFrames;
DWORD cSteps;
DWORD cx, cy;
DWORD cBitCount, cPlanes;
DWORD jifRate;
DWORD fl; } ANIHEADER, *PANIHEADER;

The compiler uses a heuristic to decide which functions to GS-protect, and this is targeted mainly at protecting against string buffer overflows. As LoadAniIcon contained no such string buffers then it was not GS-protected.

Unlike the previous example then, the ANI vulnerability could in principle have been mitigated by GS, if GS were applied more extensively; eg if LoadAniIcon had been GS-protected then the picture would have looked like:

image

The overflow would have overwritten the GS cookie and when LoadAniIcon returned then the GS cookie check would have detected the overflow and terminated the process. As noted at the start, depending on the exact control flow in LoadAniIcon between the overflow and the cookie check at function exit it may still be possible to exploit this; however GS has removed the generic method of exploitation making any exploit harder to develop and (experience tells us) often far less reliable.

It turns out that there is a way of instructing the compiler to be more aggressive in what functions it GS-protects via a pragma: #pragma strict_gs_check (blogged about here by Mike Howard). In fact partly as a result of this ANI vulnerability, MSEC worked with product teams in Windows to apply the strict GS pragma to a number of parser components as part of Windows Vista Service Pack 1.

Summary

GS is designed to mitigate a specific class of stack-based attacks, making stack-based exploits harder to develop, less reliable, and in some cases reducing what would have been attacker code execution to a denial-of-service. For example at the time of writing, we do not know of an exploit for MS06-040 on Windows XP SP2+ or Windows Server 2003 SP1 platforms. The SDL requires all Microsoft products to be built with GS enabled. Many third-party products use GS too – including recent versions of Quicktime, Adobe Acrobat, and Flash for example.

Where the attacker has more fine-grained control of where to start the overflow, or the direction of an overflow/underflow then the GS mitigation won’t help. In some cases however GS would help if present, and its absence is purely related to the default heuristics that the compiler uses. For high-risk code – code that handles untrusted data for example – consider making use of the strict_gs_check pragma.

Looking ahead I’m also excited at the prospect of “Enhanced GS” – what’s “Enhanced GS”? Well, it’s a whole other article: check back here over the next couple of days and read all about it!

And of course there is no substitute for the code being secure in the first place!

– Tim Burrell, MSEC Security Science

Links to related articles

/GS (Buffer Security Check), MSDN Visual C++ compiler options entry

Compiler Security Checks in Depth, MSDN Visual Studio Technical Articles, Brandon Bray, February 2002

MS08-067 and the SDL, SDL blog entry, Michael Howard, October 2008

Lessons learned from the Animated Cursor Security Bug, SDL blog entry, Michael Howard , April 2007

Hardening stack-based buffer overrun detection in VC2005 SP1, Michael Howard’s blog, April 2007

#pragma strict_gs_check , MSDN C/C++ pre-processor reference.

You Might Also Like

Ways to Tell if a Website Is Fake

Introducing OpenAI for Australia

OpenAI to acquire Neptune

Accelerating innovation with AWS: Snyk selected as an AWS Pattern Partner

Security Advisory: Critical RCE Vulnerabilities in React Server Components & Next.js

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.

By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Reddit Telegram Email Copy Link Print
Share
Previous Article 왕초보 HTML – 04.Heading & Paragraph
Next Article Integrating Insights from Recorded Future to Revolutionize Cloud Security
Leave a comment Leave a comment

Comments (0) Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

235.3k Followers Like
69.1k Followers Follow
11.6k Followers Pin
56.4k Followers Follow
136k Subscribers Subscribe
4.4k Followers Follow
- Advertisement -
Ad imageAd image

Latest News

From Prompt Injection To Account Takeover · Embrace The Red
Pentesting 6 December 2025
From Prompt Injection To Account Takeover · Embrace The Red
Pentesting 6 December 2025
Ways to Tell if a Website Is Fake
network vulnerability 6 December 2025
From Prompt Injection To Account Takeover · Embrace The Red
Pentesting 6 December 2025
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
Sécurité Helvétique News | AmyrisSécurité Helvétique News | Amyris
Follow US
© 2023 Sécurité Helvétique NEWS par Amyris Sarl. Tous droits réservés
Amyris news letter
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

Loading
Zero spam, Unsubscribe at any time.
login Amyris SH
Welcome Back!

Sign in to your account

Lost your password?