[PATCH] Improve talloc security

Andrew Bartlett abartlet at samba.org
Tue Feb 24 00:52:03 MST 2015

On Tue, 2015-02-24 at 08:39 +0100, Andreas Schneider wrote:
> On Monday 23 February 2015 17:30:19 Jeremy Allison wrote:
> > I think if we want to do this we need to bite the bullet
> > and add in the pthread_mutex_t guards around the global
> > variables and make talloc fully MT-safe.
> In libssh we have the same issue. During initialization we need to lock 
> correctly, specially if we initialize the crypto libraries!

Is this with library constructors, and if so, is that because the
program may already be using the crypto libs?

I'm just trying to understand how two init() calls, or an init call and
a talloc call, can happen at the same time, and so what access to the
static local variables I would be serialising.

> We came up with a solution for that:
> ssh_threads_set_callbacks(ssh_threads_get_noop());
> ssh_init();
> ssh_threads_noop is the threading structure that does nothing. It's the 
> threading callbacks being used by default when you're not using threading. The 
> first line is not needed. ssh_init() does it if the threading callbacks are 
> not set yet.
> If you use phtreads you can do:
> ssh_threads_set_callbacks(ssh_threads_get_pthread());
> ssh_init();
> http://git.libssh.org/projects/libssh.git/tree/src/threads/pthread.c
> This makes it also possible to implement threading with Windows threads by the 
> user for example ...

This all looks good for the NULL context issues, but given we have no
library init function so far, would you use this for our talloc_magic,
and if so, how?


Andrew Bartlett

Andrew Bartlett                       http://samba.org/~abartlet/
Authentication Developer, Samba Team  http://samba.org
Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba

More information about the samba-technical mailing list