s3: Fix a winbind race leading to 100% CPU
authorVolker Lendecke <vl@samba.org>
Fri, 26 Aug 2011 14:54:18 +0000 (16:54 +0200)
committerKarolin Seeger <kseeger@samba.org>
Fri, 16 Sep 2011 18:42:19 +0000 (20:42 +0200)
commitd11473401c89b810473f191c4c2febb048912a1d
tree015fc095fbbad9ae884005b979e3dd2ec3c4623b
parent6c628b8b1488a9ddce37787fce3ac4a4b1d39431
s3: Fix a winbind race leading to 100% CPU

This fixes a race condition that leads to the winbindd_children list becoming
corrupted. It happens when on a busy winbind SIGCHLD is a bit late.

Imagine a winbind with multiple requests in the queue for a single child. Child
dies, and before the SIGCHLD handler is called we find the socket to be dead.
wb_child_request_done is called, receiving an error from wb_simple_trans_recv.
It closes the socket. Then immediately the wb_child_request_trigger will do
another fork_domain_child before the signal handler is called. This means that
we do another fork_domain_child, we have child->sock==-1 at this point.
fork_domain_child will do a DLIST_ADD(winbindd_children, child) a second time
where the child is already part of that list. This corrupts the list. Then the
signal handler kicks in, spinning in

for (child = winbindd_children; child != NULL; child = child->next) {

forever. Not good. This patch makes sure that both conditions (sock==-1 and not
part of the list) for a winbindd_child struct match up.

Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Fri Aug 26 18:51:24 CEST 2011 on sn-devel-104
(cherry picked from commit ed058f4dc3e059967f3c0538bc220866e9c63588)
(cherry picked from commit b181fe9ec50ff63074b217143b6daa5cddfb8853)
source3/winbindd/winbindd_dual.c