severity critical thanks Hi Dirk, * Dirk Wetter <[EMAIL PROTECTED]> [2008-08-15 11:57]: > There's a problem with the randomness of mktemp. The > string includes a number which includes somewhat > the current process ID (based on the current PID). Worse: > Subsequent calls just seem to increase the number > by one:
The exact sequence is system dependent but looking at the code the problem is obvious: 75 static int 76 _gettemp(path, doopen, domkdir) 77 char *path; 78 register int *doopen; 79 int domkdir; 80 { 81 register char *start, *trv; 82 struct stat sbuf; 83 int pid, rval; 84 char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 85 86 if (doopen && domkdir) { 87 errno = EINVAL; 88 return(0); 89 } 90 91 pid = getpid(); 92 for (trv = path; *trv; ++trv) 93 ; 94 --trv; 95 while (trv >= path && *trv == 'X' && pid != 0) { 96 *trv-- = (pid % 10) + '0'; 97 pid /= 10; 98 } This is generating the numbers and the number here is only based on the pid. This is no randomness at all. Depending on the pid number this will always generate n non-random numbers at the end (for < 10000 4 numbers). 99 while (trv >= path && *trv == 'X') { 100 char c; 101 102 pid = (get_random() & 0xffff) % (26+26); 103 c = alphabet[pid]; 104 *trv-- = c; 105 } This is the alphabet part which looks fairly random to me (I am no crypto expert though) if _PATH_RANDOM is set which is the case for Debian. I raised the severity to critical as a lot of shell scripts in Debian rely on this data being random. Kind regards Nico -- Nico Golde - http://www.ngolde.de - [EMAIL PROTECTED] - GPG: 0x73647CFF For security reasons, all text in this mail is double-rot13 encrypted.
pgpIpS1IedUpj.pgp
Description: PGP signature