Path: blob/main/tests/sys/geom/class/eli/integrity_test.sh
39635 views
1. $(atf_get_srcdir)/conf.sh23copy_test() {4cipher=$15aalgo=$26secsize=$37ealgo=${cipher%%:*}8keylen=${cipher##*:}910atf_check -s exit:0 -e ignore \11geli init -B none -a $aalgo -e $ealgo -l $keylen -P \12-K keyfile -s $secsize ${md}13atf_check geli attach -p -k keyfile ${md}1415atf_check dd if=rnd of=/dev/${md}.eli bs=${secsize} count=1 status=none1617# Copy first small sector to the second small sector.18# This should be detected as corruption.19atf_check dd if=backing_file of=sector bs=512 count=1 \20conv=notrunc status=none21atf_check dd if=sector of=backing_file bs=512 count=1 seek=1 \22conv=notrunc status=none2324atf_check -s not-exit:0 -e ignore \25dd if=/dev/${md}.eli of=/dev/null bs=${secsize} count=12627# Fix the corruption28atf_check dd if=rnd of=/dev/${md}.eli bs=${secsize} count=2 status=none29atf_check dd if=/dev/${md}.eli of=/dev/null bs=${secsize} count=2 \30status=none3132# Copy first big sector to the second big sector.33# This should be detected as corruption.34ms=`diskinfo /dev/${md} | awk '{print $3 - 512}'`35ns=`diskinfo /dev/${md}.eli | awk '{print $4}'`36usecsize=`echo "($ms / $ns) - (($ms / $ns) % 512)" | bc`37atf_check dd if=backing_file bs=512 count=$(( ${usecsize} / 512 )) \38seek=$(( $secsize / 512 )) of=sector conv=notrunc status=none39atf_check dd of=backing_file bs=512 count=$(( ${usecsize} / 512 )) \40seek=$(( $secsize / 256 )) if=sector conv=notrunc status=none41atf_check -s not-exit:0 -e ignore \42dd if=/dev/${md}.eli of=/dev/null bs=${secsize} count=$ns43}4445atf_test_case copy cleanup46copy_head()47{48atf_set "descr" "geli will detect misdirected writes as corruption"49atf_set "require.user" "root"50atf_set "timeout" 360051}52copy_body()53{54geli_test_setup5556sectors=25758atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none59dd if=/dev/random of=rnd bs=${MAX_SECSIZE} count=${sectors} status=none6061for_each_geli_config copy_test backing_file62}63copy_cleanup()64{65geli_test_cleanup66}676869data_test() {70cipher=$171aalgo=$272secsize=$373ealgo=${cipher%%:*}74keylen=${cipher##*:}7576atf_check -s exit:0 -e ignore \77geli init -B none -a $aalgo -e $ealgo -l $keylen -P -K keyfile \78-s $secsize ${md}7980# Corrupt 8 bytes of data.81atf_check dd if=/dev/${md} of=sector bs=512 count=1 status=none82atf_check dd if=rnd of=sector bs=1 count=8 seek=64 conv=notrunc status=none83atf_check dd if=sector of=/dev/${md} bs=512 count=1 status=none84atf_check geli attach -p -k keyfile ${md}8586# Try to read from the corrupt sector87atf_check -s not-exit:0 -e ignore \88dd if=/dev/${md}.eli of=/dev/null bs=${secsize} count=189}9091atf_test_case data cleanup92data_head()93{94atf_set "descr" "With HMACs, geli will detect data corruption"95atf_set "require.user" "root"96atf_set "timeout" 180097}98data_body()99{100geli_test_setup101102sectors=2103104atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none105dd if=/dev/random of=rnd bs=${MAX_SECSIZE} count=${sectors} status=none106for_each_geli_config data_test107}108data_cleanup()109{110geli_test_cleanup111}112113hmac_test() {114cipher=$1115aalgo=$2116secsize=$3117ealgo=${cipher%%:*}118keylen=${cipher##*:}119120atf_check -s exit:0 -e ignore \121geli init -B none -a $aalgo -e $ealgo -l $keylen -P -K keyfile \122-s $secsize ${md}123124# Corrupt 8 bytes of HMAC.125atf_check dd if=/dev/${md} of=sector bs=512 count=1 status=none126atf_check dd if=rnd of=sector bs=1 count=16 conv=notrunc status=none127atf_check dd if=sector of=/dev/${md} bs=512 count=1 status=none128atf_check geli attach -p -k keyfile ${md}129130# Try to read from the corrupt sector131atf_check -s not-exit:0 -e ignore \132dd if=/dev/${md}.eli of=/dev/null bs=${secsize} count=1133}134135atf_test_case hmac cleanup136hmac_head()137{138atf_set "descr" "geli will detect corruption of HMACs"139atf_set "require.user" "root"140atf_set "timeout" 1800141}142hmac_body()143{144geli_test_setup145146sectors=2147148atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none149dd if=/dev/random of=rnd bs=${MAX_SECSIZE} count=${sectors} status=none150for_each_geli_config hmac_test151}152hmac_cleanup()153{154geli_test_cleanup155}156157atf_init_test_cases()158{159atf_add_test_case copy160atf_add_test_case data161atf_add_test_case hmac162}163164165