-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix weak-ref by-value function parameter UAF #2677
Conversation
Could someone help checking why ci failed. Maybe the error not related to this change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the CI failure seems to stem from a change in the compiler diagnostics; UI tests are generally brittle because of this. Someone ought to take the top of master
, run the UI tests with the override setting enabled, so as to update the error message expectations, and submit a PR with those changes, so that you can afterwards rebase and fix that.
Regarding this PR, as the author of the one that fixed the self
case (sorry I did not notice it occurred for non self
values as well), the changes LGTM ✅
Thanks for this! Can you add some tests specifically for this bug as well? |
According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry, the time when FinalizationRegistry cleanup logic triggered is unpredictable. So I think it's hard to add test logic into CI, because your can't await GC happens. For reference I create a repo simply for reproducing this bug and test the above fix: https://github.com/mikialex/wasm-bindgen-reproduce-2677 |
Could the test you mentioned get added to this test suite? Even if it's not deterministically exercising the bug it's better than nothing I think. |
946c0cf
to
fd14455
Compare
I'm trying to add some test but have some issues when figuring out how to run test suite on my machine. Accroding to this https://rustwasm.github.io/docs/wasm-bindgen/contributing/testing.html#wasm-tests-on-node-and-headless-browsers and this https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/browsers.html#appendix-testing-in-headless-browsers-without-wasm-pack, I tried
so, did I miss something important? I assum this will execute the tests in tests folder. |
I'd recommend running the |
Work around a bug [1] in wasm-bindgen when passing structs by-value into methods, by passing `wasm_api::Tensor`s by-reference. In order to do this without copying the underlying tensor, make `wasm_api::Tensor` use an Rc to manage its output reference. Alternative solutions would be to fix the issue in wasm-bindgen upstream or to patch generated JS code snippets like this: ``` var ptr0 = someArg.ptr; somePtr.ptr = 0; ``` To be like this instead: ``` var ptr0 = someArg.__destroy_into_raw(); ``` [1] rustwasm/wasm-bindgen#2677
Am I correct in thinking that this issue is fixed by 4458587 ? |
Yes, I think so. |
The #2447 not considered the by-value function parameter case. This MR try fix that.
All
xxx.ptr = 0;
will now called by__destroy_into_raw
and unregister the finalizer.