-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libexpr: Fix use-after-free of StaticEnv::up #12544
base: master
Are you sure you want to change the base?
Conversation
This may fix the crash part of #12527 but does it fix the performance? |
I was focused on fixing the correctness and getting rid of memory crimes. Performance will definitely not improve with this one patch. At the very least it should not regress because refcount increments are way cheaper than allocating a new shared_ptr. |
It's not very clear what the ownership model is here, but one thing is certain: `.up` can't be destroyed before the StaticEnv that refers to it is. Changing a non-owning pointer to taking shared ownership of the parent `StaticEnv` prevents the `.up` from being freed. I'm not a huge fan of the inverted ownership, where child `StaticEnv` takes a refcount of the parent, but this seems like the least intrusive way to fix the use-after-free. This shouldn't cause any shared_ptr cycles to appear (hopefully).
This is the simplest reproducer I have. It would be great to find a repro without flakes, but I guess this should be ok for now.
0a4b6e5
to
0d50045
Compare
Prior to 21071bf |
But wouldn't that have lead to an access to a still invalid I stepped through the debugger trying to pinpoint why the ASAN log here #12527 (comment) shows where the lifetime started and ended, but that doesn't really help understand why |
@xokdvium pointed me to the PR description of #5416
|
From #5416:
@edolstra My best guess for why the Sharing ownership of the parent |
Motivation
#12527
#11286
Context
I'm not very familiar with the ownership model here, so there might be some footguns with this solution. Please take a look at my reasoning in the commit message.
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.