diff --git a/crypto/fipsmodule/rand/snapsafe_detect.c b/crypto/fipsmodule/rand/snapsafe_detect.c index dee46c3aa1..430445d06c 100644 --- a/crypto/fipsmodule/rand/snapsafe_detect.c +++ b/crypto/fipsmodule/rand/snapsafe_detect.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "../delocate.h" @@ -21,28 +22,18 @@ DEFINE_STATIC_ONCE(aws_snapsafe_init) DEFINE_BSS_GET(volatile uint32_t *, sgc_addr) DEFINE_BSS_GET(int, snapsafety_state) -// aws_snapsafe_check_kernel_support returns 1 if the special sysgenid device -// file exists and 0 otherwise. -static int aws_snapsafe_check_kernel_support(void) { - // This file-exist method is generally brittle. But for our purpose, this - // should be more than fine. - if (access(CRYPTO_get_sysgenid_path(), F_OK) != 0) { - return 0; - } - return 1; -} - static void do_aws_snapsafe_init(void) { - *snapsafety_state_bss_get() = SNAPSAFETY_STATE_NOT_SUPPORTED; *sgc_addr_bss_get() = NULL; + *snapsafety_state_bss_get() = SNAPSAFETY_STATE_NOT_SUPPORTED; - if (aws_snapsafe_check_kernel_support() != 1) { + struct stat buff; + if (stat(CRYPTO_get_sysgenid_path(), &buff) != 0) { return; } - *snapsafety_state_bss_get() = SNAPSAFETY_STATE_FAILED_INITIALISE; + *snapsafety_state_bss_get() = SNAPSAFETY_STATE_FAILED_INITIALISE; int fd_sgc = open(CRYPTO_get_sysgenid_path(), O_RDONLY); - if (fd_sgc == -1) { + if (fd_sgc < 0) { return; }