Mailing List Archive

infinite loop in win32 randomness gatherer
I'm using libgcrypt 1.2.1 under win32 (mingw cross-compile).

Under some circumstances, I found that libgcrypt would go into an
infinite (well, to the limits of my patience) loop. A whole lot of
fprintfs later, I tracked down the problem.

slow_gatherer_windows95 walks the heap table and adds everything in it
to the randomness pool. What seems to be happening is that the act of
adding things to the pool, is changing the table, and you end up with an
infinite loop if that change is to add an item _after_ the place you
currently are in the scan.

Here's a patch that just cuts your losses by adding a maximum of 500
heap entries. It seems to work Much Better Now (tm). ;-)

Thanks,

- Ian

--- rndw32.c.orig 2003-12-11 10:46:12.000000000 -0500
+++ rndw32.c 2005-01-18 09:45:26.000000000 -0500
@@ -238,6 +238,8 @@

/* Walk through the local heap */
{ HEAPLIST32 hl32;
+ DWORD dwHeapsAdded = 0;
+ const DWORD maxHeapsToAdd = 500;
hl32.dwSize = sizeof (HEAPLIST32);
if (pHeap32ListFirst (hSnapshot, &hl32)) {
if ( debug_me )
@@ -254,12 +256,16 @@
if (pHeap32First (&he32, hl32.th32ProcessID, hl32.th32HeapID)){
do {
(*add) ( &he32, sizeof (he32), requester );
+ if (++dwHeapsAdded == maxHeapsToAdd) {
+ goto doneheap;
+ }
} while (pHeap32Next (&he32));
}
} while (pHeap32ListNext (hSnapshot, &hl32));
}
}

+doneheap:

/* Walk through all processes */
{ PROCESSENTRY32 pe32;
Re: infinite loop in win32 randomness gatherer [ In reply to ]
On Tue, 18 Jan 2005 10:03:12 -0500, Ian Goldberg said:

> slow_gatherer_windows95 walks the heap table and adds everything in it
> to the randomness pool. What seems to be happening is that the act of

Hmmm, I switched over to W2000 so I have not tested it for a long time.

> adding things to the pool, is changing the table, and you end up with an
> infinite loop if that change is to add an item _after_ the place you
> currently are in the scan.

I need to check Peter Gutmann's latest revision of cryptlib - the code
is basically his and I shoudl really update it.

> Here's a patch that just cuts your losses by adding a maximum of 500
> heap entries. It seems to work Much Better Now (tm). ;-)

Thanks,

Werner
Re: infinite loop in win32 randomness gatherer [ In reply to ]
On Tue, Jan 18, 2005 at 05:40:15PM +0100, Werner Koch wrote:
> On Tue, 18 Jan 2005 10:03:12 -0500, Ian Goldberg said:
>
> > slow_gatherer_windows95 walks the heap table and adds everything in it
> > to the randomness pool. What seems to be happening is that the act of
>
> Hmmm, I switched over to W2000 so I have not tested it for a long time.

This is actually an XP box. slow_gatherer_windows95 is called whenever

has_toolhelp = (platform == VER_PLATFORM_WIN32_WINDOWS
|| (is_windowsNT && osvi.dwMajorVersion >= 5));

is true.

- Ian