Commit 98c2ec6
authored
[GEODE-10520] Security : Eliminate DirectBuffer Access to sun.nio.ch Internal Package (#7955)
* refactor: Replace internal JDK DirectBuffer with public API solution
Replace sun.nio.ch.DirectBuffer usage with BufferAttachmentTracker, using only
public Java APIs (WeakHashMap and ByteBuffer).
Changes:
- Created BufferAttachmentTracker: WeakHashMap-based tracker for slice-to-original
buffer mappings, replacing internal DirectBuffer.attachment() access
- Updated BufferPool: Modified slice creation to record mappings and simplified
getPoolableBuffer() to use the tracker
- Removed DirectBuffer wrapper: Deleted geode-unsafe DirectBuffer wrapper class
- Updated MemberJvmOptions: Removed SUN_NIO_CH_EXPORT from required JVM options
- Added comprehensive unit tests: BufferAttachmentTrackerTest validates all
tracker functionality
Benefits:
- Eliminates one JVM module export requirement
- Uses only public Java APIs
- Maintains functionality with automatic memory cleanup via WeakHashMap
- Fully backward compatible
Testing:
- All BufferPool tests pass
- New BufferAttachmentTracker tests pass
- Compilation successful
* Add comprehensive documentation to BufferAttachmentTracker
- Add detailed PMD suppression justification explaining thread-safety
- Document why ConcurrentHashMap is safe for concurrent access
- Explain lock-free operations and atomic guarantees
- Add 7-line comment block explaining mutable static field design choice
* Apply spotless formatting to BufferAttachmentTrackerTest
* fix: Correct buffer pooling to prevent capacity issues in NioEngine
- Fixed acquirePredefinedFixedBuffer() to return full-capacity buffers
instead of modifying buffer limits before return
- Added BufferAttachmentTracker.removeTracking() in releaseBuffer()
to properly clean up slice-to-original mappings
- Created non-slicing buffer acquisition methods for NioPlainEngine
and NioSslEngine which require reusable full-capacity buffers
- Separated buffer acquisition into two use cases:
* Single-use sliced buffers (2-param acquireDirectBuffer)
* Reusable full-capacity buffers (3-param acquireDirectBuffer)
This fixes IllegalArgumentException 'newLimit > capacity' errors in
distributed tests by ensuring pooled buffers maintain proper capacity.
* Fix IndexOutOfBoundsException in BufferAttachmentTracker
Replace ConcurrentHashMap with synchronized IdentityHashMap to avoid
ByteBuffer.equals() issues. ByteBuffer uses content-based equality which
can throw IndexOutOfBoundsException when buffer state (position/limit)
changes after being used as a map key. IdentityHashMap uses object
identity (==) which is safe and appropriate for tracking buffer relationships.1 parent 919f915 commit 98c2ec6
File tree
6 files changed
+387
-123
lines changed- geode-core/src
- main/java/org/apache/geode/internal/net
- test/java/org/apache/geode/internal/net
- geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands
- geode-unsafe/src
- main/java/org/apache/geode/unsafe/internal/sun/nio/ch
- test/java/org/apache/geode/unsafe/internal/sun/nio/ch
6 files changed
+387
-123
lines changedLines changed: 103 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
Lines changed: 48 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | | - | |
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
| |||
111 | 109 | | |
112 | 110 | | |
113 | 111 | | |
| 112 | + | |
114 | 113 | | |
115 | 114 | | |
| 115 | + | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| 163 | + | |
162 | 164 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | 165 | | |
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
170 | 169 | | |
171 | 170 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | 171 | | |
176 | 172 | | |
177 | 173 | | |
| |||
267 | 263 | | |
268 | 264 | | |
269 | 265 | | |
| 266 | + | |
| 267 | + | |
270 | 268 | | |
271 | 269 | | |
272 | 270 | | |
273 | 271 | | |
274 | | - | |
| 272 | + | |
275 | 273 | | |
276 | | - | |
| 274 | + | |
277 | 275 | | |
278 | 276 | | |
279 | 277 | | |
280 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
281 | 311 | | |
282 | 312 | | |
283 | 313 | | |
| |||
310 | 340 | | |
311 | 341 | | |
312 | 342 | | |
313 | | - | |
314 | | - | |
315 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
316 | 348 | | |
317 | | - | |
| 349 | + | |
318 | 350 | | |
319 | 351 | | |
320 | 352 | | |
| |||
328 | 360 | | |
329 | 361 | | |
330 | 362 | | |
331 | | - | |
| 363 | + | |
332 | 364 | | |
333 | 365 | | |
334 | 366 | | |
335 | 367 | | |
336 | 368 | | |
337 | 369 | | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 370 | + | |
350 | 371 | | |
351 | 372 | | |
352 | 373 | | |
| |||
0 commit comments