|
| 1 | +# Testing of handler for /proc/sys/kernel/random |
| 2 | + |
| 3 | +load ../helpers/fs |
| 4 | +load ../helpers/run |
| 5 | +load ../helpers/uuid |
| 6 | +load ../helpers/sysbox |
| 7 | +load ../helpers/sysbox-health |
| 8 | + |
| 9 | +function setup() { |
| 10 | + setup_busybox |
| 11 | +} |
| 12 | + |
| 13 | +function teardown() { |
| 14 | + teardown_busybox syscont |
| 15 | + sysbox_log_check |
| 16 | +} |
| 17 | + |
| 18 | +@test "/proc/sys/kernel/random/uuid lookup() operation" { |
| 19 | + sv_runc run -d --console-socket $CONSOLE_SOCKET syscont |
| 20 | + [ "$status" -eq 0 ] |
| 21 | + |
| 22 | + sv_runc exec syscont sh -c "ls -lrt /proc/sys/kernel/random/uuid" |
| 23 | + [ "$status" -eq 0 ] |
| 24 | + |
| 25 | + verify_root_ro "${output}" |
| 26 | +} |
| 27 | + |
| 28 | +@test "/proc/sys/kernel/random/uuid read" { |
| 29 | + sv_runc run -d --console-socket $CONSOLE_SOCKET syscont |
| 30 | + [ "$status" -eq 0 ] |
| 31 | + |
| 32 | + sv_runc exec syscont sh -c "cat /proc/sys/kernel/random/uuid" |
| 33 | + [ "$status" -eq 0 ] |
| 34 | + |
| 35 | + is_valid_uuid "$output" |
| 36 | +} |
| 37 | + |
| 38 | +@test "/proc/sys/kernel/random/uuid read unique each time" { |
| 39 | + sv_runc run -d --console-socket $CONSOLE_SOCKET syscont |
| 40 | + [ "$status" -eq 0 ] |
| 41 | + |
| 42 | + declare -A uuid_map |
| 43 | + |
| 44 | + for i in $(seq 1 10); do |
| 45 | + sv_runc exec syscont sh -c "cat /proc/sys/kernel/random/uuid" |
| 46 | + [ "$status" -eq 0 ] |
| 47 | + |
| 48 | + uuid=$output |
| 49 | + is_valid_uuid "$uuid" |
| 50 | + |
| 51 | + # check we haven't seen this uuid before |
| 52 | + [[ -z ${uuid_map[$uuid]} ]] |
| 53 | + |
| 54 | + uuid_map[$uuid]=1 |
| 55 | + done |
| 56 | +} |
| 57 | + |
| 58 | +@test "/proc/sys/kernel/random/uuid write" { |
| 59 | + sv_runc run -d --console-socket $CONSOLE_SOCKET syscont |
| 60 | + [ "$status" -eq 0 ] |
| 61 | + |
| 62 | + sv_runc exec syscont sh -c "echo 0 > /proc/sys/kernel/random/uuid" |
| 63 | + [ "$status" -ne 0 ] |
| 64 | +} |
| 65 | + |
| 66 | +@test "/proc/sys/kernel/random dir" { |
| 67 | + sv_runc run -d --console-socket $CONSOLE_SOCKET syscont |
| 68 | + [ "$status" -eq 0 ] |
| 69 | + |
| 70 | + # check number of files in the container's /proc/sys/kernel/random matches host |
| 71 | + sv_runc exec syscont sh -c "ls -l /proc/sys/kernel/random/uuid | wc -l" |
| 72 | + [ "$status" -eq 0 ] |
| 73 | + cnum=$output |
| 74 | + hnum=$(ls -l /proc/sys/kernel/random/uuid | wc -l) |
| 75 | + [ $cnum -eq $hnum ] |
| 76 | + |
| 77 | + # read from each of the files in /proc/sys/kernel/random (except uuid), and |
| 78 | + # compare the one in the host to the corresponding one in the container. |
| 79 | + for file in /proc/sys/kernel/random/*; do |
| 80 | + if [[ $(basename "$file") == "uuid" ]]; then |
| 81 | + continue |
| 82 | + fi |
| 83 | + |
| 84 | + if [[ -r "$file" ]]; then |
| 85 | + hfile=$(cat "$file") |
| 86 | + |
| 87 | + sv_runc exec syscont sh -c "cat $file" |
| 88 | + [ "$status" -eq 0 ] |
| 89 | + cfile=$output |
| 90 | + |
| 91 | + echo "hfile = $hfile" |
| 92 | + echo "cfile = $cfile" |
| 93 | + |
| 94 | + [[ "$hfile" == "$cfile" ]] |
| 95 | + fi |
| 96 | + done |
| 97 | + |
| 98 | + # check that writes to files in /proc/sys/kernel/random (except uuid) fail |
| 99 | + # with EPERM. |
| 100 | + for file in /proc/sys/kernel/random/*; do |
| 101 | + if [[ $(basename "$file") == "uuid" ]]; then |
| 102 | + continue |
| 103 | + fi |
| 104 | + sv_runc exec syscont sh -c "echo 0 > $file" |
| 105 | + [ "$status" -ne 0 ] |
| 106 | + done |
| 107 | + |
| 108 | +} |
0 commit comments