0026-harness-Fix-PROT_WRITE-mmap-check.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From 711c0381798c85f3e25ea0ab503b24857850a762 Mon Sep 17 00:00:00 2001
  2. From: Guillem Jover <guillem@hadrons.org>
  3. Date: Wed, 14 Aug 2019 04:42:42 +0200
  4. Subject: [PATCH libaio 26/28] harness: Fix PROT_WRITE mmap check
  5. This partially reverts commit d7f5065448efb49b2a26e728ff735e12ea05b62e.
  6. The actual problem in the original code was that read() was being used
  7. to assert whether the buffer was readable, but the kernel was instead
  8. reading from the file descriptor and then writing into the buffer, so
  9. no EFAULT was being generated (on architectures that do so).
  10. We needed to use a write() so that the kernel would read from the
  11. buffer.
  12. Signed-off-by: Guillem Jover <guillem@hadrons.org>
  13. Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
  14. ---
  15. harness/cases/5.t | 9 ++++-----
  16. 1 file changed, 4 insertions(+), 5 deletions(-)
  17. diff --git a/harness/cases/5.t b/harness/cases/5.t
  18. index 7d67562..b0a7c56 100644
  19. --- a/harness/cases/5.t
  20. +++ b/harness/cases/5.t
  21. @@ -41,13 +41,12 @@ int test_main(void)
  22. assert(buf != (char *)-1);
  23. /* Whether PROT_WRITE is readable is arch-dependent. So compare
  24. - * against read result. */
  25. - res = read(rwfd, buf, SIZE);
  26. + * against write() result (to make the kernel read from buf). */
  27. + res = write(rwfd, buf, SIZE);
  28. if (res < 0)
  29. res = -errno;
  30. - status |= attempt_rw(rwfd, buf, SIZE, 0, READ, res);
  31. -
  32. - status |= attempt_rw(rwfd, buf, SIZE, 0, WRITE, SIZE);
  33. + status |= attempt_rw(rwfd, buf, SIZE, 0, READ, SIZE);
  34. + status |= attempt_rw(rwfd, buf, SIZE, 0, WRITE, res);
  35. return status;
  36. }
  37. --
  38. 2.26.0.292.g33ef6b2f38