evm_overlay.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
  4. # Based on reproducer and further discussion with Ignaz Forster <iforster@suse.de>
  5. # Reproducer for not upstreamed patchset [1] and previous report [2].
  6. # [1] https://www.spinics.net/lists/linux-integrity/msg05926.html
  7. # [2] https://www.spinics.net/lists/linux-integrity/msg03593.html
  8. TST_SETUP="setup"
  9. TST_CLEANUP="cleanup"
  10. TST_NEEDS_DEVICE=1
  11. TST_CNT=4
  12. . ima_setup.sh
  13. setup()
  14. {
  15. EVM_FILE="/sys/kernel/security/evm"
  16. [ -f "$EVM_FILE" ] || tst_brk TCONF "EVM not enabled in kernel"
  17. [ $(cat $EVM_FILE) -eq 1 ] || tst_brk TCONF "EVM not enabled for this boot"
  18. require_ima_policy_cmdline "appraise_tcb"
  19. lower="$TST_MNTPOINT/lower"
  20. upper="$TST_MNTPOINT/upper"
  21. work="$TST_MNTPOINT/work"
  22. merged="$TST_MNTPOINT/merged"
  23. mkdir -p $lower $upper $work $merged
  24. device_backup="$TST_DEVICE"
  25. TST_DEVICE="overlay"
  26. fs_type_backup="$TST_FS_TYPE"
  27. TST_FS_TYPE="overlay"
  28. mntpoint_backup="$TST_MNTPOINT"
  29. TST_MNTPOINT="$merged"
  30. params_backup="$TST_MNT_PARAMS"
  31. TST_MNT_PARAMS="-o lowerdir=$lower,upperdir=$upper,workdir=$work"
  32. tst_mount
  33. mounted=1
  34. }
  35. test1()
  36. {
  37. local file="foo1.txt"
  38. tst_res TINFO "overwrite file in overlay"
  39. EXPECT_PASS echo lower \> $lower/$file
  40. EXPECT_PASS echo overlay \> $merged/$file
  41. }
  42. test2()
  43. {
  44. local file="foo2.txt"
  45. tst_res TINFO "append file in overlay"
  46. EXPECT_PASS echo lower \> $lower/$file
  47. EXPECT_PASS echo overlay \>\> $merged/$file
  48. }
  49. test3()
  50. {
  51. local file="foo3.txt"
  52. tst_res TINFO "create a new file in overlay"
  53. EXPECT_PASS echo overlay \> $merged/$file
  54. }
  55. test4()
  56. {
  57. local f
  58. tst_res TINFO "read all created files"
  59. for f in $(find $TST_MNTPOINT -type f); do
  60. EXPECT_PASS cat $f \> /dev/null 2\> /dev/null
  61. done
  62. }
  63. cleanup()
  64. {
  65. [ -n "$mounted" ] || return 0
  66. tst_umount $TST_DEVICE
  67. TST_DEVICE="$device_backup"
  68. TST_FS_TYPE="$fs_type_backup"
  69. TST_MNTPOINT="$mntpoint_backup"
  70. TST_MNT_PARAMS="$params_backup"
  71. }
  72. tst_run