Skip to content

Commit d8ca44b

Browse files
committed
Always DPURIFY
The use of the uninitialized buffer in the RNG has no real security benefits and is only a nuisance when using memory sanitizers. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
1 parent a01dab9 commit d8ca44b

7 files changed

Lines changed: 10 additions & 34 deletions

File tree

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
Changes between 1.0.2f and 1.1.0 [xx XXX xxxx]
66

7+
*) Always DPURIFY. Remove the use of uninitialized memory in the
8+
RNG, and other conditional uses of DPURIFY. This makes -DPURIFY a no-op.
9+
[Emilia Käsper]
10+
711
*) Removed many obsolete configuration items, including
812
DES_PTR, DES_RISC1, DES_RISC2, DES_INT
913
MD2_CHAR, MD2_INT, MD2_LONG

Configurations/90-team.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
%targets = (
99
"purify" => {
1010
cc => "purify gcc",
11-
cflags => "-g -DPURIFY -Wall",
11+
cflags => "-g -Wall",
1212
thread_cflag => "(unknown)",
1313
lflags => "-lsocket -lnsl",
1414
},

Configurations/99-personal-geoff.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
%targets = (
99
"debug-geoff32" => {
1010
cc => "gcc",
11-
cflags => "-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DPURIFY -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long",
11+
cflags => "-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long",
1212
thread_cflag => "-D_REENTRANT",
1313
lflags => "-ldl",
1414
bn_ops => "BN_LLONG",
@@ -19,7 +19,7 @@
1919
},
2020
"debug-geoff64" => {
2121
cc => "gcc",
22-
cflags => "-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DPURIFY -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long",
22+
cflags => "-DBN_DEBUG -DBN_DEBUG_RAND -DBN_STRICT -DOPENSSL_NO_DEPRECATED -DOPENSSL_NO_ASM -DOPENSSL_NO_INLINE_ASM -DL_ENDIAN -DTERMIO -DPEDANTIC -O1 -ggdb2 -Wall -Werror -Wundef -pedantic -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wno-long-long",
2323
thread_cflag => "-D_REENTRANT",
2424
lflags => "-ldl",
2525
bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR",

crypto/bn/bn_lib.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,13 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
313313
return (NULL);
314314
}
315315
if (BN_get_flags(b,BN_FLG_SECURE))
316-
a = A = OPENSSL_secure_malloc(words * sizeof(*a));
316+
a = A = OPENSSL_secure_zalloc(words * sizeof(*a));
317317
else
318-
a = A = OPENSSL_malloc(words * sizeof(*a));
318+
a = A = OPENSSL_zalloc(words * sizeof(*a));
319319
if (A == NULL) {
320320
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
321321
return (NULL);
322322
}
323-
#ifdef PURIFY
324-
/*
325-
* Valgrind complains in BN_consttime_swap because we process the whole
326-
* array even if it's not initialised yet. This doesn't matter in that
327-
* function - what's important is constant time operation (we're not
328-
* actually going to use the data)
329-
*/
330-
memset(a, 0, sizeof(*a) * words);
331-
#endif
332323

333324
#if 1
334325
B = b->d;

crypto/objects/obj_dat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5647,4 +5647,3 @@ static const unsigned int obj_objs[NUM_OBJ]={
56475647
956, /* OBJ_jurisdictionStateOrProvinceName 1 3 6 1 4 1 311 60 2 1 2 */
56485648
957, /* OBJ_jurisdictionCountryName 1 3 6 1 4 1 311 60 2 1 3 */
56495649
};
5650-

crypto/rand/md_rand.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,6 @@ static int rand_bytes(unsigned char *buf, int num, int pseudo)
551551
if (!MD_Update(m, (unsigned char *)&(md_c[0]), sizeof(md_c)))
552552
goto err;
553553

554-
#ifndef PURIFY /* purify complains */
555-
/*
556-
* The following line uses the supplied buffer as a small source of
557-
* entropy: since this buffer is often uninitialised it may cause
558-
* programs such as purify or valgrind to complain. So for those
559-
* builds it is not used: the removal of such a small source of
560-
* entropy has negligible impact on security.
561-
*/
562-
if (!MD_Update(m, buf, j))
563-
goto err;
564-
#endif
565-
566554
k = (st_idx + MD_DIGEST_LENGTH / 2) - st_num;
567555
if (k > 0) {
568556
if (!MD_Update(m, &(state[st_idx]), MD_DIGEST_LENGTH / 2 - k))

crypto/rand/randfile.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,13 @@ int RAND_load_file(const char *file, long bytes)
128128
return (0);
129129

130130
#ifndef OPENSSL_NO_POSIX_IO
131-
# ifdef PURIFY
132131
/*
133132
* struct stat can have padding and unused fields that may not be
134133
* initialized in the call to stat(). We need to clear the entire
135134
* structure before calling RAND_add() to avoid complaints from
136135
* applications such as Valgrind.
137136
*/
138137
memset(&sb, 0, sizeof(sb));
139-
# endif
140138
if (stat(file, &sb) < 0)
141139
return (0);
142140
RAND_add(&sb, sizeof(sb), 0.0);
@@ -170,12 +168,8 @@ int RAND_load_file(const char *file, long bytes)
170168
i = fread(buf, 1, n, in);
171169
if (i <= 0)
172170
break;
173-
#ifdef PURIFY
171+
174172
RAND_add(buf, i, (double)i);
175-
#else
176-
/* even if n != i, use the full array */
177-
RAND_add(buf, n, (double)i);
178-
#endif
179173
ret += i;
180174
if (bytes > 0) {
181175
bytes -= n;

0 commit comments

Comments
 (0)