Add a fuzzer for STUN response handling

The three existing STUN/TURN fuzzers are stateless: stun_parser_fuzzer
reads a standalone StunMessage and validates it against an empty
password, stun_validator_fuzzer calls the static fingerprint and
integrity validators on raw bytes, and turn_unwrap_fuzzer calls
UnwrapTurnPacket. None of them constructs a StunRequestManager, so
none of them reaches response handling at all:

  RequestMap::iterator iter = requests_.find(msg->transaction_id());
  if (iter == requests_.end())
    return false;

is the third line of CheckResponse, and a fuzzer that never sent a
request always returns there. No target in test/fuzzers/BUILD.gn
depends on p2p, so everything downstream of that lookup is currently
unfuzzed: the integrity decision that depends on the request's
AuthenticationRequired state, the comprehension-required attribute
check, the success/error branch split, and the OnResponse /
OnErrorResponse dispatch.

This target sends credentialed ALLOCATE requests first, then builds
responses for them.

The response is built with the StunMessage builder instead of being
handed over as mutated bytes. Three filters sit in front of the state
machine: the transaction id has to match a pending request, the
message type has to equal GetStunSuccessResponseType or
GetStunErrorResponseType for that request, and on the success branch
IntegrityOk() has to hold, which needs a valid HMAC-SHA1 over the
message. The last one is not just unlikely to be guessed, it cannot
be, so a mutating target can never execute OnResponse. Building the
message spends the input on the parts that carry attacker data -- which
attributes are present, their lengths and contents, the error code,
whether integrity is valid, and the order in which responses arrive
relative to each other and to simulated time. Malformed wire input is
left to stun_parser_fuzzer rather than duplicated here.

The request is a TurnMessage rather than a StunMessage. CheckResponse
parses the response with iter->second->msg_->CreateNew(), so the
request's class is what decides which attribute types count as
comprehended. With a plain StunMessage every TURN attribute (LIFETIME,
DATA, XOR-RELAYED-ADDRESS) is unknown, and since they all sit in the
comprehension-required range the response is discarded before the
branch split is reached.

The callbacks act on the manager. The base class ones are empty, so a
target that sends a plain StunRequest reaches the dispatch and then
executes nothing, and CheckResponse states that a callback may modify
the StunRequestManager any way it sees fit. Each action mirrors a real
one: sending another request, as OnAuthChallenge and OnTryAlternate
both do from inside OnErrorResponse; clearing the manager, as TurnPort
does when an allocation fails; and deferring that clear with PostTask,
as the ALLOCATION_MISMATCH path does. Re-entrancy is depth-capped,
since production bounds its retries and an uncapped target would only
find its own recursion.

Simulated time advances between deliveries in steps large enough to
reach all eight retransmissions and the timeout.

Coverage over the seed corpus, four workers for seven minutes:
CheckResponse(StunMessage*) 36 of 80 edges, OnResponse 188 hits,
OnErrorResponse 220, OnTimeout 83, RevalidateMessageIntegrity 169,
GetErrorCodeValue 111. No crashes so far.

The seed corpus holds one file per branch, each named for the branch it
reaches. The byte-level STUN dictionary is deliberately not used here:
the input is a command stream, so STUN byte patterns are noise in it.

Bug: None
Change-Id: I166a130385591ceaf888f8485b39ed8380bfea93
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/510380
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#49009}
21 files changed
tree: e2b055f8714d68f17ba79cfa701c450297442f4e
  1. .agents/
  2. agents/
  3. api/
  4. audio/
  5. build_overrides/
  6. call/
  7. common_audio/
  8. common_video/
  9. data/
  10. docs/
  11. examples/
  12. experiments/
  13. g3doc/
  14. infra/
  15. logging/
  16. media/
  17. modules/
  18. net/
  19. p2p/
  20. pc/
  21. resources/
  22. rtc_base/
  23. rtc_tools/
  24. rust/
  25. sdk/
  26. stats/
  27. system_wrappers/
  28. test/
  29. tools_webrtc/
  30. video/
  31. .clang-format
  32. .clang-tidy
  33. .git-blame-ignore-revs
  34. .gitignore
  35. .gn
  36. .mailmap
  37. .rustfmt.toml
  38. .style.mdformat
  39. .style.yapf
  40. .yapfignore
  41. AUTHORS
  42. BUILD.gn
  43. CODE_OF_CONDUCT.md
  44. codereview.settings
  45. DEPS
  46. DIR_METADATA
  47. ENG_REVIEW_OWNERS
  48. GEMINI.md
  49. LICENSE
  50. license_template.txt
  51. native-api.md
  52. OWNERS
  53. OWNERS_INFRA
  54. PATENTS
  55. PRESUBMIT.py
  56. presubmit_test.py
  57. presubmit_test_mocks.py
  58. pylintrc
  59. pylintrc_old_style
  60. README.chromium
  61. README.md
  62. unsafe_buffers_paths.txt
  63. vpython.toml
  64. vpython.toml.uv.lock
  65. WATCHLISTS
  66. webrtc.gni
  67. webrtc_lib_link_test.cc
  68. whitespace.txt
README.md

WebRTC is a free, open software project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. The WebRTC components have been optimized to best serve this purpose.

Our mission: To enable rich, high-quality RTC applications to be developed for the browser, mobile platforms, and IoT devices, and allow them all to communicate via a common set of protocols.

The WebRTC initiative is a project supported by Google, Mozilla and Opera, amongst others.

Development

See here for instructions on how to get started developing with the native code.

Authoritative list of directories that contain the native API header files.

More info