rodata_test.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * rodata_test.c: functional test for mark_rodata_ro function
  3. *
  4. * (C) Copyright 2008 Intel Corporation
  5. * Author: Arjan van de Ven <arjan@linux.intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2
  10. * of the License.
  11. */
  12. #define pr_fmt(fmt) "rodata_test: " fmt
  13. #include <linux/uaccess.h>
  14. #include <asm/sections.h>
  15. static const int rodata_test_data = 0xC3;
  16. void rodata_test(void)
  17. {
  18. unsigned long start, end;
  19. int zero = 0;
  20. /* test 1: read the value */
  21. /* If this test fails, some previous testrun has clobbered the state */
  22. if (!rodata_test_data) {
  23. pr_err("test 1 fails (start data)\n");
  24. return;
  25. }
  26. /* test 2: write to the variable; this should fault */
  27. if (!probe_kernel_write((void *)&rodata_test_data,
  28. (void *)&zero, sizeof(zero))) {
  29. pr_err("test data was not read only\n");
  30. return;
  31. }
  32. /* test 3: check the value hasn't changed */
  33. if (rodata_test_data == zero) {
  34. pr_err("test data was changed\n");
  35. return;
  36. }
  37. /* test 4: check if the rodata section is PAGE_SIZE aligned */
  38. start = (unsigned long)__start_rodata;
  39. end = (unsigned long)__end_rodata;
  40. if (start & (PAGE_SIZE - 1)) {
  41. pr_err("start of .rodata is not page size aligned\n");
  42. return;
  43. }
  44. if (end & (PAGE_SIZE - 1)) {
  45. pr_err("end of .rodata is not page size aligned\n");
  46. return;
  47. }
  48. pr_info("all tests were successful\n");
  49. }