Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD and OpenBSD fork detection #2089

Merged

Conversation

torben-hansen
Copy link
Contributor

@torben-hansen torben-hansen commented Dec 31, 2024

Description of changes:

Two things are happening in this PR:

  • Refactor code in fork_detect.c to make is more readable and amendable
  • Add new sufficient method for fork detection on FreeBSD and OpenBSD.

The new method uses minherit, tagging a memory page with a special value. The semantics are equivalent to the existing case with madvise.

Testing:

We still need some more testing to increase test coverage for fork detection. This is an upcoming task.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 78.12500% with 7 lines in your changes missing coverage. Please review.

Project coverage is 78.71%. Comparing base (2459c63) to head (c152f24).
Report is 2 commits behind head on randomness_generation.

Files with missing lines Patch % Lines
crypto/ube/fork_detect.c 78.12% 7 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           randomness_generation    #2089   +/-   ##
======================================================
  Coverage                  78.71%   78.71%           
======================================================
  Files                        606      608    +2     
  Lines                     102759   102791   +32     
  Branches                   14578    14584    +6     
======================================================
+ Hits                       80887    80917   +30     
- Misses                     21161    21164    +3     
+ Partials                     711      710    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

crypto/ube/fork_detect.c Show resolved Hide resolved
crypto/ube/fork_detect.c Outdated Show resolved Hide resolved
torben-hansen and others added 7 commits January 2, 2025 06:44
### Description of changes: 
BoringSSL now requires C++17 after
google/boringssl@9ff8491.
When we build speed.cc with BoringSSL's headers we need to specify our
our build to use C++17. This is blocking all of our CI with failures
like
[this](https://us-west-2.codebuild.aws.amazon.com/project/eyJlbmNyeXB0ZWREYXRhIjoiWk5IUWJGRGxBcTJ2Mkp4WGF3dnBwYjc5V0ZZYSt5SVVGbkwvODkydTNTaVQ2V2FMN3hwa0tjSWNFemw2QWtCWW5welFWV3lpRFpKVitwejgvelhpRWh3NDNqcWhKalpPYW9hL2tLMDlJSDFPT1NkNyIsIml2UGFyYW1ldGVyU3BlYyI6Ilp4VXRNQXFGM1BZYVlaRkIiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D/build/73b9a032-23e0-493c-b4f2-08fce7df7798).

### Call-outs:
This does not change AWS-LC's normal C++11 requirement.

### Testing:
The CI will build this. 

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
@torben-hansen torben-hansen marked this pull request as ready for review January 2, 2025 19:24
@torben-hansen torben-hansen requested a review from a team as a code owner January 2, 2025 19:24
Comment on lines +79 to +83
#if defined(MADV_WIPEONFORK)
OPENSSL_STATIC_ASSERT(MADV_WIPEONFORK == 18, MADV_WIPEONFORK_is_not_18)
#else
#define MADV_WIPEONFORK 18
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If MADV_WIPEONFORK were not already defined in the headers provided by the system, why do we think it's safe to define the value here?
  • Since it's a syscall parameter, the value of MADV_WIPEONFORK should be stable for a given target, but how do we know that the value is 18 across all Linux targets?
    • Possibly related: MADV_WIPEONFORK is not supported by linux kernels prior to v4.14. There are older kernels (like v4.4) that are still actively supported (till January 2027).
  • Should the macro guard for this section instead be something like:
#if defined(OPENSSL_LINUX) && defined(MADV_WIPEONFORK)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the existing behaviour and it has worked flawlessly.
It's just to increase support for the feature that we attempt to use a hard-coded value in case the define doesn't exist.

madvise(addr, (size_t)page_size, MADV_WIPEONFORK)

will fail if the feature is not supported.

Comment on lines +116 to +119
// Sometimes (for example, on FreeBSD) MAP_INHERIT_ZERO is called INHERIT_ZERO
#if !defined(MAP_INHERIT_ZERO) && defined(INHERIT_ZERO)
#define MAP_INHERIT_ZERO INHERIT_ZERO
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: Would it be safer to define our own macro with a value specific the target OS:

#if defined(OPENSSL_FREEBSD)
    #define AWS_LC_MAP_INHERIT_ZERO INHERIT_ZERO
#else // defined(OPENSSL_OPENBSD)
    #define AWS_LC_MAP_INHERIT_ZERO MAP_INHERIT_ZERO
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current form is a bit shorter. It has worked flawlessly in s2n-tls where I first used this pattern.

crypto/ube/fork_detect.c Show resolved Hide resolved
crypto/ube/fork_detect.c Show resolved Hide resolved
tests/ci/run_benchmark_build_tests.sh Show resolved Hide resolved
@torben-hansen torben-hansen merged commit 2637eda into aws:randomness_generation Jan 3, 2025
112 of 116 checks passed
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.

5 participants