forked from aws/s2n-tls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
363 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: seccomp | ||
on: | ||
pull_request: | ||
branches: [main] | ||
merge_group: | ||
types: [checks_requested] | ||
branches: [main] | ||
|
||
jobs: | ||
ubuntu: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: install dependencies | ||
run: | | ||
sudo apt update | ||
sudo apt install cmake | ||
# For default libcrypto | ||
sudo apt install libssl-dev | ||
# For seccomp | ||
sudo apt install libseccomp-dev | ||
# For aws-lc | ||
sudo apt install clang golang | ||
- name: checkout s2n-tls | ||
uses: actions/checkout@v4 | ||
|
||
- name: checkout aws-lc | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: aws/aws-lc | ||
path: awslc | ||
|
||
- name: build awslc | ||
# See https://github.com/aws/aws-lc/blob/main/BUILDING.md#building | ||
working-directory: awslc | ||
run: | | ||
cmake -B build | ||
make -C build | ||
cmake --install build --prefix install | ||
- name: seccomp with default libcrypto | ||
# TODO: There are still issues with openssl running with seccomp. | ||
# Disable for now. | ||
if: false | ||
run: | | ||
cmake -Bbuild \ | ||
-DSECCOMP=1 \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_INSTALL_PREFIX=install | ||
cmake --build build -j $(nproc) | ||
CTEST_PARALLEL_LEVEL=$(nproc) ctest --test-dir build | ||
cmake --install build | ||
./build/bin/s2nc localhost 8000 | grep "libcrypto" | grep -v "AWS-LC" | ||
rm -rf build | ||
- name: seccomp with aws-lc | ||
run: | | ||
cmake -Bbuild \ | ||
-DSECCOMP=1 \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_PREFIX_PATH=awslc/install \ | ||
-DCMAKE_INSTALL_PREFIX=install | ||
cmake --build build -j $(nproc) | ||
CTEST_PARALLEL_LEVEL=$(nproc) ctest --test-dir build | ||
cmake --install build | ||
./build/bin/s2nc localhost 8000 | grep "libcrypto" | grep "AWS-LC" | ||
rm -rf build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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 "testlib/s2n_testlib.h" | ||
#include "utils/s2n_safety.h" | ||
|
||
#ifdef SECCOMP | ||
|
||
#include <seccomp.h> | ||
|
||
DEFINE_POINTER_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release); | ||
|
||
extern bool s2n_use_color_in_output; | ||
|
||
bool s2n_is_seccomp_supported() | ||
{ | ||
return true; | ||
} | ||
|
||
/* "seccomp" allows the kernel to control what system calls an application | ||
* is allowed to make based on a provided filter. | ||
* | ||
* seccomp is commonly used for "sandboxing" programs for security reasons. | ||
*/ | ||
S2N_RESULT s2n_seccomp_init() | ||
{ | ||
/* Using SCMP_ACT_TRAP instead of SCMP_ACT_KILL as the default action | ||
* makes this test easier to debug. GDB can be used to debug failures caused | ||
* by SCMP_ACT_TRAP, but not caused by SCMP_ACT_KILL. | ||
*/ | ||
DEFER_CLEANUP(scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_TRAP), | ||
seccomp_release_pointer); | ||
RESULT_ENSURE_REF(ctx); | ||
|
||
/* Basic requirements: s2n-tls is known to need these system calls in order | ||
* to operate. Adding a new system call to this list means that any application | ||
* using s2n-tls with seccomp will potentially also need to update its filter rules. | ||
* | ||
* Do not add any variation of "open" to this list. One of the primary reasons | ||
* that an application would choose to use seccomp is to prevent opening files, | ||
* similar to chroot. | ||
*/ | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(access), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(clock_gettime), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fstat), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getrandom), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0)); | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0)); | ||
|
||
/* Ubuntu22 uses "newfstatat" instead of "fstat" */ | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(newfstatat), 0)); | ||
|
||
/* See https://github.com/aws/aws-lc/blob/main/SANDBOXING.md#fork-protection: | ||
* We can just cause the madavise call to fail rather than blocking it entirely. */ | ||
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EINVAL), SCMP_SYS(madvise), 0)); | ||
|
||
/* Checking whether the terminal supports color requires an additional | ||
* system call. Preemptively disable color. | ||
*/ | ||
s2n_use_color_in_output = false; | ||
|
||
RESULT_GUARD_POSIX(seccomp_load(ctx)); | ||
return S2N_RESULT_OK; | ||
} | ||
|
||
#else | ||
|
||
bool s2n_is_seccomp_supported() | ||
{ | ||
return false; | ||
} | ||
|
||
S2N_RESULT s2n_seccomp_init() | ||
{ | ||
return S2N_RESULT_OK; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 <signal.h> | ||
#include <stdio.h> | ||
#include <sys/stat.h> | ||
|
||
#include "s2n_test.h" | ||
#include "testlib/s2n_testlib.h" | ||
|
||
bool s2n_fstat_success = false; | ||
bool s2n_open_success = false; | ||
|
||
void s2n_detect_open_violation(int sig) | ||
{ | ||
EXPECT_EQUAL(sig, SIGSYS); | ||
|
||
EXPECT_TRUE(s2n_fstat_success); | ||
EXPECT_FALSE(s2n_open_success); | ||
|
||
END_TEST_PRINT(); | ||
exit(0); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
BEGIN_TEST(); | ||
|
||
if (!s2n_is_seccomp_supported()) { | ||
END_TEST(); | ||
} | ||
|
||
const struct sigaction action = { | ||
.sa_handler = s2n_detect_open_violation, | ||
}; | ||
EXPECT_EQUAL(sigaction(SIGSYS, &action, NULL), 0); | ||
|
||
EXPECT_OK(s2n_seccomp_init()); | ||
|
||
/* The seccomp filter allows fstat */ | ||
struct stat st = { 0 }; | ||
EXPECT_SUCCESS(fstat(0, &st)); | ||
s2n_fstat_success = true; | ||
|
||
/* The seccomp filter does NOT allow open */ | ||
FILE *file = fopen(S2N_DEFAULT_TEST_CERT_CHAIN, "r"); | ||
s2n_open_success = true; | ||
EXPECT_NOT_NULL(file); | ||
|
||
FAIL_MSG("test unexpectedly succeeded"); | ||
} |
Oops, something went wrong.