]> git.proxmox.com Git - mirror_frr.git/commit - lib/sigevent.c
lib: make sure SEGV handler cannot lock up
authorDavid Lamparter <equinox@opensourcerouting.org>
Mon, 11 Jan 2016 15:02:49 +0000 (16:02 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 31 Mar 2017 14:22:33 +0000 (16:22 +0200)
commit3f11a103a6ee10cc9ccf2121fce914cb82ef9f80
tree518fa8cb55fa44d9ce4b6a1d3c09c066595c2f96
parent2b5c7fa46d98ea35f6febd5b3da32ca0a2445ca2
lib: make sure SEGV handler cannot lock up

Just adding -pthread to gcc options changes libc's behaviour, e.g.
making malloc() use proper locking.  This means a SEGV inside malloc()
(e.g. because malloc bookkeeping structures have been damaged by writing
to a broken pointer) can lead to a lockup by the following chain:

- random_function()
- malloc()
--- SEGV
- core_handler()
- zlog_backtrace_sigsafe()
- backtrace()
- malloc()

This will hang forever waiting for the malloc() lock to be released.

Another failure mode is dynamic linking with lazy binding (-z lazy,
default).  Since backtrace() is seldomly used, this means the call to
backtrace() in the core handler can in fact result in the dynamic linker
trying to resolve the "backtrace" symbol, which can also deadlock.

Add several safeguards to prevent any of this from happening.

(Unfortunately, these are not theoretical issues - I found them by
running into them headfirst.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/log.c
lib/sigevent.c