Bug 31807 - td_ta_thr_iter() doesn't allow loop detection
Summary: td_ta_thr_iter() doesn't allow loop detection
Status: RESOLVED WORKSFORME
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-27 14:51 UTC by Jeremy Davies
Modified: 2024-05-28 19:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Davies 2024-05-27 14:51:06 UTC
As reported in https://sourceware.org/bugzilla/show_bug.cgi?id=31003, GDB uses td_ta_thr_iter() to iterate threads found in a core file, but is encountering circular linkage that means td_ta_thr_iter() never terminates.

td_ta_thr_iter() doesn't implement loop detection itself, and it appears that it doesn't allow the callback function to return a value indicating that it has detected a loop.

Perhaps a callback return code can be added that allows the callback to indicate this condition, and which causes td_ta_thr_iter() to halt iteration and indicate same to its caller.
Comment 1 Andreas Schwab 2024-05-27 15:08:12 UTC
If the callback returns non-zero the function returns with TD_DBERR.
Comment 2 Jeremy Davies 2024-05-28 07:07:34 UTC
Exactly.

I'm proposing that if the callback returns 'loop detected' the function returns a specific 'loop detected' error code so that the caller can react accordingly.
Comment 3 Andreas Schwab 2024-05-28 08:15:30 UTC
What's wrong with the existing TD_DBERR?
Comment 4 Jeremy Davies 2024-05-28 08:42:27 UTC
Because TD_DBERR doesn't distinguish the fact that iteration terminated because a loop was detected, as opposed to some other kind of error.

In fact, is there any reason for td_ta_thr_iter() not to return the exact error code returned by the callback?
Comment 5 Andreas Schwab 2024-05-28 08:49:41 UTC
The callback can record the fact locally before returning.
Comment 6 Jeremy Davies 2024-05-28 09:06:00 UTC
I guess that's fair enough.
Feel free to close.
Comment 7 Florian Weimer 2024-05-28 19:12:47 UTC
Per comment 6.