FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-108253: Fix bug in func version cache by gvanrossum · Pull Request #108296 · python/cpython · GitHub

Repository navigation

gh-108253: Fix bug in func version cache - #108296

Merged
gvanrossum merged 1 commit into
python:mainfrom
gvanrossum:fix-func-cache
Aug 22, 2023
Merged

gvanrossum merged 1 commit into
python:mainfrom
gvanrossum:fix-func-cache

Conversation

Copy link
Copy Markdown
Member

When a function object changed its version, a stale pointer might remain in the cache.

Now, test_opcache just fails when run with -Xuops instead of accessing freed memory. This fixes gh-108253.

When a function object changed its version, a stale pointer
might remain in the cache.

alex commented Aug 23, 2023

Copy link
Copy Markdown
Member

This PR introduces a use of uninitialized memory.

  • A new PyFunctionObject is allocated here
  • And then here _PyFunction_SetVersion is called
  • Which reads from ->func_version here
  • However, ->func_version was never initialized

This was detected by OSS-Fuzz: https://oss-fuzz.com/testcase-detail/5086904889245696

Copy link
Copy Markdown
Member Author

This PR introduces a use of uninitialized memory.

Interesting, since it also definitely fixed a case of free-after-use. I will try to understand the report.

Copy link
Copy Markdown
Member Author

Ah, I was over-zealous. That is the one place where ...->func_version = 0 is correct instead of going through the call. :-( PR coming up.

alex commented Aug 23, 2023

Copy link
Copy Markdown
Member

Thanks!

Copy link
Copy Markdown
Member Author

This is a great service! Surprised though that address-sanitizer didn't catch this.

alex commented Aug 23, 2023

Copy link
Copy Markdown
Member

ASAN doesn't catch unitialized memory, only MSAN does. (And MSAN is kind of a pain in the neck to setup.)

Copy link
Copy Markdown

This PR introduces a use of uninitialized memory.

  • A new PyFunctionObject is allocated here
  • And then here _PyFunction_SetVersion is called
  • Which reads from ->func_version here
  • However, ->func_version was never initialized

This was detected by OSS-Fuzz: https://oss-fuzz.com/testcase-detail/5086904889245696

Dear Alex @alex ,

Could you please give me an access to this issue? I am a security Ph.D. student, and I am analyzing some issues to summarize some patterns. I would be very grateful if you could help me.

Best regards,
Zeyang (zeyangzhuang0315@gmail.com, or zyzhuang22@cse.cuhk.edu.hk)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

heap-use-after-free in _PyFunction_LookupByVersion

4 participants


Back | FazBrowse Home | New Git URL