Commit 428bb15
Fix Metaspace leak in SCA Reachability retransform and opcode injection (#12013)
Fix Metaspace leak in SCA Reachability (APPSEC-69201)
- Bound retransformClasses() retries: track per-class failure counts and give
up after MAX_RETRANSFORM_ATTEMPTS instead of re-queueing failed classes
forever, which retained Class<?>/ClassLoader references indefinitely.
- Cover all 13 ASM MethodVisitor visitXxxInsn callbacks in
ScaMethodCallbackInjector.MethodEntryInjector so the entry-point injection
triggers on the first bytecode instruction regardless of its opcode kind,
instead of only on the 4 previously handled ones.
Bisect failing retransform batches instead of coupling them by failure count
Split pendingRetransform into independent per-batch queue entries and retransform each
batch separately; on failure, bisect multi-class batches into two halves deferred to the
next heartbeat instead of tying an unrelated healthy class to a permanently-failing one.
Simplify singleton-batch retransform retry to drop-on-first-failure
Replace the retransformFailureCount/MAX_RETRANSFORM_ATTEMPTS bounded
retry with an immediate drop once a batch is narrowed down to a
single class, per the performance-over-detection trade-off agreed
with mcculls on PR #12013.
Batch already-loaded classes as one shared retransform group
checkAlreadyLoadedClasses() previously queued each already-loaded
vulnerable class as its own singleton batch, turning the common
all-succeed startup path into one retransformClasses() call per
class instead of one call for all of them. Queue them as a single
shared batch instead; bisection still applies on the next heartbeat
if that batch fails.
Found by Codex review on PR #12013.
Add test coverage for remaining MethodEntryInjector opcode overrides
jacocoTestCoverageVerification failed: visitIntInsn/visitJumpInsn/visitIincInsn/
visitTableSwitchInsn/visitLookupSwitchInsn/visitMultiANewArrayInsn were never
exercised by any test, leaving instruction coverage at 0.7 against the 0.8
minimum for the appsec module.
Remove non-modifiable classes from batch in place instead of copying to a second list
Addresses mccull's review comment: mutate the polled batch directly via
removeIf() instead of allocating a second ArrayList to hold the modifiable
classes. Updates tests that seeded pendingRetransform with immutable
singletonList() batches, which is no longer valid now that batches must
support in-place removal.
Merge branch 'master' into sca-bug
Merge branch 'master' into sca-bug
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent 0bf04c1 commit 428bb15
5 files changed
Lines changed: 510 additions & 50 deletions
File tree
- dd-java-agent/appsec/src
- main/java/com/datadog/appsec/sca
- test/java/com/datadog/appsec/sca
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
103 | 163 | | |
104 | 164 | | |
105 | 165 | | |
| |||
Lines changed: 98 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
85 | 87 | | |
86 | 88 | | |
87 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
90 | | - | |
| 94 | + | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| |||
242 | 246 | | |
243 | 247 | | |
244 | 248 | | |
| 249 | + | |
245 | 250 | | |
246 | 251 | | |
247 | 252 | | |
| |||
264 | 269 | | |
265 | 270 | | |
266 | 271 | | |
267 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
268 | 281 | | |
269 | 282 | | |
270 | 283 | | |
| |||
286 | 299 | | |
287 | 300 | | |
288 | 301 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
295 | 311 | | |
296 | 312 | | |
297 | 313 | | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
302 | 318 | | |
303 | 319 | | |
| 320 | + | |
304 | 321 | | |
305 | 322 | | |
306 | 323 | | |
| |||
310 | 327 | | |
311 | 328 | | |
312 | 329 | | |
313 | | - | |
| 330 | + | |
314 | 331 | | |
315 | 332 | | |
316 | 333 | | |
317 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
318 | 338 | | |
319 | 339 | | |
320 | | - | |
| 340 | + | |
321 | 341 | | |
322 | 342 | | |
323 | 343 | | |
| |||
329 | 349 | | |
330 | 350 | | |
331 | 351 | | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
352 | 374 | | |
353 | 375 | | |
354 | 376 | | |
355 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
356 | 396 | | |
357 | | - | |
| 397 | + | |
358 | 398 | | |
359 | | - | |
360 | | - | |
| 399 | + | |
361 | 400 | | |
362 | | - | |
363 | | - | |
364 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
365 | 419 | | |
366 | 420 | | |
367 | 421 | | |
| |||
0 commit comments