Skip to content

Protect WAF context creation against handle closure - #216

Draft
claponcet wants to merge 1 commit into
masterfrom
clara.poncet/appsec-70090-context-lifetime
Draft

claponcet wants to merge 1 commit into
masterfrom
clara.poncet/appsec-70090-context-lifetime

Conversation

@claponcet

@claponcet claponcet commented Oct 9, 2026 •

Copy link
Copy Markdown

What does this PR do?

Protects native WAF context creation against concurrent handle closure and rejects handles that have already closed.

Motivation

The handle-lifetime race investigated in APPSEC-70090 allows context initialization to access a freed native handle. The exact customer crash remains unreproduced.

Description of the Change

Context initialization takes the handle's existing read lock and checks its state before calling JNI. Handle closure uses the same lock's write side. Existing contexts retain their rules and continue evaluating after handle closure.

Adds four regression tests covering null and closed handles, creation waiting behind closure, and closure waiting for creation.

Additional Notes

Keep the tracer workaround until a release containing this fix is adopted. Removing that workaround also requires retrying with the current handle when a captured handle has closed.

Validated on macOS ARM64 with libddwaf 2.0.1: 201 standard tests passed, one skipped, on JDK 8 and 25; six GC tests passed on JDK 25/ZGC. Java 8 validation used a scratch compiler configuration with --release 8. Formatting checks pass. Performance benchmarking remains pending.

@datadog-datadog-prod-us1

Copy link
Copy Markdown

Pipelines

✨ Unblock PR with BitsAI

⚠️ Warnings

Your PR has warnings. Please review the issues below.

🚦 4 Pipeline jobs failed

Build Native Libraries | Coverage — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build Native Libraries | Development tests (macos-15) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build Native Libraries | Development tests (ubuntu-22.04) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

View all 4 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 556d7c1 | Docs | View more details | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant