Fix misaligned header pointer access in CreateTcpResetPacket.

### Why are we doing this?
`//third_party/quic/qbone/platform:tcp_packet_test` currently passes on `x86_64` (`--cpu=k8`) but fails on `Arm` (`--cpu=arm`) (see [go/multiarch-fix](http://go/multiarch-fix)).

Under `--config=ubsan`, `//third_party/quic/qbone/platform:tcp_packet_test` failed on Arm because `[tcp_packet.cc](http://cs/f:google3/third_party/quic/qbone/platform/tcp_packet.cc)` cast the raw byte buffer from `original_packet.data()` directly to `const ip6_hdr*` via `reinterpret_cast`. On Arm, `kReferenceTCPSYNPacket` in `[tcp_packet_test.cc](http://cs/f:google3/third_party/quic/qbone/platform/tcp_packet_test.cc)` happened to be placed at an address that was not 4-byte aligned (e.g. ending in `...b2`), whereas on x86_64 it happened to be aligned. Accessing struct members through a misaligned pointer is undefined behavior and triggered UndefinedBehaviorSanitizer's `misaligned-pointer-use` runtime error on Arm.

### What changed
In [tcp_packet.cc](http://cs/f:google3/third_party/quic/qbone/platform/tcp_packet.cc), copy `ip6_hdr` and `tcphdr` into naturally aligned stack structures using `memcpy` rather than casting unaligned byte pointers with `reinterpret_cast`. Also verify that `original_packet.size()` is large enough to contain both `ip6_hdr` and `tcphdr` before copying the TCP header.

### Verification
Verified with `blaze test --nocache_test_results`:
- Pre-fix `--cpu=k8` (`PASS`): http://sponge2/dd1bf5ff-8512-4572-aad5-ac7dd22d6c8b
- Pre-fix `--cpu=arm` (`FAIL`): http://sponge2/8f3ea8a2-678c-4166-995e-2a6c846a7e40
- Post-fix `--cpu=arm` (`PASS`): http://sponge2/c76c4440-ca59-4047-acfb-d26fc3b3eac7
- Post-fix `--cpu=k8` (`PASS`): http://sponge2/cf42a087-6bfc-4f94-b77c-876d041c62f1

Generated by [Lightway](http://go/lightway) for `multiarch_divergence_fixer`: [Pipeline summary](http://g3doc/.journal/g3doc/pipeline_summary?cl=groupagent-lightway-ai/1111606) | [Run dashboard](http://go/lightway-runs?f=RunId:eq:937aa2b5-4a8c-416f-9c42-c81a7fa6127e)

#multiarch_divergence_fixer #fix-divergence #lightway

Tested:
    Local presubmit tests passed.
PiperOrigin-RevId: 1008932221
2 files changed
tree: 1eee6cc4d6b2f93c7ab280dc1a48768da1a5e7d9
  1. build/
  2. depstool/
  3. quiche/
  4. .bazelrc
  5. .bazelversion
  6. BUILD.bazel
  7. CONTRIBUTING.md
  8. LICENSE
  9. MODULE.bazel
  10. MODULE.bazel.lock
  11. README.md
  12. WHITESPACE
README.md

QUICHE

QUICHE stands for QUIC, Http, Etc. It is Google‘s production-ready implementation of QUIC, HTTP/2, HTTP/3, and related protocols and tools. It powers Google’s servers, Chromium, Envoy, and other projects. It is actively developed and maintained.

There are two public QUICHE repositories. Either one may be used by embedders, as they are automatically kept in sync:

To embed QUICHE in your project, platform APIs need to be implemented and build files need to be created. Note that it is on the QUICHE team's roadmap to include default implementation for all platform APIs and to open-source build files. In the meanwhile, take a look at open source embedders like Chromium and Envoy to get started:

To contribute to QUICHE, follow instructions at CONTRIBUTING.md.

QUICHE is only supported on little-endian platforms.

Build and run standalone QUICHE

QUICHE has binaries that can run on Linux platforms.

Follow the instructions to install Bazel.

sudo apt install libicu-dev clang lld
cd <directory that will be the root of your quiche implmentation>
git clone https://github.com/google/quiche.git
cd quiche
CC=clang bazel build -c opt //...
./bazel-bin/quiche/<target_name> <arguments>

There are several targets that can be built and then run. Full usage instructions are available using the --helpfull flag on any binary.

  • quic_packet_printer: from a provided packet, parses and prints out the contents that are accessible without decryption.

Usage: quic_packet_printer server|client <hex dump of packet>

  • crypto_message_printer: dumps the contents of a QUIC crypto handshake message in a human readable format.

Usage: crypto_message_printer_bin <hex of message>

  • quic_client: connects to a host using QUIC and HTTP/3, sends a request to the provided URL, and displays the response.

Usage: quic_client <URL>

  • quic_server: listens forever on --port (default 6121) until halted via ctrl-c.

  • masque_client: tunnels to a URL via an identified proxy (See RFC 9298).

Usage: masque_client [options] <proxy-url> <urls>

  • masque_server: a MASQUE tunnel proxy that defaults to port 9661.

Usage: masque_server

  • web_transport_test_server: a server that clients can connect to via WebTransport.

  • moqt_relay: a relay for the Media Over QUIC transport for publishers and subscribers can connect to.

Usage: moqt_relay

Logging

Most log messages in QUICHE use the QUICHE_DLOG macro. In standalone quiche, these all either go to stderr, or are suppressed, based on the --stderrthreshold flag.

To send INFO level log messages to a file, you would therefore invoke

<binary> <args> > <logfile> 2>&1

Use the --helpfull flag for more.