Blame SOURCES/glibc-rh1337242.patch

147e83
commit b3a810d0d3d5c6ce7ddfb61321cd7971808ca703
147e83
Author: Stefan Liebler <stli@linux.vnet.ibm.com>
147e83
Date:   Tue May 17 10:45:48 2016 +0200
147e83
147e83
    Fix tst-cancel17/tst-cancelx17, which sometimes segfaults while exiting.
147e83
    
147e83
    The testcase tst-cancel[x]17 ends sometimes with a segmentation fault.
147e83
    This happens in one of 10000 cases. Then the real testcase has already
147e83
    exited with success and returned from do_test(). The segmentation fault
147e83
    occurs after returning from main in _dl_fini().
147e83
    
147e83
    In those cases, the aio_read(&a) was not canceled because the read
147e83
    request was already in progress. In the meanwhile aio_write(ap) wrote
147e83
    something to the pipe and the read request is able to read the
147e83
    requested byte.
147e83
    The read request hasn't finished before returning from do_test().
147e83
    After it finishes, it writes the return value and error code from the
147e83
    read syscall to the struct aiocb a, which lies on the stack of do_test.
147e83
    The stack of the subsequent function call of _dl_fini or _dl_sort_fini,
147e83
    which is inlined in _dl_fini is corrupted.
147e83
    
147e83
    In case of S390, it reads a zero and decrements it by 1:
147e83
    unsigned int k = nmaps - 1;
147e83
    struct link_map **runp = maps[k]->l_initfini;
147e83
    The load from unmapped memory leads to the segmentation fault.
147e83
    The stack corruption also happens on other architectures.
147e83
    I saw them e.g. on x86 and ppc, too.
147e83
    
147e83
    This patch adds an aio_suspend call to ensure, that the read request
147e83
    is finished before returning from do_test().
147e83
    
147e83
    ChangeLog:
147e83
    
147e83
    	* nptl/tst-cancel17.c (do_test): Wait for finishing aio_read(&a).
147e83
147e83
diff --git a/nptl/tst-cancel17.c b/nptl/tst-cancel17.c
147e83
index fb89292..eedd28e 100644
147e83
--- a/nptl/tst-cancel17.c
147e83
+++ b/nptl/tst-cancel17.c
147e83
@@ -333,6 +333,22 @@ do_test (void)
147e83
 
147e83
   puts ("early cancellation succeeded");
147e83
 
147e83
+  if (ap == &a2)
147e83
+    {
147e83
+      /* The aio_read(&a) was not canceled because the read request was
147e83
+	 already in progress. In the meanwhile aio_write(ap) wrote something
147e83
+	 to the pipe and the read request either has already been finished or
147e83
+	 is able to read the requested byte.
147e83
+	 Wait for the read request before returning from this function because
147e83
+	 the return value and error code from the read syscall will be written
147e83
+	 to the struct aiocb a, which lies on the stack of this function.
147e83
+	 Otherwise the stack from subsequent function calls - e.g. _dl_fini -
147e83
+	 will be corrupted, which can lead to undefined behaviour like a
147e83
+	 segmentation fault.  */
147e83
+      const struct aiocb *l[1] = { &a };
147e83
+      TEMP_FAILURE_RETRY (aio_suspend(l, 1, NULL));
147e83
+    }
147e83
+
147e83
   return 0;
147e83
 }
147e83