Conditional jump or move depends on uninitialised value(s)
Closed, ResolvedPublic

Description

On calling gcry_pk_genkey() valgrind reports uninitialized values:

gcry_pk_genkey(..., [elg])
==1860== Conditional jump or move depends on uninitialised value(s)
==1860==    at 0x4AF69C4: jent_stuck (jitterentropy-base.c:314)
==1860==    by 0x4AF6FD7: jent_entropy_init (jitterentropy-base.c:694)
==1860==    by 0x4AF7218: _gcry_rndjent_poll (rndjent.c:278)
==1860==    by 0x4AF7D52: _gcry_rndlinux_gather_random (rndlinux.c:203)
==1860==    by 0x4AF21AF: read_random_source (random-csprng.c:1279)
==1860==    by 0x4AF2FC5: read_pool (random-csprng.c:976)
==1860==    by 0x4AF2FC5: _gcry_rngcsprng_randomize (random-csprng.c:538)
==1860==    by 0x4AF1E3F: _gcry_random_bytes_secure (random.c:405)
==1860==    by 0x4AC4866: generate (elgamal.c:345)
==1860==    by 0x4AC4866: elg_generate (elgamal.c:718)
==1860==    by 0x4A4AAEC: _gcry_pk_genkey (pubkey.c:578)
==1860==    by 0x4A36B9F: gcry_pk_genkey (visibility.c:1029)
==1860==    by 0x40749A: main (t-rfc4880.cc:175)
==1860== 
==1860== Conditional jump or move depends on uninitialised value(s)
==1860==    at 0x4AF69CB: jent_stuck (jitterentropy-base.c:314)
==1860==    by 0x4AF6FD7: jent_entropy_init (jitterentropy-base.c:694)
==1860==    by 0x4AF7218: _gcry_rndjent_poll (rndjent.c:278)
==1860==    by 0x4AF7D52: _gcry_rndlinux_gather_random (rndlinux.c:203)
==1860==    by 0x4AF21AF: read_random_source (random-csprng.c:1279)
==1860==    by 0x4AF2FC5: read_pool (random-csprng.c:976)
==1860==    by 0x4AF2FC5: _gcry_rngcsprng_randomize (random-csprng.c:538)
==1860==    by 0x4AF1E3F: _gcry_random_bytes_secure (random.c:405)
==1860==    by 0x4AC4866: generate (elgamal.c:345)
==1860==    by 0x4AC4866: elg_generate (elgamal.c:718)
==1860==    by 0x4A4AAEC: _gcry_pk_genkey (pubkey.c:578)
==1860==    by 0x4A36B9F: gcry_pk_genkey (visibility.c:1029)
==1860==    by 0x40749A: main (t-rfc4880.cc:175)
==1860== 
[...]

The corresponding code fragment from jitterentropy-base.c looks like:

	int64_t delta2 = ec->last_delta - current_delta;
	int64_t delta3 = delta2 - ec->last_delta2;

	ec->last_delta = current_delta;
	ec->last_delta2 = delta2;

        if (!current_delta || !delta2 || !delta3)
		return 1;

Do you have any idea on this issue? Maybe the structure ec (type rand_data) should be zeroed on the first call.

stm created this task.Nov 13 2018, 9:30 PM
stm added a comment.Nov 13 2018, 9:53 PM

Please note that this issue in Jitterentropy has been already fixed by upstream: http://www.chronox.de/jent.html

Initialize variable ec to satisfy valgrind as suggested by Steve Grubb

werner added a subscriber: werner.Nov 14 2018, 2:16 PM

Thanks. Just pushed the change to master.