Fix a race condition in winbind leading to a panic
authorVolker Lendecke <vl@samba.org>
Sun, 24 May 2009 16:57:13 +0000 (18:57 +0200)
committerKarolin Seeger <kseeger@samba.org>
Wed, 10 Jun 2009 14:17:55 +0000 (16:17 +0200)
commit8c1bc861a8482694935042e69449e02cc0ab4b25
treef366de1da0e714e8083c976420c8eaea037f9d7f
parent6ac88a21c006ea2754debaf75c41d3fb9d074d6c
Fix a race condition in winbind leading to a panic

In winbind, we do multiple events in one select round. This needs fixing, but
as long as we're still using it, for efficiency reasons we need to do that.

What can happen is the following: We have outgoing data pending for a client,
thus

state->fd_event.flags == EVENT_FD_WRITE

Now a new client comes in, we go through the list of clients to find an idle
one. The detection for idle clients in remove_idle_client does not take the
pending data into account. We close the socket that has pending outgoing data,
the accept(2) one syscall later gives us the same socket.

In new_connection(), we do a setup_async_read, setting up a read fde. The
select from before however had found the socket (that we had already closed!!)
to be writable. In rw_callback we only want to see a readable flag, and we
panic in the SMB_ASSERT(flags == EVENT_FD_READ).

Found using

bin/smbtorture //127.0.0.1/tmp -U% -N 500 -o 2 local-wbclient

Volker

(commit 68c5c6df in master)
(cherry picked from commit c9df9c68da21610d9c32a57e24f45d36ebe432c5)
source/winbindd/winbindd.c