Re: double free in digest-md5

Philipp Gesang <[email protected]> Wed, 17 Apr 2019 10:01:31 +0200
Newsgroups gmane.comp.security.cyrus.sasl
Message-ID <[email protected]>
Hi Simo,

-<| Quoting Simo Sorce <[email protected]>, on Tuesday, 2019-04-16 10:23:37 AM |>-
> I created PR #562 which should handle this issue, would be nice if you
> could try it out and confirm it resolve the crashes for you.

tried it against 2.1.27 and mutt is no longer crashing.

Thank you for the quick fix!
Philipp

> On Tue, 2019-04-16 at 09:03 +0200, Philipp Gesang wrote:
> > Hi,
> > 
> > this is an issue I originally raised on the mutt-users list [0]
> > where it was suggested that I seek assistance here. The MUA
> > crashes when sending email over a digest-md5 authenticated
> > connection. This happens in a call to sasl_dispose() that
> > indirectly frees some handle that had been freed earlier while
> > authenticating.
> > 
> > Backtraces:
> > 
> > --8<-- free 1 ----------------------------------------------->8--
> > 
> > #0  free_rc4 (text=text@entry=0x21d3460) at digestmd5.c:1227
> > #1  0x00007f1fa8416b92 in make_client_response (text=text@entry=0x21d3460, 
> >     params=params@entry=0x21d3200, oparams=oparams@entry=0x21d18f0) at digestmd5.c:3613
> > #2  0x00007f1fa8417039 in digestmd5_client_mech_step2 (oparams=<optimized out>, 
> >     clientoutlen=<optimized out>, clientout=<optimized out>, prompt_need=<optimized out>, 
> >     serverinlen=<optimized out>, serverin=<optimized out>, params=0x21d3200, 
> >     ctext=<optimized out>) at digestmd5.c:4364
> > #3  digestmd5_client_mech_step (conn_context=<optimized out>, params=0x21d3200, 
> >     serverin=<optimized out>, serverinlen=<optimized out>, prompt_need=<optimized out>, 
> >     clientout=<optimized out>, clientoutlen=<optimized out>, oparams=<optimized out>)
> >     at digestmd5.c:4558
> > #4  0x00007f1fa7e6a471 in sasl_client_step (conn=0x21d1080, serverin=<optimized out>, 
> >     serverinlen=<optimized out>, prompt_need=prompt_need@entry=0x7fffc8656330, 
> >     clientout=clientout@entry=0x7fffc8656340, clientoutlen=clientoutlen@entry=0x7fffc865631c)
> >     at client.c:922
> > #5  0x0000000000492c05 in smtp_auth_sasl (conn=conn@entry=0x210f810, mechlist=<optimized out>)
> >     at smtp.c:635
> > #6  0x000000000049339d in smtp_auth (conn=0x210f810) at smtp.c:549
> > #7  smtp_open (conn=0x210f810) at smtp.c:503
> > #8  mutt_smtp_send (from=0x210ce70, to=0x210c890, cc=0x0, bcc=0x0, 
> >     msgfile=msgfile@entry=0x7fffc8657570 "/tmp/mutt-drift-2428-105237-294724449650828126", 
> >     eightbit=1) at smtp.c:311
> > #9  0x0000000000464a45 in send_message (msg=<optimized out>, msg=<optimized out>) at send.c:1030
> > #10 ci_send_message (flags=<optimized out>, flags@entry=0, msg=<optimized out>, msg@entry=0x0, 
> >     tempfile=tempfile@entry=0x0, ctx=0x1f44270, cur=<optimized out>, cur@entry=0x0) at send.c:1936
> > #11 0x000000000042201e in mutt_index_menu () at curs_main.c:2161
> > #12 0x0000000000409253 in main (argc=1, argv=0x7fffc865abe8, environ=<optimized out>)
> >     at main.c:1274
> > 
> > --8<-- free 2 ----------------------------------------------->8--
> > 
> > #0  free_rc4 (text=0x21d3460) at digestmd5.c:1227
> > #1  0x00007f1fa8413420 in digestmd5_common_mech_dispose (conn_context=0x21d3460, utils=0x21d32d0)
> >     at digestmd5.c:1610
> > #2  0x00007f1fa7e696f8 in client_dispose (pconn=0x21d1080) at client.c:337
> > #3  0x00007f1fa7e6c414 in sasl_dispose (pconn=0x21693a0) at common.c:849
> > #4  0x00000000004987c0 in mutt_sasl_conn_close (conn=0x210f810) at mutt_sasl.c:496
> > #5  0x00000000004952a3 in mutt_socket_close (conn=conn@entry=0x210f810) at mutt_socket.c:85
> > #6  0x000000000049395a in mutt_smtp_send (from=<optimized out>, to=0x210c890, cc=0x0, bcc=0x0, 
> >     msgfile=msgfile@entry=0x7fffc8657570 "/tmp/mutt-drift-2428-105237-294724449650828126", 
> >     eightbit=<optimized out>) at smtp.c:357
> > #7  0x0000000000464a45 in send_message (msg=<optimized out>, msg=<optimized out>) at send.c:1030
> > #8  ci_send_message (flags=<optimized out>, flags@entry=0, msg=<optimized out>, msg@entry=0x0, 
> >     tempfile=tempfile@entry=0x0, ctx=0x1f44270, cur=<optimized out>, cur@entry=0x0) at send.c:1936
> > #9  0x000000000042201e in mutt_index_menu () at curs_main.c:2161
> > #10 0x0000000000409253 in main (argc=1, argv=0x7fffc865abe8, environ=<optimized out>)
> >     at main.c:1274
> > 
> > --8<--------------------------------------------------------->8--
> > 
> > AFAICT mutt’s smtp client code follows the steps layed out in
> > sample/client.c. Is there a precaution to be taken by the caller
> > of sasl_client_step() and sasl_dispose() to guard against
> > accidentally triggering free_rc4() twice?
> > 
> > I’ve tested both 2.1.26 and 2.1.27, the issue is present in both.
> > FWIW the client authenticates against a postfix built against
> > cyrus-sasl 2.1.23. Let me know if you need more information.
> > 
> > Thanks,
> > Philipp
> > 
> > [0] http://lists.mutt.org/pipermail/mutt-users/Week-of-Mon-20190415/000824.html
> > 
> 
> -- 
> Simo Sorce
> Sr. Principal Software Engineer
> Red Hat, Inc
> 
>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEc8fuSIDXOZ07wD2Q8S2brBeKCUwFAly23VgACgkQ8S2brBeK
CUxm8Q//b5gX7AGSk1+dxZsKyXs99k/3UTtCfCZFEopKgOyZOxLliRUoPK73d49w
v2DwBk1USg+RvuswbTxMcaw1/yfLN8+ZIH12LUgDs7CwavjAqQOM9GEZSmYDjGcP
xmWnv+TDAOUN5V5eTtxsUdz+Z7x04BYJ52EF5clburfg/pdA2mrN9UIGycChjBNl
RD5Oxl/LUTHC45hSOBrOLM+UuZMR+CK7FwkJg6jRywxTkh9lu6X2jJq9JJ7Oa2Au
/sTEXh7cxs362o4u5OUg1xkfYB1bGHxkK+MMiPwMNDyz24hVhBocNy9dh1q+/fq2
y9CYBAETuTYszBaHB4gWje1/ZqeIpF/+iT9wJkEbT+OyMifW3orkBbd3knwFyC8P
gdyVTQmu5PdION1qkvaN+Cn8Fm+C8I+Td/SFAbzA+413JBmyNTUT0uyesMxxQPxs
ItivJow6Q8ODS2tf3Y4pdO+eepexoHU7LZQLMq20nCiJOhZK9vNWFMMeQRV9t/xE
K1si3SgRCWLSu5pWIyAtErpQ8OgNnBl6Y4kLpw8VAV32hdK5/WP53wHyRTk+8D9a
rQdJrH03yFQAyW3sCzNP6JoHDo08x8EY4f/6Ue6CHS4ommJGWtAlh/llQnQNawzn
pEyna3JOeEu2Q3+GAk05FrjSKGhWxVd085AysRK5MjzWZS7qxbY=
=wfU4
-----END PGP SIGNATURE-----