[Serdev] Problem accessing object in memory

Andrei Pelinescu-Onciul pelinescu-onciul at fokus.fraunhofer.de
Mon Mar 7 14:09:31 UTC 2005


On Mar 03, 2005 at 17:04, Cesc <cesc.santa at gmail.com> wrote:
> Hi,
> 
> Sorry if the email is messy, but it is just the way my ideas on this
> problem are at the moment :)
> 
> I am working on the TCP code and i am having some problems while
> trying to use an external library (openssl).
> Let's say we have a TLS listener socket, gets an incoming connection,
> and the TCP socket is created (accept) and the wrapping "struct
> tcp_connection *c" (with shm_malloc).
> So, when i try to init the overlay SSL on this socket, i need to
> create an (SSL * ssl), this in function tcpconn_new (tcp_main.c), and
> as i need this for later, i store the "ssl" object in c->extra_data
> (don't know if it was meant for that, but it was an unused void
> pointer ... ).

It was meant exactly for this :-)



> Note that "ssl" is created with openssl's own malloc
> ... that is, if i am not wrong, the "normal" malloc.
> So far so good ... SSL handshake succeeds.
> Now, when later on the receiver child it tries to read from "ssl"
> (tcp_receiver_loop, tcp_read.c), i get an error saying that this
> object is uninitialized. And it is true, it is uninitialized, at least
> from where the child tries to access it (via the tcp_connection *c ->
> extra_data).
> My problem is that there is something wrong with the memory, because
> if you try to read from "ssl" from the same function where it was
> created (tcpconn_new in tcp_main.c), it works!! no problem.
> 
> So, my question is ... what's wrong with the (SSL *) ssl pointer? what
> am i doing wrong? why is it ok in one function, but not accessible
> from another?

The problem is malloc. openssl uses libc malloc by default, which will
alloc normal "private" memory (not shared). This will only work if you
use the ssl connection within one process (which doesn't happen in ser).
You need to make openssl use the shared memory alloc functions
from ser. Write some simple wrappers for them and set the openssl
mallocs with CRYPTO_set_mem_functions(..).



Andrei




More information about the Serdev mailing list