Skip to content

Add test for snapsafe ensuring read permission failure is not silent #2494

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions crypto/fipsmodule/rand/snapsafe_detect_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ TEST(SnapsafeGenerationTest, DISABLED_SysGenIDretrievalTesting) {
EXPECT_EQ(new_sysgenid_value_hint, current_snapsafe_gen_num);
}
}

// This test verifies that AWS-LC properly handles the case where /dev/sysgenid
// exists but cannot be opened due to permission restrictions.
TEST(SnapsafePermissionTest, DISABLED_PermissionDeniedTest) {
// Verify the file was created and initially accessible
const char* sysgenid_path = CRYPTO_get_sysgenid_path();
struct stat file_stat;
ASSERT_EQ(0, stat(sysgenid_path, &file_stat));

// Make file unreadable by anyone
ASSERT_EQ(0, chmod(sysgenid_path, 0000));

// There is support, but it's not active due to read failure
EXPECT_EQ(1, CRYPTO_get_snapsafe_supported());
EXPECT_EQ(0, CRYPTO_get_snapsafe_active());

// Should return 0 (failure) and set generation number to 0
uint32_t gen_num = 0xFFFFFFFF;
EXPECT_EQ(0, CRYPTO_get_snapsafe_generation(&gen_num));
EXPECT_EQ(0U, gen_num);
}

#elif defined(OPENSSL_LINUX)
TEST(SnapsafeGenerationTest, SysGenIDretrievalLinux) {
uint32_t current_snapsafe_gen_num = 0xffffffff;
Expand Down
6 changes: 6 additions & 0 deletions util/all_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"skip_valgrind": true,
"target_arch": "x86"
},
{
"comment": "Run snapsafe permissions test suite",
"cmd": ["crypto/crypto_test", "--gtest_also_run_disabled_tests", "--gtest_filter=SnapsafePermissionTest.*"],
"skip_valgrind": true,
"shard": false
},
{
"comment": "Run snapsafe detection test suite",
"cmd": ["crypto/crypto_test", "--gtest_also_run_disabled_tests", "--gtest_filter=SnapsafeGenerationTest.*"],
Expand Down
Loading