summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorbcook <>2016-06-30 12:17:29 +0000
committerbcook <>2016-06-30 12:17:29 +0000
commitfafc8dbf4d3bb9d3105c9575a1536623d00a3eca (patch)
tree1befc101a690cd02f9a8dd0a47bdc267d399819f /src/lib
parent5bfca97f9b3e68d1e83fcb3a5ade7b35c3b95e32 (diff)
downloadopenbsd-fafc8dbf4d3bb9d3105c9575a1536623d00a3eca.tar.gz
openbsd-fafc8dbf4d3bb9d3105c9575a1536623d00a3eca.tar.bz2
openbsd-fafc8dbf4d3bb9d3105c9575a1536623d00a3eca.zip
Tighten behavior of _rs_allocate on Windows.
For Windows, we are simply using calloc, which has two annoyances: the memory has more permissions than needed by default, and it comes from the process heap, which looks like a memory leak since this memory is rightfully never freed. This switches _rs_alloc on Windows to use VirtualAlloc, which restricts the memory to READ|WRITE and keeps the memory out of the process heap. ok deraadt@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/arc4random/arc4random_win.h11
-rw-r--r--src/lib/libcrypto/crypto/arc4random_win.h11
2 files changed, 14 insertions, 8 deletions
diff --git a/src/lib/libcrypto/arc4random/arc4random_win.h b/src/lib/libcrypto/arc4random/arc4random_win.h
index 48a1bda128..deec8a1efe 100644
--- a/src/lib/libcrypto/arc4random/arc4random_win.h
+++ b/src/lib/libcrypto/arc4random/arc4random_win.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_win.h,v 1.5 2015/01/15 06:57:18 deraadt Exp $ */ 1/* $OpenBSD: arc4random_win.h,v 1.6 2016/06/30 12:17:29 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -52,13 +52,16 @@ _getentropy_fail(void)
52static inline int 52static inline int
53_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 53_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
54{ 54{
55 *rsp = calloc(1, sizeof(**rsp)); 55 *rsp = VirtualAlloc(NULL, sizeof(**rsp),
56 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
56 if (*rsp == NULL) 57 if (*rsp == NULL)
57 return (-1); 58 return (-1);
58 59
59 *rsxp = calloc(1, sizeof(**rsxp)); 60 *rsxp = VirtualAlloc(NULL, sizeof(**rsxp),
61 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
60 if (*rsxp == NULL) { 62 if (*rsxp == NULL) {
61 free(*rsp); 63 VirtualFree(*rsp, 0, MEM_RELEASE);
64 *rsp = NULL;
62 return (-1); 65 return (-1);
63 } 66 }
64 return (0); 67 return (0);
diff --git a/src/lib/libcrypto/crypto/arc4random_win.h b/src/lib/libcrypto/crypto/arc4random_win.h
index 48a1bda128..deec8a1efe 100644
--- a/src/lib/libcrypto/crypto/arc4random_win.h
+++ b/src/lib/libcrypto/crypto/arc4random_win.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random_win.h,v 1.5 2015/01/15 06:57:18 deraadt Exp $ */ 1/* $OpenBSD: arc4random_win.h,v 1.6 2016/06/30 12:17:29 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -52,13 +52,16 @@ _getentropy_fail(void)
52static inline int 52static inline int
53_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 53_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
54{ 54{
55 *rsp = calloc(1, sizeof(**rsp)); 55 *rsp = VirtualAlloc(NULL, sizeof(**rsp),
56 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
56 if (*rsp == NULL) 57 if (*rsp == NULL)
57 return (-1); 58 return (-1);
58 59
59 *rsxp = calloc(1, sizeof(**rsxp)); 60 *rsxp = VirtualAlloc(NULL, sizeof(**rsxp),
61 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
60 if (*rsxp == NULL) { 62 if (*rsxp == NULL) {
61 free(*rsp); 63 VirtualFree(*rsp, 0, MEM_RELEASE);
64 *rsp = NULL;
62 return (-1); 65 return (-1);
63 } 66 }
64 return (0); 67 return (0);