Mailing List Archive

new libgcrypt
I just ported gnutls to the 1.1.42 version of libgcrypt.
It seems that it gets a segmentation fault at:

Program received signal SIGSEGV, Segmentation fault.
_gcry_module_release (module=0x0) at module.c:156
156 if (! --module->counter)

The part of code involved was not affected by the changes
for the new libgcrypt, so I suspect that other things changed
internally in the sexp stuff. The whole backtrace is:

#0 _gcry_module_release (module=0x0) at module.c:156
#1 0x400c7660 in sexp_to_enc (sexp=0x807ce48, retarray=0x400fb6c0,
retalgo=0x400fb6c0, ret_modern=0xbfffeff8, ret_want_pkcs1=0xbfffeffc,
flags=0x400fb6c0) at pubkey.c:1017
#2 0x400c87a3 in gcry_pk_decrypt (r_plain=0xbffff040, s_data=0x807ce48,
s_skey=0x807d368) at pubkey.c:1439
#3 0x40038d8b in _gnutls_pk_decrypt (algo=1, resarr=0xbffff084,
data=0x807afa0, pkey=0x807c148, pkey_len=6) at gnutls_pk.c:616
[...]

--
Nikos Mavroyanopoulos
Re: new libgcrypt [ In reply to ]
On Wed, 6 Aug 2003 22:10:29 +0300, Nikos Mavroyanopoulos said:

> Program received signal SIGSEGV, Segmentation fault.
> _gcry_module_release (module=0x0) at module.c:156

Fixed in CVS:

diff -u -r1.6 -r1.7
--- src/module.c 14 Jul 2003 22:33:41 -0000 1.6
+++ src/module.c 7 Aug 2003 06:20:53 -0000 1.7
@@ -149,11 +149,12 @@
}

/* Release a module. In case the use-counter reaches zero, destroy
- the module. */
+ the module. Passing MODULE as NULL is a dummy operation (similar
+ to free()). */
void
_gcry_module_release (gcry_module_t module)
{
- if (! --module->counter)
+ if (module && ! --module->counter)
_gcry_module_drop (module);
}


It happens in the error handling part of some code. In general it is
a good idea to allow release functions to take a NULL argument to make
cleanup after errors easier.

Thanks,

Werner


--
Werner Koch <wk@gnupg.org>
The GnuPG Experts http://g10code.com
Free Software Foundation Europe http://fsfeurope.org
Re: new libgcrypt [ In reply to ]
On Thu, Aug 07, 2003 at 08:28:02AM +0200, Werner Koch wrote:

> > Program received signal SIGSEGV, Segmentation fault.
> > _gcry_module_release (module=0x0) at module.c:156
> Fixed in CVS:
[...]
> /* Release a module. In case the use-counter reaches zero, destroy
> - the module. */
> + the module. Passing MODULE as NULL is a dummy operation (similar
> + to free()). */
> void
> _gcry_module_release (gcry_module_t module)
> {
> - if (! --module->counter)
> + if (module && ! --module->counter)
> _gcry_module_drop (module);
> }
> It happens in the error handling part of some code. In general it is
> a good idea to allow release functions to take a NULL argument to make
> cleanup after errors easier.

This fixes the segmentation fault, but the RSA decryption is not
done correctly so gnutls no longer works. The strange thing is that
no gcrypt function returns an error code.

> Thanks,
> Werner
>
> --
> Werner Koch <wk@gnupg.org>
> The GnuPG Experts http://g10code.com
> Free Software Foundation Europe http://fsfeurope.org

--
Nikos Mavroyanopoulos
Re: new libgcrypt [ In reply to ]
Nikos Mavroyanopoulos <nmav@gnutls.org> writes:

> This fixes the segmentation fault, but the RSA decryption is not
> done correctly so gnutls no longer works.

Could you provide the S-Expressions that did not work - or maybe even
a small test program that triggers the bug?

Thanks,
moritz
--
((gpg-key-id . "6F984199")
(email . "moritz@duesseldorf.ccc.de")
(webpage . "http://duesseldorf.ccc.de/~moritz/"))
Re: new libgcrypt [ In reply to ]
On Thu, 7 Aug 2003 14:24:10 +0300, Nikos Mavroyanopoulos said:

> This fixes the segmentation fault, but the RSA decryption is not
> done correctly so gnutls no longer works. The strange thing is that
> no gcrypt function returns an error code.

FWIW, I have ported GnuPG (1.9) to Libgcrypt and it works without any
hassles. The problem Simon reported yesterdat was entirely a error in
the glue code of GnuPG.

--
Werner Koch <wk@gnupg.org>
The GnuPG Experts http://g10code.com
Free Software Foundation Europe http://fsfeurope.org
Re: new libgcrypt [ In reply to ]
On Thu, Aug 07, 2003 at 01:45:42PM +0200, Moritz Schulte wrote:

> > This fixes the segmentation fault, but the RSA decryption is not
> > done correctly so gnutls no longer works.
> Could you provide the S-Expressions that did not work - or maybe even
> a small test program that triggers the bug?

The code that fails is:

static
int _gnutls_pk_decrypt(int algo, GNUTLS_MPI * resarr, GNUTLS_MPI data, GNUTLS_MPI * pkey, int pkey_len)
{
gcry_sexp_t s_plain, s_data, s_pkey;
int rc=-1;

/* make a sexp from pkey */
switch (algo) {
case GCRY_PK_RSA:
if (pkey_len >=6)
rc = gcry_sexp_build(&s_pkey, NULL,
"(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))",
pkey[0], pkey[1], pkey[2], pkey[3], pkey[4], pkey[5]);

break;

default:
gnutls_assert();
return GNUTLS_E_INTERNAL_ERROR;
}

if (rc != 0) {
gnutls_assert();
return GNUTLS_E_INTERNAL_ERROR;
}

/* put the data into a simple list */
if (gcry_sexp_build(&s_data, NULL, "(enc-val(rsa(a%m)))", data)) {
gnutls_assert();
gcry_sexp_release(s_pkey);
return GNUTLS_E_INTERNAL_ERROR;
}

/* pass it to libgcrypt */
rc = gcry_pk_decrypt(&s_plain, s_data, s_pkey);
gcry_sexp_release(s_data);
gcry_sexp_release(s_pkey);

---->Here the strerror on rc shows: "Missing item in object"
if (rc != 0) {
gnutls_assert();
return GNUTLS_E_PK_ENCRYPTION_FAILED;

} else { /* add better error handling or make gnupg use S-Exp directly */
resarr[0] = gcry_sexp_nth_mpi(s_plain, 0, 0);

if (resarr[0] == NULL) {
gnutls_assert();
gcry_sexp_release(s_plain);
return GNUTLS_E_INTERNAL_ERROR;
}
}

gcry_sexp_release(s_plain);
return rc;
}



> Thanks,
> moritz
> --
> ((gpg-key-id . "6F984199")
> (email . "moritz@duesseldorf.ccc.de")
> (webpage . "http://duesseldorf.ccc.de/~moritz/"))

--
Nikos Mavroyanopoulos
Re: new libgcrypt [ In reply to ]
Thanks for triggering this bug, I just commited a fix into CVS. As a
work-around, use an S-Expression like "(enc-val(flags)(rsa(a%m)))"
instead of "(enc-val(rsa(a%m)))".

moritz
--
((gpg-key-id . "6F984199")
(email . "moritz@duesseldorf.ccc.de")
(webpage . "http://duesseldorf.ccc.de/~moritz/"))
Re: new libgcrypt [ In reply to ]
On Fri, Aug 08, 2003 at 12:36:58AM +0200, Moritz Schulte wrote:

> Thanks for triggering this bug, I just commited a fix into CVS. As a
It might also be a good idea to make the configure script to
fail if libgpg-error is not present, since compilation fails anyway.


> moritz
> --
> ((gpg-key-id . "6F984199")
> (email . "moritz@duesseldorf.ccc.de")
> (webpage . "http://duesseldorf.ccc.de/~moritz/"))

--
Nikos Mavroyanopoulos
Re: new libgcrypt [ In reply to ]
Nikos Mavroyanopoulos <nmav@gnutls.org> writes:

> It might also be a good idea to make the configure script to fail if
> libgpg-error is not present, since compilation fails anyway.

I commited that change few days ago.

moritz
--
((gpg-key-id . "6F984199")
(email . "moritz@duesseldorf.ccc.de")
(webpage . "http://duesseldorf.ccc.de/~moritz/"))
Re: new libgcrypt [ In reply to ]
On Fri, 8 Aug 2003 20:58:52 +0300, Nikos Mavroyanopoulos said:

> It might also be a good idea to make the configure script to
> fail if libgpg-error is not present, since compilation fails anyway.

We will do so.

--
Werner Koch <wk@gnupg.org>
The GnuPG Experts http://g10code.com
Free Software Foundation Europe http://fsfeurope.org