inject-ra-err.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include <signal.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/ioctl.h>
  8. #include <sys/mman.h>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12. #include "vas-api.h"
  13. #include "utils.h"
  14. static bool faulted;
  15. static void sigbus_handler(int n, siginfo_t *info, void *ctxt_v)
  16. {
  17. ucontext_t *ctxt = (ucontext_t *)ctxt_v;
  18. struct pt_regs *regs = ctxt->uc_mcontext.regs;
  19. faulted = true;
  20. regs->nip += 4;
  21. }
  22. static int test_ra_error(void)
  23. {
  24. struct vas_tx_win_open_attr attr;
  25. int fd, *paste_addr;
  26. char *devname = "/dev/crypto/nx-gzip";
  27. struct sigaction act = {
  28. .sa_sigaction = sigbus_handler,
  29. .sa_flags = SA_SIGINFO,
  30. };
  31. memset(&attr, 0, sizeof(attr));
  32. attr.version = 1;
  33. attr.vas_id = 0;
  34. SKIP_IF(access(devname, F_OK));
  35. fd = open(devname, O_RDWR);
  36. FAIL_IF(fd < 0);
  37. FAIL_IF(ioctl(fd, VAS_TX_WIN_OPEN, &attr) < 0);
  38. FAIL_IF(sigaction(SIGBUS, &act, NULL) != 0);
  39. paste_addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0ULL);
  40. /* The following assignment triggers exception */
  41. mb();
  42. *paste_addr = 1;
  43. mb();
  44. FAIL_IF(!faulted);
  45. return 0;
  46. }
  47. int main(void)
  48. {
  49. return test_harness(test_ra_error, "inject-ra-err");
  50. }