Skip to content

Commit

Permalink
mcount: Fix recursion during fork()
Browse files Browse the repository at this point in the history
In the atfork_child_handler() it renews the shmem buffer.  But if the
application implements some functions used by dealing with shmem buffer
- notably malloc and free - it'll recurse to libmcount with NULL rstack.

This was found by Honggyu when tracing the chrome browser.  (Fixes #42)

Reported-by: Honggyu Kim <hong.gyu.kim@lge.com>
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Dec 29, 2016
1 parent 6ea9500 commit 8eb2330
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libmcount/mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,17 @@ static void atfork_child_handler(void)
assert(mtdp);
}

mtd.tid = 0;
/* flush tid cache */
mtdp->tid = 0;

clear_shmem_buffer(&mtd);
prepare_shmem_buffer(&mtd);
mtdp->recursion_guard = true;

clear_shmem_buffer(mtdp);
prepare_shmem_buffer(mtdp);

ftrace_send_message(FTRACE_MSG_FORK_END, &tmsg, sizeof(tmsg));

mtdp->recursion_guard = false;
}

static void build_debug_domain(char *dbg_domain_str)
Expand Down

0 comments on commit 8eb2330

Please sign in to comment.