This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch master-push created. glibc-2.27.9000-166-g5226a81


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master-push has been created
        at  5226a81f5517bcbc892679cca792006a6bafc53f (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5226a81f5517bcbc892679cca792006a6bafc53f

commit 5226a81f5517bcbc892679cca792006a6bafc53f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Mar 2 13:04:36 2018 -0300

    Define _DIRENT_MATCHES_DIRENT64 regardless
    
    This patch defines _DIRENT_MATCHES_DIRENT64 to either 0 or 1 and adjust its
    usage from checking its definition to its value.
    
    Checked on a build for major Linux abis.
    
    	* bits/dirent.h (__INO_T_MATCHES_INO64_T): Define regardless whether
    	__INO_T_MATCHES_INO64_T is defined.
    	* sysdeps/unix/sysv/linux/bits/dirent.h: Likewise.
    	* dirent/alphasort.c: Check _DIRENT_MATCHES_DIRENT64 value instead
    	of definition.
    	* dirent/alphasort64.c: Likewise.
    	* dirent/scandir.c: Likewise.
    	* dirent/scandir64-tail.c: Likewise.
    	* dirent/scandir64.c: Likewise.
    	* dirent/scandirat.c: Likewise.
    	* dirent/scandirat64.c: Likewise.
    	* dirent/versionsort.c: Likewise.
    	* dirent/versionsort64.c: Likewise.
    	* include/dirent.h: Likewise.

diff --git a/ChangeLog b/ChangeLog
index 92b86bf..42e167e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2018-03-03  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* bits/dirent.h (__INO_T_MATCHES_INO64_T): Define regardless whether
+	__INO_T_MATCHES_INO64_T is defined.
+	* sysdeps/unix/sysv/linux/bits/dirent.h: Likewise.
+	* dirent/alphasort.c: Check _DIRENT_MATCHES_DIRENT64 value instead
+	of definition.
+	* dirent/alphasort64.c: Likewise.
+	* dirent/scandir.c: Likewise.
+	* dirent/scandir64-tail.c: Likewise.
+	* dirent/scandir64.c: Likewise.
+	* dirent/scandirat.c: Likewise.
+	* dirent/scandirat64.c: Likewise.
+	* dirent/versionsort.c: Likewise.
+	* dirent/versionsort64.c: Likewise.
+	* include/dirent.h: Likewise.
+
 	* nptl/tst-cancel4-common.h (set_socket_buffer): New function.
 	* nptl/tst-cancel4-common.c (do_test): Call set_socket_buffer
 	for socketpair endpoint.
diff --git a/bits/dirent.h b/bits/dirent.h
index 8c38b8c..d775540 100644
--- a/bits/dirent.h
+++ b/bits/dirent.h
@@ -56,4 +56,6 @@ struct dirent64
 #ifdef __INO_T_MATCHES_INO64_T
 /* Inform libc code that these two types are effectively identical.  */
 # define _DIRENT_MATCHES_DIRENT64	1
+#else
+# define _DIRENT_MATCHES_DIRENT64	0
 #endif
diff --git a/dirent/alphasort.c b/dirent/alphasort.c
index 8d3b939..a6cd151 100644
--- a/dirent/alphasort.c
+++ b/dirent/alphasort.c
@@ -32,6 +32,6 @@ alphasort (const struct dirent **a, const struct dirent **b)
   return strcoll ((*a)->d_name, (*b)->d_name);
 }
 
-#ifdef _DIRENT_MATCHES_DIRENT64
+#if _DIRENT_MATCHES_DIRENT64
 weak_alias (alphasort, alphasort64)
 #endif
diff --git a/dirent/alphasort64.c b/dirent/alphasort64.c
index deb1921..3a47a97 100644
--- a/dirent/alphasort64.c
+++ b/dirent/alphasort64.c
@@ -19,7 +19,7 @@
 #include <string.h>
 
 /* alphasort.c defines alphasort64 as an alias if _DIRENT_MATCHES_DIRENT64.  */
-#ifndef _DIRENT_MATCHES_DIRENT64
+#if !_DIRENT_MATCHES_DIRENT64
 
 int
 alphasort64 (const struct dirent64 **a, const struct dirent64 **b)
diff --git a/dirent/scandir.c b/dirent/scandir.c
index 977d645..b24e157 100644
--- a/dirent/scandir.c
+++ b/dirent/scandir.c
@@ -40,6 +40,6 @@ SCANDIR (const char *dir,
   return SCANDIR_TAIL (__opendir (dir), namelist, select, cmp);
 }
 
-#ifdef _DIRENT_MATCHES_DIRENT64
+#if _DIRENT_MATCHES_DIRENT64
 weak_alias (scandir, scandir64)
 #endif
diff --git a/dirent/scandir64-tail.c b/dirent/scandir64-tail.c
index 684088c..8d5cc07 100644
--- a/dirent/scandir64-tail.c
+++ b/dirent/scandir64-tail.c
@@ -18,7 +18,7 @@
 
 #include <dirent.h>
 
-#ifndef _DIRENT_MATCHES_DIRENT64
+#if !_DIRENT_MATCHES_DIRENT64
 # define SCANDIR_TAIL   __scandir64_tail
 # define READDIR        __readdir64
 # define DIRENT_TYPE    struct dirent64
diff --git a/dirent/scandir64.c b/dirent/scandir64.c
index 7e666b0..0c63fa9 100644
--- a/dirent/scandir64.c
+++ b/dirent/scandir64.c
@@ -18,7 +18,7 @@
 #include <dirent.h>
 
 /* scandir.c defines scandir64 as an alias if _DIRENT_MATCHES_DIRENT64.  */
-#ifndef _DIRENT_MATCHES_DIRENT64
+#if !_DIRENT_MATCHES_DIRENT64
 
 # define SCANDIR        scandir64
 # define SCANDIR_TAIL   __scandir64_tail
diff --git a/dirent/scandirat.c b/dirent/scandirat.c
index 3f63f4d..96a1b0e 100644
--- a/dirent/scandirat.c
+++ b/dirent/scandirat.c
@@ -44,6 +44,6 @@ libc_hidden_def (SCANDIRAT)
 weak_alias (__scandirat, scandirat)
 #endif
 
-#ifdef _DIRENT_MATCHES_DIRENT64
+#if _DIRENT_MATCHES_DIRENT64
 weak_alias (scandirat, scandirat64)
 #endif
diff --git a/dirent/scandirat64.c b/dirent/scandirat64.c
index 6d682ff..520ae7c 100644
--- a/dirent/scandirat64.c
+++ b/dirent/scandirat64.c
@@ -18,7 +18,7 @@
 #include <dirent.h>
 
 /* scandirat.c defines scandirat64 as an alias if _DIRENT_MATCHES_DIRENT64.  */
-#ifndef _DIRENT_MATCHES_DIRENT64
+#if !_DIRENT_MATCHES_DIRENT64
 
 # define SCANDIRAT      scandirat64
 # define SCANDIR_TAIL   __scandir64_tail
diff --git a/dirent/versionsort.c b/dirent/versionsort.c
index 0130138..5ec15e8 100644
--- a/dirent/versionsort.c
+++ b/dirent/versionsort.c
@@ -32,6 +32,6 @@ versionsort (const struct dirent **a, const struct dirent **b)
   return __strverscmp ((*a)->d_name, (*b)->d_name);
 }
 
-#ifdef _DIRENT_MATCHES_DIRENT64
+#if _DIRENT_MATCHES_DIRENT64
 weak_alias (versionsort, versionsort64)
 #endif
diff --git a/dirent/versionsort64.c b/dirent/versionsort64.c
index bfb0cbb..7689c26 100644
--- a/dirent/versionsort64.c
+++ b/dirent/versionsort64.c
@@ -19,7 +19,7 @@
 #include <string.h>
 
 /* versionsort.c defines a versionsort64 alias if _DIRENT_MATCHES_DIRENT64.  */
-#ifndef _DIRENT_MATCHES_DIRENT64
+#if !_DIRENT_MATCHES_DIRENT64
 
 int
 versionsort64 (const struct dirent64 **a, const struct dirent64 **b)
diff --git a/include/dirent.h b/include/dirent.h
index caaeb0b..cc8f189 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -57,7 +57,7 @@ extern int __scandir_tail (DIR *dp,
 			   int (*cmp) (const struct dirent **,
 				       const struct dirent **))
   attribute_hidden;
-#  ifdef _DIRENT_MATCHES_DIRENT64
+#  if _DIRENT_MATCHES_DIRENT64
 #   define __scandir64_tail (dp, namelist, select, cmp)         \
   __scandir_tail (dp, (struct dirent ***) (namelist),           \
 		  (int (*) (const struct dirent *)) (select),   \
diff --git a/sysdeps/unix/sysv/linux/bits/dirent.h b/sysdeps/unix/sysv/linux/bits/dirent.h
index 2ed7919..f312720 100644
--- a/sysdeps/unix/sysv/linux/bits/dirent.h
+++ b/sysdeps/unix/sysv/linux/bits/dirent.h
@@ -54,4 +54,6 @@ struct dirent64
 #if defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T
 /* Inform libc code that these two types are effectively identical.  */
 # define _DIRENT_MATCHES_DIRENT64	1
+#else
+# define _DIRENT_MATCHES_DIRENT64	0
 #endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=fbd01e6c4427b558b63fedb938b7fc5fada8c6b8

commit fbd01e6c4427b558b63fedb938b7fc5fada8c6b8
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Feb 22 15:47:33 2018 -0300

    nptl: Fix tst-cancel4 sendto tests
    
    Now that send might be implemented calling sendto syscall on Linux,
    I am seeing some issue in some kernel configurations where tst-cancel4
    sendto do not block as expected.
    
    The socket used to force the syscall blocking is used with default
    system configuration for buffer sending size, which might not be
    suffice to force blocking.  This patch fixes it by explicit setting
    buffer socket lower than the buffer size used.  It also enables sendto
    cancellation tests to work in both ways (since internally send is
    implemented routing to sendto on Linux kernel).
    
    The patch also removes unrequired make rules on some archictures
    for send/recv. The generic nptl Makefile already set the compiler flags
    required on some architectures for correct unwinding and libc object
    are not strictly required to support unwind (since pthread_cancel
    requires linking against libpthread).
    
    Checked on aarch64-linux-gnu and x86_64-linux-gnu. I also did a
    sniff test with tst-cancel{4,5} on a simulated mips64-linux-gnu.
    
    	* nptl/tst-cancel4-common.h (set_socket_buffer): New function.
    	* nptl/tst-cancel4-common.c (do_test): Call set_socket_buffer
    	for socketpair endpoint.
    	* nptl/tst-cancel4.c (tf_send): Call set_socket_buffer and use
    	WRITE_BUFFER_SIZE as buffer size for sending socket.
    	(tf_sendto): Use SOCK_STREAM instead of SOCK_DGRAM and fix an
    	issue on system where send is implemented with sendto syscall.
    	* sysdeps/unix/sysv/linux/mips/mips64/Makefile [$(subdir) = socket]
    	(CFLAGS-recv.c, CFLAGS-send.c): Remove rules.
    	[$(subdir) = nptl] (CFLAGS-recv.c, CFLAGS-send.c): Likewise.
    	* sysdeps/unix/sysv/linux/riscv/rv64/Makefile: Remove file.

diff --git a/ChangeLog b/ChangeLog
index f54496f..92b86bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2018-03-03  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/tst-cancel4-common.h (set_socket_buffer): New function.
+	* nptl/tst-cancel4-common.c (do_test): Call set_socket_buffer
+	for socketpair endpoint.
+	* nptl/tst-cancel4.c (tf_send): Call set_socket_buffer and use
+	WRITE_BUFFER_SIZE as buffer size for sending socket.
+	(tf_sendto): Use SOCK_STREAM instead of SOCK_DGRAM and fix an
+	issue on system where send is implemented with sendto syscall.
+	* sysdeps/unix/sysv/linux/mips/mips64/Makefile [$(subdir) = socket]
+	(CFLAGS-recv.c, CFLAGS-send.c): Remove rules.
+	[$(subdir) = nptl] (CFLAGS-recv.c, CFLAGS-send.c): Likewise.
+	* sysdeps/unix/sysv/linux/riscv/rv64/Makefile: Remove file.
+
 	[BZ #21269]
 	* sysdeps/unix/sysv/linux/i386/Makefile (tests): Add tst-bz21269.
 	* sysdeps/unix/sysv/linux/i386/sigaction.c (SET_SA_RESTORER): Clear
diff --git a/nptl/tst-cancel4-common.c b/nptl/tst-cancel4-common.c
index 5bc7e44..c6eee73 100644
--- a/nptl/tst-cancel4-common.c
+++ b/nptl/tst-cancel4-common.c
@@ -20,29 +20,13 @@
 static int
 do_test (void)
 {
-  int val;
-  socklen_t len;
-
   if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
     {
       perror ("socketpair");
       exit (1);
     }
 
-  val = 1;
-  len = sizeof(val);
-  setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
-  if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
-    {
-      perror ("getsockopt");
-      exit (1);
-    }
-  if (val >= WRITE_BUFFER_SIZE)
-    {
-      puts ("minimum write buffer size too large");
-      exit (1);
-    }
-  setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
+  set_socket_buffer (fds[1]);
 
   if (mktemp (fifoname) == NULL)
     {
diff --git a/nptl/tst-cancel4-common.h b/nptl/tst-cancel4-common.h
index a526c0c..10cc4f3 100644
--- a/nptl/tst-cancel4-common.h
+++ b/nptl/tst-cancel4-common.h
@@ -62,6 +62,20 @@ static pthread_barrier_t b2;
 
 #define WRITE_BUFFER_SIZE 16384
 
+/* Set the send buffer of socket S to 1 byte so any send operation
+   done with WRITE_BUFFER_SIZE bytes will force syscall blocking.  */
+static void
+set_socket_buffer (int s)
+{
+  int val = 1;
+  socklen_t len = sizeof(val);
+
+  TEST_VERIFY_EXIT (setsockopt (s, SOL_SOCKET, SO_SNDBUF, &val,
+		    sizeof(val)) == 0);
+  TEST_VERIFY_EXIT (getsockopt (s, SOL_SOCKET, SO_SNDBUF, &val, &len) == 0);
+  TEST_VERIFY_EXIT (val < WRITE_BUFFER_SIZE);
+}
+
 /* Cleanup handling test.  */
 static int cl_called;
 
diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c
index 92a3d80..0532538 100644
--- a/nptl/tst-cancel4.c
+++ b/nptl/tst-cancel4.c
@@ -726,6 +726,8 @@ tf_send (void *arg)
   if (tempfd2 == -1)
     FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
 
+  set_socket_buffer (tempfd2);
+
   if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
     FAIL_EXIT1 ("connect: %m");
 
@@ -738,8 +740,7 @@ tf_send (void *arg)
 
   pthread_cleanup_push (cl, NULL);
 
-  /* Very large block, so that the send call blocks.  */
-  char mem[700000];
+  char mem[WRITE_BUFFER_SIZE];
 
   send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
 
@@ -1230,16 +1231,11 @@ tf_msync (void *arg)
 static void *
 tf_sendto (void *arg)
 {
-  if (arg == NULL)
-    // XXX If somebody can provide a portable test case in which sendto()
-    // blocks we can enable this test to run in both rounds.
-    abort ();
-
   struct sockaddr_un sun;
 
-  tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
+  tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
   if (tempfd == -1)
-    FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
+    FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
 
   int tries = 0;
   do
@@ -1254,23 +1250,30 @@ tf_sendto (void *arg)
   while (bind (tempfd, (struct sockaddr *) &sun,
 	       offsetof (struct sockaddr_un, sun_path)
 	       + strlen (sun.sun_path) + 1) != 0);
-  tempfname = strdup (sun.sun_path);
 
-  tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
+  listen (tempfd, 5);
+
+  tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
   if (tempfd2 == -1)
-    FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
+    FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
 
-  xpthread_barrier_wait (&b2);
+  set_socket_buffer (tempfd2);
+
+  if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
+    FAIL_EXIT1 ("connect: %m");
+
+  unlink (sun.sun_path);
 
   xpthread_barrier_wait (&b2);
 
+  if (arg != NULL)
+    xpthread_barrier_wait (&b2);
+
   pthread_cleanup_push (cl, NULL);
 
-  char mem[1];
+  char mem[WRITE_BUFFER_SIZE];
 
-  sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
-	  (struct sockaddr *) &sun,
-	  offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
+  sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0, NULL, 0);
 
   pthread_cleanup_pop (0);
 
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/Makefile b/sysdeps/unix/sysv/linux/mips/mips64/Makefile
index b4fb190..fcb48c0 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/Makefile
+++ b/sysdeps/unix/sysv/linux/mips/mips64/Makefile
@@ -1,13 +1,3 @@
-ifeq ($(subdir),socket)
-CFLAGS-recv.c += -fexceptions
-CFLAGS-send.c += -fexceptions
-endif
-
-ifeq ($(subdir),nptl)
-CFLAGS-recv.c += -fexceptions
-CFLAGS-send.c += -fexceptions
-endif
-
 ifeq ($(subdir),signal)
 # sigaction.c defines static functions in asms and refers to them from
 # C code, resulting in "'restore_rt' used but never defined" (which
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/Makefile b/sysdeps/unix/sysv/linux/riscv/rv64/Makefile
deleted file mode 100644
index cb60d74..0000000
--- a/sysdeps/unix/sysv/linux/riscv/rv64/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-ifeq ($(subdir),socket)
-CFLAGS-recv.c += -fexceptions
-CFLAGS-send.c += -fexceptions
-endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=68448be208ee06e76665918b37b0a57e3e00c8b4

commit 68448be208ee06e76665918b37b0a57e3e00c8b4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Nov 17 16:04:29 2017 -0200

    i386: Fix i386 sigaction sa_restorer initialization (BZ#21269)
    
    This patch fixes the i386 sa_restorer field initialization for sigaction
    syscall for kernel with vDSO.  As described in bug report, i386 Linux
    (and compat on x86_64) interprets SA_RESTORER clear with nonzero
    sa_restorer as a request for stack switching if the SS segment is 'funny'.
    This means that anything that tries to mix glibc's signal handling with
    segmentation (for instance through modify_ldt syscall) is randomly broken
    depending on what values lands in sa_restorer.
    
    The testcase added  is based on Linux test tools/testing/selftests/x86/ldt_gdt.c,
    more specifically in do_multicpu_tests function.  The main changes are:
    
      - C11 atomics instead of plain access.
    
      - Remove x86_64 support which simplifies the syscall handling and fallbacks.
    
      - Replicate only the test required to trigger the issue.
    
    Checked on i686-linux-gnu.
    
    	[BZ #21269]
    	* sysdeps/unix/sysv/linux/i386/Makefile (tests): Add tst-bz21269.
    	* sysdeps/unix/sysv/linux/i386/sigaction.c (SET_SA_RESTORER): Clear
    	sa_restorer for vDSO case.
    	* sysdeps/unix/sysv/linux/i386/tst-bz21269.c: New file.

diff --git a/ChangeLog b/ChangeLog
index e0639e9..f54496f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-03-03  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	[BZ #21269]
+	* sysdeps/unix/sysv/linux/i386/Makefile (tests): Add tst-bz21269.
+	* sysdeps/unix/sysv/linux/i386/sigaction.c (SET_SA_RESTORER): Clear
+	sa_restorer for vDSO case.
+	* sysdeps/unix/sysv/linux/i386/tst-bz21269.c: New file.
+
 2018-03-03  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
 	* scripts/check-installed-headers.sh: Ignore Hurd and Mach headers.
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index 4080b8c..da716e2 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -3,6 +3,9 @@ default-abi := 32
 
 ifeq ($(subdir),misc)
 sysdep_routines += ioperm iopl vm86
+
+tests += tst-bz21269
+$(objpfx)tst-bz21269: $(shared-thread-library)
 endif
 
 ifeq ($(subdir),elf)
diff --git a/sysdeps/unix/sysv/linux/i386/sigaction.c b/sysdeps/unix/sysv/linux/i386/sigaction.c
index a5eb9e0..177ff60 100644
--- a/sysdeps/unix/sysv/linux/i386/sigaction.c
+++ b/sysdeps/unix/sysv/linux/i386/sigaction.c
@@ -42,7 +42,6 @@ extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
 #endif
 extern void restore (void) asm ("__restore") attribute_hidden;
 
-
 /* If ACT is not NULL, change the action for SIG to *ACT.
    If OACT is not NULL, put the old action for SIG in *OACT.  */
 int
@@ -65,6 +64,8 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
 	  kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
 			      ? &restore_rt : &restore);
 	}
+      else
+	kact.sa_restorer = NULL;
     }
 
   /* XXX The size argument hopefully will have to be changed to the
diff --git a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
new file mode 100644
index 0000000..353e365
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
@@ -0,0 +1,233 @@
+/* Test for i386 sigaction sa_restorer handling (BZ#21269)
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This is based on Linux test tools/testing/selftests/x86/ldt_gdt.c,
+   more specifically in do_multicpu_tests function.  The main changes
+   are:
+
+   - C11 atomics instead of plain access.
+   - Remove x86_64 support which simplifies the syscall handling
+     and fallbacks.
+   - Replicate only the test required to trigger the issue for the
+     BZ#21269.  */
+
+#include <stdatomic.h>
+
+#include <asm/ldt.h>
+#include <linux/futex.h>
+
+#include <setjmp.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/syscall.h>
+#include <sys/mman.h>
+
+#include <support/xunistd.h>
+#include <support/check.h>
+#include <support/xthread.h>
+
+static int
+xset_thread_area (struct user_desc *u_info)
+{
+  long ret = syscall (SYS_set_thread_area, u_info);
+  TEST_VERIFY_EXIT (ret == 0);
+  return ret;
+}
+
+static void
+xmodify_ldt (int func, const void *ptr, unsigned long bytecount)
+{
+  TEST_VERIFY_EXIT (syscall (SYS_modify_ldt, 1, ptr, bytecount) == 0);
+}
+
+static int
+futex (int *uaddr, int futex_op, int val, void *timeout, int *uaddr2,
+	int val3)
+{
+  return syscall (SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
+}
+
+static void
+xsethandler (int sig, void (*handler)(int, siginfo_t *, void *), int flags)
+{
+  struct sigaction sa = { 0 };
+  sa.sa_sigaction = handler;
+  sa.sa_flags = SA_SIGINFO | flags;
+  TEST_VERIFY_EXIT (sigemptyset (&sa.sa_mask) == 0);
+  TEST_VERIFY_EXIT (sigaction (sig, &sa, 0) == 0);
+}
+
+static jmp_buf jmpbuf;
+
+static void
+sigsegv_handler (int sig, siginfo_t *info, void *ctx_void)
+{
+  siglongjmp (jmpbuf, 1);
+}
+
+/* Points to an array of 1024 ints, each holding its own index.  */
+static const unsigned int *counter_page;
+static struct user_desc *low_user_desc;
+static struct user_desc *low_user_desc_clear; /* Used to delete GDT entry.  */
+static int gdt_entry_num;
+
+static void
+setup_counter_page (void)
+{
+  long page_size = sysconf (_SC_PAGE_SIZE);
+  TEST_VERIFY_EXIT (page_size > 0);
+  unsigned int *page = xmmap (NULL, page_size, PROT_READ | PROT_WRITE,
+			      MAP_ANONYMOUS | MAP_PRIVATE | MAP_32BIT, -1);
+  for (int i = 0; i < (page_size / sizeof (unsigned int)); i++)
+    page[i] = i;
+  counter_page = page;
+}
+
+static void
+setup_low_user_desc (void)
+{
+  low_user_desc = xmmap (NULL, 2 * sizeof (struct user_desc),
+			 PROT_READ | PROT_WRITE,
+			 MAP_ANONYMOUS | MAP_PRIVATE | MAP_32BIT, -1);
+
+  low_user_desc->entry_number    = -1;
+  low_user_desc->base_addr       = (unsigned long) &counter_page[1];
+  low_user_desc->limit           = 0xffff;
+  low_user_desc->seg_32bit       = 1;
+  low_user_desc->contents        = 0;
+  low_user_desc->read_exec_only  = 0;
+  low_user_desc->limit_in_pages  = 1;
+  low_user_desc->seg_not_present = 0;
+  low_user_desc->useable         = 0;
+
+  xset_thread_area (low_user_desc);
+
+  low_user_desc_clear = low_user_desc + 1;
+  low_user_desc_clear->entry_number = gdt_entry_num;
+  low_user_desc_clear->read_exec_only = 1;
+  low_user_desc_clear->seg_not_present = 1;
+}
+
+/* Possible values of futex:
+   0: thread is idle.
+   1: thread armed.
+   2: thread should clear LDT entry 0.
+   3: thread should exit.  */
+static atomic_uint ftx;
+
+static void *
+threadproc (void *ctx)
+{
+  while (1)
+    {
+      futex ((int *) &ftx, FUTEX_WAIT, 1, NULL, NULL, 0);
+      while (atomic_load (&ftx) != 2)
+	{
+	  if (atomic_load (&ftx) >= 3)
+	    return NULL;
+	}
+
+      /* clear LDT entry 0.  */
+      const struct user_desc desc = { 0 };
+      xmodify_ldt (1, &desc, sizeof (desc));
+
+      /* If ftx == 2, set it to zero,  If ftx == 100, quit.  */
+      if (atomic_fetch_add (&ftx, -2) != 2)
+	return NULL;
+    }
+}
+
+
+/* As described in testcase, for historical reasons x86_32 Linux (and compat
+   on x86_64) interprets SA_RESTORER clear with nonzero sa_restorer as a
+   request for stack switching if the SS segment is 'funny' (this is default
+   scenario for vDSO system).  This means that anything that tries to mix
+   signal handling with segmentation should explicit clear the sa_restorer.
+
+   This testcase check if sigaction in fact does it by changing the local
+   descriptor table (LDT) through the modify_ldt syscall and triggering
+   a synchronous segfault on iret fault by trying to install an invalid
+   segment.  With a correct zeroed sa_restorer it should not trigger an
+   'real' SEGSEGV and allows the siglongjmp in signal handler.  */
+
+static int
+do_test (void)
+{
+  setup_counter_page ();
+  setup_low_user_desc ();
+
+  pthread_t thread;
+  unsigned short orig_ss;
+
+  xsethandler (SIGSEGV, sigsegv_handler, 0);
+  /* 32-bit kernels send SIGILL instead of SIGSEGV on IRET faults.  */
+  xsethandler (SIGILL, sigsegv_handler, 0);
+
+  thread = xpthread_create (0, threadproc, 0);
+
+  asm volatile ("mov %%ss, %0" : "=rm" (orig_ss));
+
+  for (int i = 0; i < 5; i++)
+    {
+      if (sigsetjmp (jmpbuf, 1) != 0)
+	continue;
+
+      /* Make sure the thread is ready after the last test. */
+      while (atomic_load (&ftx) != 0)
+	;
+
+      struct user_desc desc = {
+	.entry_number       = 0,
+	.base_addr          = 0,
+	.limit              = 0xffff,
+	.seg_32bit          = 1,
+	.contents           = 0,
+	.read_exec_only     = 0,
+	.limit_in_pages     = 1,
+	.seg_not_present    = 0,
+	.useable            = 0
+      };
+
+      xmodify_ldt (0x11, &desc, sizeof (desc));
+
+      /* Arm the thread.  */
+      ftx = 1;
+      futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);
+
+      asm volatile ("mov %0, %%ss" : : "r" (0x7));
+
+      /* Fire up thread modify_ldt call.  */
+      atomic_store (&ftx, 2);
+
+      while (atomic_load (&ftx) != 0)
+	;
+
+      /* On success, modify_ldt will segfault us synchronously and we will
+	 escape via siglongjmp.  */
+      support_record_failure ();
+    }
+
+  atomic_store (&ftx, 100);
+  futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);
+
+  xpthread_join (thread);
+
+  return 0;
+}
+
+#include <support/test-driver.c>

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]