GoogleChromeLabs / chromeos_smart_card_connector

Smart Card Connector App for Chrome OS
https://chrome.google.com/webstore/detail/smart-card-connector/khpfeaanjngmcnplbdlpegiifgpfgdco
Apache License 2.0
134 stars 49 forks source link

[libusb] Fix use-after-free on transfer race cond #1083

Closed emaxx-google closed 1 year ago

emaxx-google commented 1 year ago

Fix a rare race condition in the Libusb transfer handling code, which was leading to a use-after-free in some scenarios: this fixes #1065. Technically, the fix is "don't dereference a transfer struct after executing its callback".

The underlying root cause is that while one thread calls the transfer's callback, the other thread might already notice it and, if it's waiting for that particular transfer, destroy it. So by the time the first thread reaches the next line (the read from "transfer->flags"), the pointer can be a dangling one.

The commit doesn't add new tests, because it seems that the existing tests are sufficient for catching these kinds of bugs, even with a low probability.

github-actions[bot] commented 1 year ago

Continuous Integration: All tests passed. C/C++ test coverage: 72.35% lines.

github-actions[bot] commented 1 year ago

Continuous Integration: All tests passed. C/C++ test coverage: 72.35% lines.