OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Licensed Materials - Property of IBM | 3 * Licensed Materials - Property of IBM |
4 * | 4 * |
5 * trousers - An open source TCG Software Stack | 5 * trousers - An open source TCG Software Stack |
6 * | 6 * |
7 * (C) Copyright International Business Machines Corp. 2004, 2005 | 7 * (C) Copyright International Business Machines Corp. 2004, 2005 |
8 * | 8 * |
9 */ | 9 */ |
10 | 10 |
11 | 11 |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <time.h> | 15 #include <time.h> |
16 #include <errno.h> | 16 #include <errno.h> |
17 #include <unistd.h> | 17 #include <unistd.h> |
18 #include <sys/types.h> | 18 #include <sys/types.h> |
19 #include <sys/mman.h> | 19 #include <sys/mman.h> |
20 | 20 |
21 #include "trousers/tss.h" | 21 #include "trousers/tss.h" |
22 #include "trousers/trousers.h" | 22 #include "trousers/trousers.h" |
23 #include "trousers_types.h" | 23 #include "trousers_types.h" |
24 #include "spi_utils.h" | 24 #include "spi_utils.h" |
25 #include "capabilities.h" | 25 #include "capabilities.h" |
26 #include "tsplog.h" | 26 #include "tsplog.h" |
27 #include "obj.h" | 27 #include "obj.h" |
28 | 28 |
| 29 #define PGSIZE sysconf(_SC_PAGESIZE) |
| 30 #define PGOFFSET (PGSIZE - 1) |
| 31 #define PGMASK (~PGOFFSET) |
| 32 |
29 /* | 33 /* |
30 * popup_GetSecret() | 34 * popup_GetSecret() |
31 * | 35 * |
32 * newPIN - non-zero to popup the dialog to enter a new PIN, zero to popup a
dialog | 36 * newPIN - non-zero to popup the dialog to enter a new PIN, zero to popup a
dialog |
33 * to enter an existing PIN | 37 * to enter an existing PIN |
34 * hash_mode - flag indicating whether to include null terminating data in th
e hash | 38 * hash_mode - flag indicating whether to include null terminating data in th
e hash |
35 * of the secret (1.2 backport only). | 39 * of the secret (1.2 backport only). |
36 * popup_str - string to appear in the title bar of the popup dialog | 40 * popup_str - string to appear in the title bar of the popup dialog |
37 * auth_hash - the 20+ byte buffer that receives the SHA1 hash of the auth da
ta | 41 * auth_hash - the 20+ byte buffer that receives the SHA1 hash of the auth da
ta |
38 * entered into the dialog box | 42 * entered into the dialog box |
39 * | 43 * |
40 */ | 44 */ |
41 TSS_RESULT | 45 TSS_RESULT |
42 popup_GetSecret(UINT32 new_pin, UINT32 hash_mode, BYTE *popup_str, void *auth_ha
sh) | 46 popup_GetSecret(UINT32 new_pin, UINT32 hash_mode, BYTE *popup_str, void *auth_ha
sh) |
43 { | 47 { |
44 BYTE secret[UI_MAX_SECRET_STRING_LENGTH] = { 0 }; | 48 BYTE secret[UI_MAX_SECRET_STRING_LENGTH] = { 0 }; |
45 BYTE *dflt = (BYTE *)"TSS Authentication Dialog"; | 49 BYTE *dflt = (BYTE *)"TSS Authentication Dialog"; |
46 » UINT32 secret_len; | 50 » UINT32 secret_len = 0; |
47 TSS_RESULT result; | 51 TSS_RESULT result; |
48 | 52 |
49 if (popup_str == NULL) | 53 if (popup_str == NULL) |
50 popup_str = dflt; | 54 popup_str = dflt; |
51 | 55 |
52 /* pin the area where the secret will be put in memory */ | 56 /* pin the area where the secret will be put in memory */ |
53 if (pin_mem(&secret, UI_MAX_SECRET_STRING_LENGTH)) { | 57 if (pin_mem(&secret, UI_MAX_SECRET_STRING_LENGTH)) { |
54 LogError("Failed to pin secret in memory."); | 58 LogError("Failed to pin secret in memory."); |
55 return TSPERR(TSS_E_INTERNAL_ERROR); | 59 return TSPERR(TSS_E_INTERNAL_ERROR); |
56 } | 60 } |
(...skipping 24 matching lines...) Expand all Loading... |
81 | 85 |
82 int | 86 int |
83 pin_mem(void *addr, size_t len) | 87 pin_mem(void *addr, size_t len) |
84 { | 88 { |
85 /* only root can lock pages into RAM */ | 89 /* only root can lock pages into RAM */ |
86 if (getuid() != (uid_t)0) { | 90 if (getuid() != (uid_t)0) { |
87 LogWarn("Not pinning secrets in memory due to insufficient perms
."); | 91 LogWarn("Not pinning secrets in memory due to insufficient perms
."); |
88 return 0; | 92 return 0; |
89 } | 93 } |
90 | 94 |
| 95 len += (uintptr_t)addr & PGOFFSET; |
| 96 addr = (void *)((uintptr_t)addr & PGMASK); |
91 if (mlock(addr, len) == -1) { | 97 if (mlock(addr, len) == -1) { |
92 LogError("mlock: %s", strerror(errno)); | 98 LogError("mlock: %s", strerror(errno)); |
93 return 1; | 99 return 1; |
94 } | 100 } |
95 | 101 |
96 return 0; | 102 return 0; |
97 } | 103 } |
98 | 104 |
99 int | 105 int |
100 unpin_mem(void *addr, size_t len) | 106 unpin_mem(void *addr, size_t len) |
101 { | 107 { |
102 /* only root can lock pages into RAM */ | 108 /* only root can lock pages into RAM */ |
103 if (getuid() != (uid_t)0) { | 109 if (getuid() != (uid_t)0) { |
104 return 0; | 110 return 0; |
105 } | 111 } |
106 | 112 |
| 113 len += (uintptr_t)addr & PGOFFSET; |
| 114 addr = (void *)((uintptr_t)addr & PGMASK); |
107 if (munlock(addr, len) == -1) { | 115 if (munlock(addr, len) == -1) { |
108 LogError("mlock: %s", strerror(errno)); | 116 LogError("mlock: %s", strerror(errno)); |
109 return 1; | 117 return 1; |
110 } | 118 } |
111 | 119 |
112 return 0; | 120 return 0; |
113 } | 121 } |
114 | 122 |
115 | 123 |
OLD | NEW |