nss_winbind is not thread safe, any suggestions to fix this?
jra at samba.org
Thu Sep 20 11:25:55 GMT 2007
On Thu, Sep 20, 2007 at 06:59:49PM +0800, boyang wrote:
> Hi, all:
> libnss_winbind is not thread safe, the following steps and result
> can explain it.
> To reproduce it:
> write some junk code and tune the process time of winbindd:
> Two threads are used in reproduce it.
> 1. at second 0, call getpwnam_r
> 2. at second 1, call getgrgid_r
> 3. at second 2, winbindd daemon process GETPWNAM request, ie, sleep(1) after
> receive GETPWNAM request
> 4. at second 3, thread getgrgid_r become active again after sleep(2), and
> try to read the result(it is actually the result of getpwnam_r)
> 5. at second 4, winbindd deamon process GETGRGID request, ie sleep(3)after
> GETGRGID request
> 6. at second 5, thread getpwnam_r become active again after sleep(5), and try
> read the result(actually the result of getgrgid_r)
> I have enlarged the time ticks to explain the race condition situation.
> Generally speaking, the response of the two request in corresponding thread can
> be messed. request 1 get the response of request2 and request2 get the response
> of request1.
Yes, if we export a _r function we must ensure it's thread-safe, even
if we merely add a 'global' mutex around the call.
More information about the samba-technical