-
Notifications
You must be signed in to change notification settings - Fork 878
fix heap-use-after-free when upstream response stops unexpectly #1534
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
Conversation
|
Hello @zlm2012 thanks for taking a look at this. I have two questions regarding the PR as it currently stands:
|
|
Thanks for replying. I just happened to get to know this issue then tried to fix it. So for the first question, it could be. There's just no evidence now. For the second question, it could. I will investigate this issue more thoroughly then update this PR. |
|
After some investigation, heep use after free only happens when |
4c616f2 to
92a5a43
Compare
|
Thank you for the changes. So now we fix the issue in http1.c instead of the original approach that fixed the issue in the caller. Generally speaking I prefer doing things synchronously, but I have no objection for fixing this particular issue this way. That said, I do not think that libuv allows passing a zero-length array of buffers to So I think that we need to make changes to our libuv binding to address the issue. |
Of course doing things synchronously is much more clear & straightforward. IMHO heap use after free could also be triggered somewhere like https://github.com/h2o/h2o/blob/master/lib/handler/file.c#L204 (though highly unlikely go there) mainly during error handling. I'm not sure if there're more points like that. So maybe current approach is more suitable according to logic simplicity of handlers but not so good for maintainance? I'm not sure.
Or maybe we could change |
|
@zlm2012 Thank you for pointing out another scary piece of code. I am now totally convinced that we should fix the issue in the protocol handler (or the event loop).
I believe that that is the way to go. Can we use the I do not think that modifying the libuv binding to handle zero-element write is a good idea. OTOH I would prefer noticing such mistake being made also when evloop is being used. How about adding an assertion in |
|
Suggestions applied. |
|
Thank you for the changes. The code looks good to me. |
|
Note: this has been a long-standing bug but became a real issue when #1358 got merged. |
t/50unexpected-upstream-body.twould trigger an AddressSanitizer heap-use-after-free error though the test still passes. It is caused byhttp1.cwhere memory pool is released when last chunck of data is sent, but we still do some check onstruct rp_generator_twhich is already freed. This PR fix the problem by switching the order of the check mentioned above anddo_send.