TestKernelUnveil.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <unistd.h>
  8. TEST_CASE(test_failures)
  9. {
  10. auto res = unveil("/etc", "r");
  11. if (res < 0)
  12. FAIL("unveil read only failed");
  13. res = unveil("/etc", "w");
  14. if (res >= 0)
  15. FAIL("unveil write permitted after unveil read only");
  16. res = unveil("/etc", "x");
  17. if (res >= 0)
  18. FAIL("unveil execute permitted after unveil read only");
  19. res = unveil("/etc", "c");
  20. if (res >= 0)
  21. FAIL("unveil create permitted after unveil read only");
  22. res = unveil("/tmp/doesnotexist", "c");
  23. if (res < 0)
  24. FAIL("unveil create on non-existent path failed");
  25. res = unveil("/home", "b");
  26. if (res < 0)
  27. FAIL("unveil browse failed");
  28. res = unveil("/home", "w");
  29. if (res >= 0)
  30. FAIL("unveil write permitted after unveil browse only");
  31. res = unveil("/home", "x");
  32. if (res >= 0)
  33. FAIL("unveil execute permitted after unveil browse only");
  34. res = unveil("/home", "c");
  35. if (res >= 0)
  36. FAIL("unveil create permitted after unveil browse only");
  37. res = unveil(nullptr, nullptr);
  38. if (res < 0)
  39. FAIL("unveil state lock failed");
  40. res = unveil("/bin", "w");
  41. if (res >= 0)
  42. FAIL("unveil permitted after unveil state locked");
  43. res = access("/bin/id", F_OK);
  44. if (res == 0)
  45. FAIL("access(..., F_OK) permitted after locked veil without relevant unveil");
  46. }