Skip to content
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

director reference counting races #3949

Open
nigoroll opened this issue Jul 3, 2023 · 1 comment
Open

director reference counting races #3949

nigoroll opened this issue Jul 3, 2023 · 1 comment

Comments

@nigoroll
Copy link
Member

nigoroll commented Jul 3, 2023

Expected Behavior

Director reference counting should avoid use-after-frees

Current Behavior

I believe there are still open races with our director reference counting

Simple director assignment

VCL: set bereq.backend = vmod.backend()

this basically translates to: VRT_Assign_Backend(&ctx->bo->director_req, vmod_function())

So what happens when the last reference goes away between the time of vmod_function() returning and VRT_Assign_Backend() referencing it?

Resolve function

VRT_DirectorResolve() does not take/release references. But even if it would, it still left a similar gap as in the previous case, the backend could go away between d->vdir->methods->resolve() looking it up and VRT_DirectorResolve() taking a reference.

(edit: VDI_Http1Pipe() and VDI_GetHdr() call VRT_DirectorResolve() via VDI_Resolve() and they do take references. So the window is larger than for the simple assignment case, but still comparably small)

Possible Solution

#2725 suggested to avoid this and similar problems by putting all to-be-deleted backends onto a cool list, which would be worked when the last request possibly referring any of the to-be-deleted backends went away.
With the current implementation, it would appear to me that any function returning a backend would need to provide the reference with it.

Steps to Reproduce (for bugs)

No response

Context

Staring at nigoroll/libvmod-dynamic#81

Varnish Cache version

No response

Operating system

No response

Source of binary packages used (if any)

No response

@nigoroll nigoroll changed the title director reference counting reaces director reference counting races Jul 3, 2023
@nigoroll
Copy link
Member Author

nigoroll commented Jul 3, 2023

bugwash: we tend towards changing interfaces returning directors to always return with another reference held.
phk said he wanted to work on this.

nigoroll added a commit to nigoroll/libvmod-dynamic that referenced this issue Jul 3, 2023
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

No branches or pull requests

1 participant