Skip to content

Commit 11bb87b

Browse files
committed
Record robust futex changes before we send SIGKILL in case the SIGKILL destroys the threadgroup without sending a proper PTRACE_EVENT_EXIT
1 parent a1b782d commit 11bb87b

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/RecordSession.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ static void record_robust_futex_change(
7373
*/
7474
template <typename Arch>
7575
static void record_robust_futex_changes_arch(RecordTask* t) {
76+
if (t->did_record_robust_futex_changes) {
77+
return;
78+
}
79+
t->did_record_robust_futex_changes = true;
80+
7681
auto head_ptr = t->robust_list().cast<typename Arch::robust_list_head>();
7782
if (head_ptr.is_null()) {
7883
return;
@@ -488,6 +493,13 @@ bool RecordSession::handle_ptrace_event(RecordTask** t_ptr,
488493
case SECCOMP_RET_KILL:
489494
LOG(debug) << " seccomp kill for syscall: "
490495
<< syscall_name(syscallno, t->arch());
496+
for (Task* tt : t->thread_group()->task_set()) {
497+
// Record robust futex changes now in case the taskgroup dies
498+
// synchronously without a regular PTRACE_EVENT_EXIT (as seems
499+
// to happen on Ubuntu 4.2.0-42-generic)
500+
RecordTask* rt = static_cast<RecordTask*>(tt);
501+
record_robust_futex_changes(rt);
502+
}
491503
t->tgkill(SIGKILL);
492504
step_state->continue_type = RecordSession::CONTINUE;
493505
break;

src/RecordTask.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ RecordTask::RecordTask(RecordSession& session, pid_t _tid, uint32_t serial,
190190
break_at_syscallbuf_traced_syscalls(false),
191191
break_at_syscallbuf_untraced_syscalls(false),
192192
break_at_syscallbuf_final_instruction(false),
193-
next_pmc_interrupt_is_for_user(false) {
193+
next_pmc_interrupt_is_for_user(false),
194+
did_record_robust_futex_changes(false) {
194195
push_event(Event::sentinel());
195196
if (session.tasks().empty()) {
196197
// Initial tracee. It inherited its state from this process, so set it up.

src/RecordTask.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ class RecordTask : public Task {
669669
// The pmc is programmed to interrupt at a value requested by the tracee, not
670670
// by rr.
671671
bool next_pmc_interrupt_is_for_user;
672+
673+
bool did_record_robust_futex_changes;
672674
};
673675

674676
} // namespace rr

0 commit comments

Comments
 (0)