fix(dynamic): handle PID/TID reuse in address identity#2933
fix(dynamic): handle PID/TID reuse in address identity#2933Vib3ss wants to merge 3 commits intomandiant:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the robustness of dynamic analysis by addressing the challenge of PID/TID reuse. It introduces optional lifecycle identifiers to process and thread addresses, ensuring that each instance is uniquely identifiable throughout its existence. This enhancement prevents data loss and aggregation issues that previously occurred when the operating system recycled process or thread identifiers. The changes are integrated across the address definition, data extraction, serialization, and rendering components, maintaining backward compatibility and including new tests to verify the fix. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed
There was a problem hiding this comment.
Code Review
This pull request effectively addresses PID/TID reuse by introducing optional lifecycle IDs to ProcessAddress and ThreadAddress. The changes are well-integrated across feature extraction, serialization (freeze), and rendering, ensuring backward compatibility. The addition of regression tests is also a great inclusion. I have a couple of suggestions to improve consistency in logging and output formatting.
| seq: dict[int, int] = {} | ||
| for tid in threads: | ||
| seq[tid] = seq.get(tid, 0) + 1 | ||
| thread_id = seq[tid] - 1 if counts[tid] > 1 else None | ||
|
|
||
| address: ThreadAddress = ThreadAddress(process=ph.address, tid=tid, id=thread_id) | ||
| yield ThreadHandle(address=address, inner={}) |
There was a problem hiding this comment.
This function handles TID reuse by assigning a lifecycle ID, which is great. However, unlike the corresponding get_processes function which warns about PID/PPID reuse, there's no warning here for TID reuse. For consistency and better diagnostics, consider adding a warning when a TID is reused within a process.
seq: dict[int, int] = {}
warned_tids: set[int] = set()
for tid in threads:
if counts[tid] > 1 and tid not in warned_tids:
logger.warning("TID reuse detected for tid %d in process %s", tid, ph.address)
warned_tids.add(tid)
seq[tid] = seq.get(tid, 0) + 1
thread_id = seq[tid] - 1 if counts[tid] > 1 else None
address: ThreadAddress = ThreadAddress(process=ph.address, tid=tid, id=thread_id)
yield ThreadHandle(address=address, inner={})| if len(address.value) == 2: | ||
| ppid, pid = address.value | ||
| assert isinstance(ppid, int) | ||
| assert isinstance(pid, int) | ||
| return f"process{{pid:{pid}}}" | ||
| ppid, pid, process_id = address.value | ||
| assert isinstance(ppid, int) | ||
| assert isinstance(pid, int) | ||
| assert isinstance(process_id, int) | ||
| if process_id >= 0: | ||
| return f"process{{pid:{pid},id:{process_id}}}" | ||
| return f"process{{pid:{pid}}}" | ||
| elif address.type == frz.AddressType.THREAD: | ||
| assert isinstance(address.value, tuple) | ||
| ppid, pid, tid = address.value | ||
| if len(address.value) == 3: | ||
| ppid, pid, tid = address.value | ||
| assert isinstance(ppid, int) | ||
| assert isinstance(pid, int) | ||
| assert isinstance(tid, int) | ||
| return f"process{{pid:{pid},tid:{tid}}}" | ||
| ppid, pid, tid, process_id, thread_id = address.value | ||
| assert isinstance(ppid, int) | ||
| assert isinstance(pid, int) | ||
| assert isinstance(tid, int) | ||
| return f"process{{pid:{pid},tid:{tid}}}" | ||
| assert isinstance(process_id, int) | ||
| assert isinstance(thread_id, int) | ||
| s = f"process{{pid:{pid},tid:{tid}" | ||
| if process_id >= 0: | ||
| s += f",pid_id:{process_id}" | ||
| if thread_id >= 0: | ||
| s += f",id:{thread_id}" | ||
| return s + "}" | ||
| elif address.type == frz.AddressType.CALL: | ||
| assert isinstance(address.value, tuple) | ||
| ppid, pid, tid, id_ = address.value | ||
| return f"process{{pid:{pid},tid:{tid},call:{id_}}}" | ||
| if len(address.value) == 4: | ||
| ppid, pid, tid, id_ = address.value | ||
| return f"process{{pid:{pid},tid:{tid},call:{id_}}}" | ||
| ppid, pid, tid, id_, process_id, thread_id = address.value | ||
| s = f"process{{pid:{pid},tid:{tid}" | ||
| if process_id >= 0: | ||
| s += f",pid_id:{process_id}" | ||
| if thread_id >= 0: | ||
| s += f",id:{thread_id}" | ||
| return s + f",call:{id_}}}" |
There was a problem hiding this comment.
The keys used for formatting process and thread lifecycle IDs are inconsistent and can be ambiguous.
- For
PROCESSaddresses, the process lifecycle ID is keyed asid. - For
THREADandCALLaddresses, the process lifecycle ID is keyed aspid_id, while the thread lifecycle ID is keyed asid.
This is inconsistent (id vs pid_id for the same concept) and ambiguous (id can mean process or thread lifecycle ID depending on context).
To improve clarity and consistency, I suggest using p_id for the process lifecycle ID and t_id for the thread lifecycle ID across all address types.
if len(address.value) == 2:
ppid, pid = address.value
assert isinstance(ppid, int)
assert isinstance(pid, int)
return f"process{{pid:{pid}}}"
ppid, pid, process_id = address.value
assert isinstance(ppid, int)
assert isinstance(pid, int)
assert isinstance(process_id, int)
if process_id >= 0:
return f"process{{pid:{pid},p_id:{process_id}}}"
return f"process{{pid:{pid}}}"
elif address.type == frz.AddressType.THREAD:
assert isinstance(address.value, tuple)
if len(address.value) == 3:
ppid, pid, tid = address.value
assert isinstance(ppid, int)
assert isinstance(pid, int)
assert isinstance(tid, int)
return f"process{{pid:{pid},tid:{tid}}}"
ppid, pid, tid, process_id, thread_id = address.value
assert isinstance(ppid, int)
assert isinstance(pid, int)
assert isinstance(tid, int)
assert isinstance(process_id, int)
assert isinstance(thread_id, int)
s = f"process{{pid:{pid},tid:{tid}"
if process_id >= 0:
s += f",p_id:{process_id}"
if thread_id >= 0:
s += f",t_id:{thread_id}"
return s + "}"
elif address.type == frz.AddressType.CALL:
assert isinstance(address.value, tuple)
if len(address.value) == 4:
ppid, pid, tid, id_ = address.value
return f"process{{pid:{pid},tid:{tid},call:{id_}}}"
ppid, pid, tid, id_, process_id, thread_id = address.value
s = f"process{{pid:{pid},tid:{tid}"
if process_id >= 0:
s += f",p_id:{process_id}"
if thread_id >= 0:
s += f",t_id:{thread_id}"
return s + f",call:{id_}}}"CHANGELOG updated or no update needed, thanks! 😄
|
dup of #2882 |
Implemented a fix for #2619 by preventing PID/TID reuse collisions in dynamic analysis.
Process/thread identities now support optional lifecycle IDs, and dynamic layout aggregation no longer drops matched calls when a thread address is reused.
The change is backward-compatible across freeze/proto/render address handling and includes new regression tests (6 passed) plus related dynamic/proto/render tests (50 passed).
Closes #2619