You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Bert Huijben <be...@qqmail.nl> on 2011/09/08 10:37:59 UTC

RE: svn commit: r1166555 - /subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c


> -----Original Message-----
> From: stsp@apache.org [mailto:stsp@apache.org]
> Sent: donderdag 8 september 2011 10:05
> To: commits@subversion.apache.org
> Subject: svn commit: r1166555 -
> /subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c
> 
> Author: stsp
> Date: Thu Sep  8 08:05:00 2011
> New Revision: 1166555
> 
> URL: http://svn.apache.org/viewvc?rev=1166555&view=rev
> Log:
> Fix a possible crash in ra_svn if SASL authentication is active.
> 
> * subversion/libsvn_ra_svn/cyrus_auth.c
>   (svn_ra_svn__do_cyrus_auth): Give the auth callbacks sufficient
>    lifetime to survive until connection pool cleanup. CyrusSASL
>    needs the callbacks in the cleanup handler of this pool.
> 
> Found by: Dave Huang <kh...@azeotrope.org>
> 
> Modified:
>     subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c
> 
> Modified: subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c
> URL:
> http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_svn/c
> yrus_auth.c?rev=1166555&r1=1166554&r2=1166555&view=diff
> ==========================================================
> ====================
> --- subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c (original)
> +++ subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c Thu Sep  8
> 08:05:00 2011
> @@ -738,9 +738,7 @@ svn_ra_svn__do_cyrus_auth(svn_ra_svn__se
>    const char *mechstring = "", *last_err = "", *realmstring;
>    const char *local_addrport = NULL, *remote_addrport = NULL;
>    svn_boolean_t success;
> -  /* Reserve space for 3 callbacks (for the username, password and the
> -     array terminator). */
> -  sasl_callback_t callbacks[3];
> +  sasl_callback_t *callbacks;
>    cred_baton_t cred_baton;
>    int i;
> 
> @@ -776,6 +774,10 @@ svn_ra_svn__do_cyrus_auth(svn_ra_svn__se
>    cred_baton.realmstring = realmstring;
>    cred_baton.pool = pool;
> 
> +  /* Reserve space for 3 callbacks (for the username, password and the
> +     array terminator). */
> +  callbacks = apr_palloc(sess->conn->pool, sizeof(*callbacks) * 3);
> +
>    /* Initialize the callbacks array. */

This isn't going to help when the baton that is passed (by pointer) to the callbacks is also allocated on the stack.
(The baton should probably move to heap as well if this is the right fix)

The function seems to assume that this callback infrastructure isn't used after returning from svn_ra_svn__do_cyrus_auth(), which would make allocating on the stack safe. 
Any idea why this worked for years in 1.6 but now starts failing?

	Bert


Re: svn commit: r1166555 - /subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c

Posted by Stefan Sperling <st...@elego.de>.
On Thu, Sep 08, 2011 at 04:37:00PM +0200, Stefan Sperling wrote:
> On Thu, Sep 08, 2011 at 05:20:20PM +0300, Daniel Shahaf wrote:
> > Semi-related question: how does this fix interact with this part of
> > svnserve's main():
> > 
> >       /* Use a subpool for the connection to ensure that if SASL is used
> >        * the pool cleanup handlers that call sasl_dispose() (connection_pool)
> >        * and sasl_done() (pool) are run in the right order. See issue #3664. */
> >       connection_pool = svn_pool_create(pool);
> >       conn = svn_ra_svn_create_conn2(NULL, in_file, out_file,
> >                                      params.compression_level,
> >                                      connection_pool);
> >       svn_error_clear(serve(conn, &params, connection_pool));
> >       exit(0);
> > 
> > ?
> > 
> > Both are SASL pool lifetime issues.  Is the above hunk still needed
> > after the change below?
> 
> Quite likely still needed.

Also, note that the above fix was server-side, while the new fix
is on the client side :)

Re: svn commit: r1166555 - /subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c

Posted by Stefan Sperling <st...@elego.de>.
On Thu, Sep 08, 2011 at 05:20:20PM +0300, Daniel Shahaf wrote:
> Semi-related question: how does this fix interact with this part of
> svnserve's main():
> 
>       /* Use a subpool for the connection to ensure that if SASL is used
>        * the pool cleanup handlers that call sasl_dispose() (connection_pool)
>        * and sasl_done() (pool) are run in the right order. See issue #3664. */
>       connection_pool = svn_pool_create(pool);
>       conn = svn_ra_svn_create_conn2(NULL, in_file, out_file,
>                                      params.compression_level,
>                                      connection_pool);
>       svn_error_clear(serve(conn, &params, connection_pool));
>       exit(0);
> 
> ?
> 
> Both are SASL pool lifetime issues.  Is the above hunk still needed
> after the change below?

Quite likely still needed.
The above was a crash that happened at exit(0) time, and only when svnserve
was run in inetd mode. I don't know how the reporters of the new bug are
running svnserve, but I would guess that it's a different bug.
In any case, even if this was now redundant, there is no harm in
keeping this as it is.

Re: svn commit: r1166555 - /subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c

Posted by Daniel Shahaf <da...@elego.de>.
Semi-related question: how does this fix interact with this part of
svnserve's main():

      /* Use a subpool for the connection to ensure that if SASL is used
       * the pool cleanup handlers that call sasl_dispose() (connection_pool)
       * and sasl_done() (pool) are run in the right order. See issue #3664. */
      connection_pool = svn_pool_create(pool);
      conn = svn_ra_svn_create_conn2(NULL, in_file, out_file,
                                     params.compression_level,
                                     connection_pool);
      svn_error_clear(serve(conn, &params, connection_pool));
      exit(0);

?

Both are SASL pool lifetime issues.  Is the above hunk still needed
after the change below?

Philip Martin wrote on Thu, Sep 08, 2011 at 11:20:00 +0100:
> "Bert Huijben" <be...@qqmail.nl> writes:
> 
> >> --- subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c (original)
> >> +++ subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c Thu Sep  8
> >> 08:05:00 2011
> >> @@ -738,9 +738,7 @@ svn_ra_svn__do_cyrus_auth(svn_ra_svn__se
> >>    const char *mechstring = "", *last_err = "", *realmstring;
> >>    const char *local_addrport = NULL, *remote_addrport = NULL;
> >>    svn_boolean_t success;
> >> -  /* Reserve space for 3 callbacks (for the username, password and the
> >> -     array terminator). */
> >> -  sasl_callback_t callbacks[3];
> >> +  sasl_callback_t *callbacks;
> >>    cred_baton_t cred_baton;
> >>    int i;
> >> 
> >> @@ -776,6 +774,10 @@ svn_ra_svn__do_cyrus_auth(svn_ra_svn__se
> >>    cred_baton.realmstring = realmstring;
> >>    cred_baton.pool = pool;
> >> 
> >> +  /* Reserve space for 3 callbacks (for the username, password and the
> >> +     array terminator). */
> >> +  callbacks = apr_palloc(sess->conn->pool, sizeof(*callbacks) * 3);
> >> +
> >>    /* Initialize the callbacks array. */
> >
> > This isn't going to help when the baton that is passed (by pointer) to
> > the callbacks is also allocated on the stack.  (The baton should
> > probably move to heap as well if this is the right fix)
> 
> In practice it doesn't matter, see below.  We should probably change it
> or add a comment.
> 
> > The function seems to assume that this callback infrastructure isn't
> > used after returning from svn_ra_svn__do_cyrus_auth(), which would
> > make allocating on the stack safe.
> >
> > Any idea why this worked for years in 1.6 but now starts failing?
> 
> The original bug report explained it.  During pool cleanup we call the
> SASL function sasl_dispose and that looks at the callback structs.  The
> stack struct has random values and if the id member makes it look like
> the logging callback it gets invoked.  Most callbacks won't get invoked
> at that stage so only particular values will cause a problem.  Also
> since the auth callback won't get invoked it explains why the baton on
> the stack works.
> 
> -- 
> uberSVN: Apache Subversion Made Easy
> http://www.uberSVN.com

Re: svn commit: r1166555 - /subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c

Posted by Philip Martin <ph...@wandisco.com>.
"Bert Huijben" <be...@qqmail.nl> writes:

>> --- subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c (original)
>> +++ subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c Thu Sep  8
>> 08:05:00 2011
>> @@ -738,9 +738,7 @@ svn_ra_svn__do_cyrus_auth(svn_ra_svn__se
>>    const char *mechstring = "", *last_err = "", *realmstring;
>>    const char *local_addrport = NULL, *remote_addrport = NULL;
>>    svn_boolean_t success;
>> -  /* Reserve space for 3 callbacks (for the username, password and the
>> -     array terminator). */
>> -  sasl_callback_t callbacks[3];
>> +  sasl_callback_t *callbacks;
>>    cred_baton_t cred_baton;
>>    int i;
>> 
>> @@ -776,6 +774,10 @@ svn_ra_svn__do_cyrus_auth(svn_ra_svn__se
>>    cred_baton.realmstring = realmstring;
>>    cred_baton.pool = pool;
>> 
>> +  /* Reserve space for 3 callbacks (for the username, password and the
>> +     array terminator). */
>> +  callbacks = apr_palloc(sess->conn->pool, sizeof(*callbacks) * 3);
>> +
>>    /* Initialize the callbacks array. */
>
> This isn't going to help when the baton that is passed (by pointer) to
> the callbacks is also allocated on the stack.  (The baton should
> probably move to heap as well if this is the right fix)

In practice it doesn't matter, see below.  We should probably change it
or add a comment.

> The function seems to assume that this callback infrastructure isn't
> used after returning from svn_ra_svn__do_cyrus_auth(), which would
> make allocating on the stack safe.
>
> Any idea why this worked for years in 1.6 but now starts failing?

The original bug report explained it.  During pool cleanup we call the
SASL function sasl_dispose and that looks at the callback structs.  The
stack struct has random values and if the id member makes it look like
the logging callback it gets invoked.  Most callbacks won't get invoked
at that stage so only particular values will cause a problem.  Also
since the auth callback won't get invoked it explains why the baton on
the stack works.

-- 
uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com