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

Implementation of fork generation number API #3191

Merged
merged 54 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
44af86d
Implementation of fork generation number API
torben-hansen Feb 3, 2022
a8409a6
Use s2n_array_len
torben-hansen Feb 3, 2022
bc16bc1
Remove out-of-date comment
torben-hansen Feb 3, 2022
02a6d29
Work around simple_mistakes error
torben-hansen Feb 3, 2022
6b83410
Remove unused error
torben-hansen Feb 3, 2022
d5a25e5
UB to increment void pointer. So, cast to char pointer which is stand…
torben-hansen Feb 3, 2022
5557bf3
Use correct function signature for thread creation callback and don't…
torben-hansen Feb 3, 2022
9954e45
Rename not to collide with other unused definition
torben-hansen Feb 3, 2022
eef8df7
Actually return all the time
torben-hansen Feb 3, 2022
788f28b
Feature test macro for clone()
torben-hansen Feb 3, 2022
0f6e7ff
Sigh, wrong signature
torben-hansen Feb 3, 2022
407af3e
This might fix it
torben-hansen Feb 3, 2022
6ff05c0
Properly set test feature macro, makes sure to include pthread header…
torben-hansen Feb 3, 2022
65eb924
Silence unused error and return frmom thread callback
torben-hansen Feb 3, 2022
8c99000
Use another static assert implementation that doesn't cause unused er…
torben-hansen Feb 3, 2022
95f493c
Reorder commands
torben-hansen Feb 3, 2022
25285a3
Can't reproduce locally, so inject debug statements that are visible …
torben-hansen Feb 4, 2022
550a36f
More debug statements
torben-hansen Feb 4, 2022
5d40108
Valgrind doesn't work well with clone(). Attempt to make this more re…
torben-hansen Feb 4, 2022
c630631
Give up on trying to make Valgrind work with clone using heap memory...
torben-hansen Feb 4, 2022
dd33655
Rever test
torben-hansen Feb 4, 2022
2e66c17
Switch to heap memory and clean up debug statements.
torben-hansen Feb 4, 2022
5939ed3
mman.h is always included, so move it out.
torben-hansen Feb 12, 2022
708cc5f
Use s2n namespace for fork event macro
torben-hansen Feb 12, 2022
63bb388
Remove the invalid advice probe. We can't distinguish anyway and it i…
torben-hansen Feb 12, 2022
c1cfbdf
Improve comment about prediction resistance
torben-hansen Feb 12, 2022
6fe340d
Add back comment on verifying invalid advice arguments.
torben-hansen Feb 12, 2022
af3794d
Add s2n namespace prefix to non-static functions.
torben-hansen Feb 12, 2022
63ec53e
Improve static array length calc comment
torben-hansen Feb 12, 2022
a42d77b
Moved static assert macro away from code-generated file.
torben-hansen Feb 12, 2022
3d3683a
Include correct safety header.
torben-hansen Feb 12, 2022
8b409a9
Fix comment
torben-hansen Feb 18, 2022
cba7c08
American vs British language form debate
torben-hansen Feb 18, 2022
48e84bf
Always use s2n namespace... and a missing letter t.
torben-hansen Feb 18, 2022
690b1af
Fixed indentation...
torben-hansen Feb 18, 2022
af1cc51
Fix new-line diff
torben-hansen Feb 18, 2022
bf54e6c
Also check return value of munmap where it makes sense
torben-hansen Feb 18, 2022
d2e58a5
Return S2N_RESULT type from for_testing functions
torben-hansen Feb 19, 2022
a614d82
Change to bool return type
torben-hansen Feb 19, 2022
112dd7c
Remove magic numbers and add more bool from previous commit
torben-hansen Feb 19, 2022
b22ea20
Simplify error handling by factoring out init logic
torben-hansen Feb 19, 2022
47bca31
Ported s2n_get_fork_generation_number() to S2N_RESULT, which is nicer
torben-hansen Feb 19, 2022
ca564f6
Fix function documentation and some off-by-one-space indentation
torben-hansen Feb 21, 2022
f04fda5
Use TEST_DEBUG_PRINT instead of custom FGN_TEST_CASE_PRINT_MSG_INFO
torben-hansen Mar 13, 2022
6627a45
Varies changes based on PR comments
torben-hansen Mar 13, 2022
08d45c6
Convert to bool type variables
torben-hansen Mar 15, 2022
b54c7a9
Make more s2n'ish by switching more stuff to use the S2N_RESULT type
torben-hansen Mar 15, 2022
36c2554
Rename function, use runtime array check, and some minor stuff
torben-hansen Mar 15, 2022
16bb0ca
Use try_compile instead
torben-hansen Mar 16, 2022
93147c8
Attempt to improve s2n_probe_madv_wipeonfork_support
torben-hansen Mar 16, 2022
42e1de2
Use preprocessor and if directive to verify the value of MADV_WIPEONF…
torben-hansen Mar 16, 2022
80556da
Few minor PR comments
torben-hansen Mar 16, 2022
cbbcc05
Improve try_compile() feature probing
torben-hansen Mar 16, 2022
693e038
Fix wrong macro
torben-hansen Mar 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,30 @@ try_compile(
COMPILE_DEFINITIONS "-Werror"
)

# Determine if madvise() is available
try_compile(
MADVISE_SUPPORTED
${CMAKE_BINARY_DIR}
SOURCES "${CMAKE_CURRENT_LIST_DIR}/tests/features/madvise.c"
COMPILE_DEFINITIONS "-Werror"
)

# Determine if minherit() is available
try_compile(
MINHERIT_SUPPORTED
${CMAKE_BINARY_DIR}
SOURCES "${CMAKE_CURRENT_LIST_DIR}/tests/features/minherit.c"
COMPILE_DEFINITIONS "-Werror"
)

# Determine if clone() is available
try_compile(
CLONE_SUPPORTED
${CMAKE_BINARY_DIR}
SOURCES "${CMAKE_CURRENT_LIST_DIR}/tests/features/clone.c"
COMPILE_DEFINITIONS "-Werror"
)

if(APPLE)
set(OS_LIBS c Threads::Threads)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
Expand Down Expand Up @@ -436,6 +460,21 @@ if (__RESTRICT__SUPPORTED)
target_compile_options(${PROJECT_NAME} PUBLIC -DS2N___RESTRICT__SUPPORTED)
endif()

if (MADVISE_SUPPORTED)
target_compile_options(${PROJECT_NAME} PUBLIC -DS2N_MADVISE_SUPPORTED)
message(STATUS "madvise() support detected")
endif()

if (MINHERIT_SUPPORTED)
target_compile_options(${PROJECT_NAME} PUBLIC -DS2N_MINHERIT_SUPPORTED)
message(STATUS "minherit() support detected")
endif()

if (CLONE_SUPPORTED)
target_compile_options(${PROJECT_NAME} PUBLIC -DS2N_CLONE_SUPPORTED)
message(STATUS "clone() support detected")
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

#work around target differences
Expand Down
11 changes: 8 additions & 3 deletions crypto/s2n_drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,14 @@ int s2n_drbg_generate(struct s2n_drbg *drbg, struct s2n_blob *blob)

S2N_ERROR_IF(blob->size > S2N_DRBG_GENERATE_LIMIT, S2N_ERR_DRBG_REQUEST_SIZE);

/* Always mix in additional entropy, for prediction resistance.
If s2n_drbg_mix is removed: must implement reseeding according to limit
specified in NIST SP800-90A 10.2.1 Table 3. */
/* Mix in additional entropy for every randomness generation call. This
* defense mechanism is referred to as "prediction resistance".
* If we ever relax this defense, we must:
* 1. Implement reseeding according to limit specified in
* NIST SP800-90A 10.2.1 Table 3.
* 2. Re-consider whether the current fork detection strategy is still
* sufficient.
*/
POSIX_GUARD(s2n_drbg_mix(drbg, &zeros));
POSIX_GUARD(s2n_drbg_bits(drbg, blob));
POSIX_GUARD(s2n_drbg_update(drbg, &zeros));
Expand Down
3 changes: 3 additions & 0 deletions error/s2n_errno.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ static const char *no_such_error = "Internal s2n error";
ERR_ENTRY(S2N_ERR_KEYING_MATERIAL_EXPIRED, "The lifetime of the connection keying material has exceeded the limit. Perform a new full handshake.") \
ERR_ENTRY(S2N_ERR_EARLY_DATA_TRIAL_DECRYPT, "Unable to decrypt rejected early data") \
ERR_ENTRY(S2N_ERR_PKEY_CTX_INIT, "Unable to initialize the libcrypto pkey context") \
ERR_ENTRY(S2N_ERR_FORK_DETECTION_INIT, "Fork detection initialization failed") \
ERR_ENTRY(S2N_ERR_RETRIEVE_FORK_GENERATION_NUMBER, "Retrieving fork generation number failed") \

/* clang-format on */

#define ERR_STR_CASE(ERR, str) case ERR: return str;
Expand Down
2 changes: 2 additions & 0 deletions error/s2n_errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ typedef enum {
S2N_ERR_INVALID_CERT_STATE,
S2N_ERR_INVALID_EARLY_DATA_STATE,
S2N_ERR_PKEY_CTX_INIT,
S2N_ERR_FORK_DETECTION_INIT,
S2N_ERR_RETRIEVE_FORK_GENERATION_NUMBER,
S2N_ERR_T_INTERNAL_END,

/* S2N_ERR_T_USAGE */
Expand Down
18 changes: 18 additions & 0 deletions s2n.mk
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ ifeq ($(TRY_EVP_MD_CTX_SET_PKEY_CTX), 0)
DEFAULT_CFLAGS += -DS2N_LIBCRYPTO_SUPPORTS_EVP_MD_CTX_SET_PKEY_CTX
endif

# Determine if madvise() is available
TRY_COMPILE_MADVISE := $(call try_compile,$(S2N_ROOT)/tests/features/madvise.c)
ifeq ($(TRY_COMPILE_MADVISE), 0)
DEFAULT_CFLAGS += -DS2N_MADVISE_SUPPORTED
endif

# Determine if minherit() is available
TRY_COMPILE_MINHERIT:= $(call try_compile,$(S2N_ROOT)/tests/features/minherit.c)
ifeq ($(TRY_COMPILE_MINHERIT), 0)
DEFAULT_CFLAGS += -DS2N_MINHERIT_SUPPORTED
endif

# Determine if clone() is available
TRY_COMPILE_CLONE := $(call try_compile,$(S2N_ROOT)/tests/features/clone.c)
ifeq ($(TRY_COMPILE_CLONE), 0)
DEFAULT_CFLAGS += -DS2N_CLONE_SUPPORTED
endif

CFLAGS_LLVM = ${DEFAULT_CFLAGS} -emit-llvm -c -g -O1

$(BITCODE_DIR)%.bc: %.c
Expand Down
24 changes: 24 additions & 0 deletions tests/features/clone.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#define _GNU_SOURCE

#include <sched.h>
#include <stddef.h>

int main() {
clone(NULL, NULL, 0, NULL);
return 0;
}
27 changes: 27 additions & 0 deletions tests/features/madvise.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/* Keep in sync with utils/s2n_fork_detection.c */
#if !defined(__APPLE__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif

#include <stddef.h>
#include <sys/mman.h>

int main() {
madvise(NULL, 0, 0);
return 0;
}
22 changes: 22 additions & 0 deletions tests/features/minherit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include <stddef.h>
#include <sys/mman.h>

int main() {
minherit(NULL, 0, 0);
return 0;
}
Loading