Commit 29d7d20
fix(plugins): close TOCTOU window in keystore directory scans
The plugins CLI scans (KeystoreList, KeystoreImport.findExistingKeystore,
KeystoreUpdate.findKeystoreByAddress) and the second keystore read in
KeystoreUpdate.call previously combined a NOFOLLOW lstat check with a
subsequent MAPPER.readValue(file, ...). Jackson's File overload uses
FileInputStream → open(2) without O_NOFOLLOW, so an attacker who can
write in the keystore directory could swap a regular file for a symlink
between the stat and the read.
Replace the check-then-use pattern with a single read that pushes the
NOFOLLOW flag down to the open syscall:
- New KeystoreCliUtils.readKeystoreFile(File, PrintWriter) opens via
Files.newByteChannel(path, READ, NOFOLLOW_LINKS), reads at most
MAX_KEYSTORE_SIZE (8 KiB) bytes, and returns the byte[] for the
caller to feed into MAPPER.readValue(byte[], Class) — no second
file handle, no follow-symlink window.
- Drop isSafeRegularFile (now subsumed by readKeystoreFile).
- All four call sites switched: list, import duplicate scan, update
lookup scan, and update's re-read after lookup at KeystoreUpdate
.call line 141.
Also adds an explicit oversized-file warning ("skipping oversized
file") so a hostile directory of large planted files surfaces clearly
rather than silently consuming memory.
Note: this hardens the plugins CLI scenario specifically. The SR
startup path through WalletUtils.loadCredentials uses a different
policy (warn + follow, see commit df91f45) — that path explicitly
configures a single keystore file, parallel to Lighthouse's
voting_keystore_path, where symlink support is part of the contract.1 parent df91f45 commit 29d7d20
4 files changed
Lines changed: 78 additions & 25 deletions
File tree
- plugins/src/main/java/common/org/tron/plugins
Lines changed: 60 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
| |||
202 | 210 | | |
203 | 211 | | |
204 | 212 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
211 | 216 | | |
212 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
213 | 227 | | |
214 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
215 | 231 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
221 | 262 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
225 | 267 | | |
226 | | - | |
| 268 | + | |
227 | 269 | | |
228 | 270 | | |
229 | | - | |
| 271 | + | |
230 | 272 | | |
231 | 273 | | |
232 | 274 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
| 173 | + | |
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
176 | | - | |
| 177 | + | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
| |||
199 | 207 | | |
200 | 208 | | |
201 | 209 | | |
202 | | - | |
| 210 | + | |
| 211 | + | |
203 | 212 | | |
204 | 213 | | |
205 | 214 | | |
206 | | - | |
| 215 | + | |
207 | 216 | | |
208 | 217 | | |
209 | 218 | | |
| |||
0 commit comments