Make `bssl::Span::subspan` behave like `std::span::subspan`.

This means it will no longer clip requested sizes to what is available,
but instead `abort()` the process. In comparison, `std::span::subspan`
would throw a contract violation, whereas `absl::Span` clips.

This enables compile-time sizing of `std::span::subspan` return values
even if the input span is runtime sized.

Also, a bunch of places have been changed to perform desired clipping at
the call site; `subspan` use has previously been audited and marked in
I5d37c730fd6ea131f3b3bfafe7ea0fe690906a22.

Audited all potential new `abort()` calls with Ghidriff; found the
following two places of interest:

- https://boringssl.googlesource.com/boringssl/+/4c2a6a5467e4abea270877740b5975cac772802d/ssl/d1_both.cc#775
  uses offsets and lengths from `range` and indexes into `body` with
  them. `body` is 12 bytes less than `msg.data`, and `range` is
  initialized to precisely that size, so things should be fine.
- https://boringssl.googlesource.com/boringssl/+/4c2a6a5467e4abea270877740b5975cac772802d/ssl/tls13_enc.cc#668
  assumes `msg` is at least `full_header_len` large, and that
  `offset >= full_header_len`. In the former case it'd already be
  failing anyway; the latter case would be obvious nonsense and indicate
  a clear bug of the caller. I checked all callers, and none can cause
  this condition right now.

Update-Note: `bssl::Span::subspan` method now fails when second argument
points beyond span length. Previous `sp.subspan(pos, len)` can be
rewritten as `sp.subspan(pos, std::min(len, sp.size() - pos))` if
necessary.

Bug: 453872746
Change-Id: I68d031abc0d8d5a602d9913bcd88cde659fb1956
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/83707
Reviewed-by: David Benjamin <davidben@google.com>
Auto-Submit: Rudolf Polzer <rpolzer@google.com>
Commit-Queue: Rudolf Polzer <rpolzer@google.com>
5 files changed
tree: 3b2b53437ac7c45f8f223042558e42629f55a92a
  1. .bcr/
  2. .github/
  3. cmake/
  4. crypto/
  5. decrepit/
  6. docs/
  7. fuzz/
  8. gen/
  9. include/
  10. infra/
  11. pki/
  12. rust/
  13. ssl/
  14. third_party/
  15. tool/
  16. util/
  17. .bazelignore
  18. .bazelrc
  19. .bazelversion
  20. .clang-format
  21. .clang-format-ignore
  22. .gitignore
  23. API-CONVENTIONS.md
  24. AUTHORS
  25. BREAKING-CHANGES.md
  26. BUILD.bazel
  27. build.json
  28. BUILDING.md
  29. CMakeLists.txt
  30. codereview.settings
  31. CONTRIBUTING.md
  32. FUZZING.md
  33. go.mod
  34. go.sum
  35. INCORPORATING.md
  36. LICENSE
  37. MODULE.bazel
  38. MODULE.bazel.lock
  39. PORTING.md
  40. PRESUBMIT.py
  41. PrivacyInfo.xcprivacy
  42. README.md
  43. SANDBOXING.md
  44. STYLE.md
README.md

BoringSSL

BoringSSL is a fork of OpenSSL that is designed to meet Google's needs.

Although BoringSSL is an open source project, it is not intended for general use, as OpenSSL is. We don't recommend that third parties depend upon it. Doing so is likely to be frustrating because there are no guarantees of API or ABI stability.

Programs ship their own copies of BoringSSL when they use it and we update everything as needed when deciding to make API changes. This allows us to mostly avoid compromises in the name of compatibility. It works for us, but it may not work for you.

BoringSSL arose because Google used OpenSSL for many years in various ways and, over time, built up a large number of patches that were maintained while tracking upstream OpenSSL. As Google's product portfolio became more complex, more copies of OpenSSL sprung up and the effort involved in maintaining all these patches in multiple places was growing steadily.

Currently BoringSSL is the SSL library in Chrome/Chromium, Android (but it's not part of the NDK) and a number of other apps/programs.

Project links:

To file a security issue, use the Chromium process and mention in the report this is for BoringSSL. You can ignore the parts of the process that are specific to Chromium/Chrome.

There are other files in this directory which might be helpful: