Skip to content

IIS: fix ReadFileChunk latent overflow (allocate m_dwPageSize, not 1) - #3624

Open
A13501350 wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
A13501350:fix/iis-readfilechunk-buffer
Open

IIS: fix ReadFileChunk latent overflow (allocate m_dwPageSize, not 1)#3624
A13501350 wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
A13501350:fix/iis-readfilechunk-buffer

Conversation

@A13501350

Copy link
Copy Markdown

Summary

Fixes a latent buffer overflow in ReadFileChunk (IIS module).

The I/O scratch buffer was allocated with VirtualAlloc(NULL, 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE), yet ReadFile writes m_dwPageSize bytes into it (iis/mymodule.cpp:304, :339). It only worked by accident: VirtualAlloc rounds the allocation size up to a full page, and the returned address is page-aligned — so requesting 1 byte commits exactly one page, which happens to equal m_dwPageSize. If m_dwPageSize ever differed from the system page size, ReadFile would write past the committed region (access violation).

Fixes

Closes #3623

Changed location

  • iis/mymodule.cpp:305 — allocate the real size: VirtualAlloc(NULL, m_dwPageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)

The page-aligned address still satisfies the file I/O alignment requirements already used in the function, and the committed size now matches the ReadFile length. VirtualFree(pIoBuffer, 0, MEM_RELEASE) cleanup is unchanged.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cbd28e70-132c-4da4-8988-faf99f0f3900

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a latent buffer overflow risk in the IIS module’s CMyHttpModule::ReadFileChunk by allocating an I/O scratch buffer sized to the actual read length (m_dwPageSize) rather than relying on VirtualAlloc’s page-rounding behavior.

Changes:

  • Update VirtualAlloc call to allocate m_dwPageSize bytes instead of 1, matching the ReadFile(..., m_dwPageSize, ...) usage.
  • Keep existing cleanup behavior (VirtualFree(..., MEM_RELEASE)) unchanged.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@airween

airween commented Aug 27, 2026

Copy link
Copy Markdown
Member

This PR looks good to me - I'll approve and merge it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants