1*e4a36f41SAndroid Build Coastguard Worker# System and vendor domains for BoringSSL self test binaries. 2*e4a36f41SAndroid Build Coastguard Worker# 3*e4a36f41SAndroid Build Coastguard Worker# For FIPS compliance, all processes linked against libcrypto perform a startup 4*e4a36f41SAndroid Build Coastguard Worker# self test which computes a hash of the BoringSSL Crypto Module (BCM) and, at least once 5*e4a36f41SAndroid Build Coastguard Worker# per device boot, also run a series of Known Answer Tests (KAT) to verify functionality. 6*e4a36f41SAndroid Build Coastguard Worker# 7*e4a36f41SAndroid Build Coastguard Worker# The KATs are expensive, and to ensure they are run as few times as possible, they 8*e4a36f41SAndroid Build Coastguard Worker# are skipped if a marker file exists in /dev/boringssl/selftest whose name is 9*e4a36f41SAndroid Build Coastguard Worker# the hash of the BCM that was computed earlier. The files are zero length and their contents 10*e4a36f41SAndroid Build Coastguard Worker# should never be read or written. To avoid giving arbitrary processes access to /dev/boringssl 11*e4a36f41SAndroid Build Coastguard Worker# to create these marker files, there are dedicated self test binaries which this policy 12*e4a36f41SAndroid Build Coastguard Worker# gives access to and which are run during early-init. 13*e4a36f41SAndroid Build Coastguard Worker# 14*e4a36f41SAndroid Build Coastguard Worker# Due to build skew, the version of libcrypto in /vendor may have a different hash than 15*e4a36f41SAndroid Build Coastguard Worker# the system one. To cater for this there are vendor variants of the self test binaries 16*e4a36f41SAndroid Build Coastguard Worker# which also have permission to write to the same files in /dev/boringssl. In the case where 17*e4a36f41SAndroid Build Coastguard Worker# vendor and system libcrypto have the same hash, there will be a race to create the file, 18*e4a36f41SAndroid Build Coastguard Worker# but this is harmless. 19*e4a36f41SAndroid Build Coastguard Worker# 20*e4a36f41SAndroid Build Coastguard Worker# If the self tests fail, then the device should reboot into firmware and for this reason 21*e4a36f41SAndroid Build Coastguard Worker# the system boringssl_self_test domain needs to be in coredomain. As vendor domains 22*e4a36f41SAndroid Build Coastguard Worker# are not allowed in coredomain, this means that the vendor self tests cannot trigger a 23*e4a36f41SAndroid Build Coastguard Worker# reboot. However every binary linked against the vendor libcrypto will abort on startup, 24*e4a36f41SAndroid Build Coastguard Worker# so in practice the device will crash anyway in this unlikely scenario. 25*e4a36f41SAndroid Build Coastguard Worker 26*e4a36f41SAndroid Build Coastguard Worker# System boringssl_self_test domain 27*e4a36f41SAndroid Build Coastguard Workertype boringssl_self_test, domain, coredomain; 28*e4a36f41SAndroid Build Coastguard Workertype boringssl_self_test_exec, system_file_type, exec_type, file_type; 29*e4a36f41SAndroid Build Coastguard Worker 30*e4a36f41SAndroid Build Coastguard Worker# Vendor boringssl_self_test domain 31*e4a36f41SAndroid Build Coastguard Workertype vendor_boringssl_self_test, domain; 32*e4a36f41SAndroid Build Coastguard Workertype vendor_boringssl_self_test_exec, vendor_file_type, exec_type, file_type; 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Worker# Switch to boringssl_self_test security domain when running boringssl_self_test_exec 35*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(boringssl_self_test) 36*e4a36f41SAndroid Build Coastguard Worker 37*e4a36f41SAndroid Build Coastguard Worker# Switch to vendor_boringssl_self_test security domain when running vendor_boringssl_self_test_exec 38*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(vendor_boringssl_self_test) 39*e4a36f41SAndroid Build Coastguard Worker 40*e4a36f41SAndroid Build Coastguard Worker# Marker files, common to both domains, indicating KAT have been performed on a particular libcrypto 41*e4a36f41SAndroid Build Coastguard Worker# 42*e4a36f41SAndroid Build Coastguard Worker# The files are zero length so there is no issue if both vendor and system code 43*e4a36f41SAndroid Build Coastguard Worker# try to create the same file simultaneously. One will succeed and the other will fail 44*e4a36f41SAndroid Build Coastguard Worker# silently, i.e. still indicate success. Similar harmless naming collisions will happen in the 45*e4a36f41SAndroid Build Coastguard Worker# system domain e.g. when system and APEX copies of libcrypto are identical. 46*e4a36f41SAndroid Build Coastguard Workertype boringssl_self_test_marker, file_type; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# Allow self test binaries to create/check for the existence of boringssl_self_test_marker files 49*e4a36f41SAndroid Build Coastguard Workerallow { boringssl_self_test vendor_boringssl_self_test } 50*e4a36f41SAndroid Build Coastguard Worker boringssl_self_test_marker:file create_file_perms; 51*e4a36f41SAndroid Build Coastguard Workerallow { boringssl_self_test vendor_boringssl_self_test } 52*e4a36f41SAndroid Build Coastguard Worker boringssl_self_test_marker:dir ra_dir_perms; 53*e4a36f41SAndroid Build Coastguard Worker 54*e4a36f41SAndroid Build Coastguard Worker# Allow self test binaries to write their stdout/stderr messages to kmsg_debug 55*e4a36f41SAndroid Build Coastguard Workerallow { boringssl_self_test vendor_boringssl_self_test } 56*e4a36f41SAndroid Build Coastguard Worker kmsg_debug_device:chr_file { w_file_perms getattr ioctl }; 57*e4a36f41SAndroid Build Coastguard Worker 58*e4a36f41SAndroid Build Coastguard Worker# No other process should be able to create marker files because their existence causes the 59*e4a36f41SAndroid Build Coastguard Worker# boringssl KAT to be skipped. 60*e4a36f41SAndroid Build Coastguard Workerneverallow { 61*e4a36f41SAndroid Build Coastguard Worker domain 62*e4a36f41SAndroid Build Coastguard Worker -vendor_boringssl_self_test 63*e4a36f41SAndroid Build Coastguard Worker -boringssl_self_test 64*e4a36f41SAndroid Build Coastguard Worker -init 65*e4a36f41SAndroid Build Coastguard Worker -vendor_init 66*e4a36f41SAndroid Build Coastguard Worker} boringssl_self_test_marker:file no_rw_file_perms; 67*e4a36f41SAndroid Build Coastguard Worker 68*e4a36f41SAndroid Build Coastguard Workerneverallow { 69*e4a36f41SAndroid Build Coastguard Worker domain 70*e4a36f41SAndroid Build Coastguard Worker -vendor_boringssl_self_test 71*e4a36f41SAndroid Build Coastguard Worker -boringssl_self_test 72*e4a36f41SAndroid Build Coastguard Worker -init 73*e4a36f41SAndroid Build Coastguard Worker -vendor_init 74*e4a36f41SAndroid Build Coastguard Worker} boringssl_self_test_marker:dir write; 75