Repository navigation
fix: snapshot scan waiting-list head under the list lock #460
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
Open
fabioesposito
wants to merge
1
commit into
h2zero:master
Choose a base branch
from
fabioesposito:pr/scan-waiting-list-race
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Keep device lifetime valid while
srTimerCb()uses the captured device.The snapshot covers only the head pointer and its timestamp. After
srTimerCb()releases the critical section, it still usespDev. Ifstop()runs at that point withm_maxResults == 0,clearResults()can delete the same device fromm_scanResults.m_deviceVec. The callback then reads and writes freed memory inremoveWaitingDevice(pDev),onResult(pDev), orerase(pDev).stop()does not wait for a runningsrTimerCb(), andclearWaitingList()only stops a pending callout. Neither call closes this window. The fix must guarantee that the device stays valid for the whole callback, or that the callback does not use the device after the list lock is released. Choose the ownership or synchronization approach that fits the scan result lifetime model. Keep the timeout behavior unchanged.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.
Verified against the current code: the hazard is real but pre-existing and unchanged by this PR — every use of
pDevafter the head read (removeWaitingDevice,m_callbackSent,onResult,erase) is byte-identical to before; this change only moves the head read under the list lock to fix the observed null-deref crash (LoadProhibitedat 0xc inresetWaitingTimer).Making the captured device survive concurrent deletion is a separate bug class (use-after-free, not null-deref) and cannot be fixed minimally here: devices are raw pointers owned by
m_scanResults.m_deviceVec, and the same borrowed-pointer pattern exists inhandleGapEventand botheraseoverloads. A correct fix needs shared ownership or a results-wide lock spanning the app callbacks — an architectural change to the scan-results lifetime model, which I'd rather track as its own issue/PR than bundle into this crash fix.Note the existing guards narrow the window:
clearResults()refuses whileisScanning(), andstop()only clears results whenm_maxResults == 0(default0xFF), so exposure requires a non-default configuration plus a cross-task stop with the callout already queued. The application where the crash was observed uses the default and never callserase/clearResults.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.
Analysis chain
Script executed:
Length of output: 3136
@fabioespositoArr, you’re right: the device-lifetime hazard predates this PR. The diff changes the head and timestamp snapshots, not the later uses ofpDev.I withdraw my request to fix the lifetime hazard in this PR. It remains a separate issue, so I’m not marking the finding as addressed.
You are interacting with an AI system.