[PATCH libaio 26/28] harness: Fix PROT_WRITE mmap check
authorGuillem Jover <guillem@hadrons.org>
Wed, 14 Aug 2019 02:42:42 +0000 (04:42 +0200)
committerGuillem Jover <guillem@debian.org>
Thu, 11 Nov 2021 03:56:01 +0000 (03:56 +0000)
This partially reverts commit d7f5065448efb49b2a26e728ff735e12ea05b62e.

The actual problem in the original code was that read() was being used
to assert whether the buffer was readable, but the kernel was instead
reading from the file descriptor and then writing into the buffer, so
no EFAULT was being generated (on architectures that do so).

We needed to use a write() so that the kernel would read from the
buffer.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Gbp-Pq: Topic upstream
Gbp-Pq: Name 0026-harness-Fix-PROT_WRITE-mmap-check.patch

harness/cases/5.t

index 7d675624262474971f230f982b92bb1bc742c917..b0a7c56ff5cc42951c30bd2bf804878833bcadb9 100644 (file)
@@ -41,13 +41,12 @@ int test_main(void)
        assert(buf != (char *)-1);
 
        /* Whether PROT_WRITE is readable is arch-dependent.  So compare
-        * against read result. */
-       res = read(rwfd, buf, SIZE);
+        * against write() result (to make the kernel read from buf). */
+       res = write(rwfd, buf, SIZE);
        if (res < 0)
                res = -errno;
-       status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, res);
-
-       status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, SIZE);
+       status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, SIZE);
+       status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, res);
 
        return status;
 }