binfmt_misc01.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. #
  4. # Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  5. # Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
  6. #
  7. # Description:
  8. # Use various invalid inputs to register a new binary type.
  9. # 1) Invalid format of string fails to register a new binary type.
  10. # 2) Invalid type fails to register a new binary type.
  11. # 3) Invalid name containing slashes fails to register a new
  12. # binary type.
  13. # 4) If extension matching is chosen, invalid magic containing
  14. # slashes fails to register a new binary type.
  15. # 5) If magic matching is chosen, invalid offset(e.g. -1 and
  16. # 2500000000) fails to register a new binary type.
  17. # 6) Invalid flag fails to register a new binary type.
  18. #
  19. # Note:
  20. # This is also a regression test for the following kernel bug:
  21. # '5cc41e099504 ("fs/binfmt_misc.c: do not allow offset overflow")'
  22. TST_CNT=9
  23. TST_TESTFUNC=do_test
  24. TST_NEEDS_CMDS="cat"
  25. . binfmt_misc_lib.sh
  26. verify_binfmt_misc()
  27. {
  28. local name=$(echo "$1" | awk -F ':' '{print $2}')
  29. local mntpoint=$(get_binfmt_misc_mntpoint)
  30. (echo "$1" >"$mntpoint/register") 2>/dev/null
  31. if [ $? -ne 0 -a ! -f "$mntpoint/$name" ]; then
  32. tst_res TPASS "Failed to register a binary type"
  33. return
  34. fi
  35. # Trigger kernel crash reliably by cat command.
  36. cat "$mntpoint/$name" >/dev/null 2>&1
  37. tst_res TFAIL "Register a binary type successfully"
  38. [ -f "$mntpoint/$name" ] && \
  39. remove_binary_type "$mntpoint/$name"
  40. }
  41. do_test()
  42. {
  43. case $1 in
  44. 1) verify_binfmt_misc ".textension,E,,ltp,,$(which cat),";;
  45. 2) verify_binfmt_misc ":tnone:X::ltp::$(which cat):";;
  46. 3) verify_binfmt_misc ":textension/:E::ltp::$(which cat):";;
  47. 4) verify_binfmt_misc ":tmagic/:M::ltp::$(which cat):";;
  48. 5) verify_binfmt_misc ":textension:E::ltp/::$(which cat):";;
  49. 6) verify_binfmt_misc ":tmagic:M:-1:ltp::$(which cat):";;
  50. 7) verify_binfmt_misc ":tmagic:M:2500000000:ltp::$(which cat):";;
  51. 8) verify_binfmt_misc ":textension:E::ltp::$(which cat):A";;
  52. 9) verify_binfmt_misc ":tmagic:M::ltp::$(which cat):A";;
  53. esac
  54. }
  55. tst_run