aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--debug/longjmp_chk.c2
-rw-r--r--setjmp/longjmp.c5
-rw-r--r--setjmp/sigjmp.c4
-rw-r--r--sysdeps/generic/setjmpP.h24
-rw-r--r--sysdeps/unix/sysv/linux/x86/Makefile5
-rw-r--r--sysdeps/unix/sysv/linux/x86/jmp_buf-ssp.sym5
-rw-r--r--sysdeps/unix/sysv/linux/x86/setjmpP.h67
-rw-r--r--sysdeps/unix/sysv/linux/x86/tst-saved_mask-1.c55
9 files changed, 178 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 888f9fbd67..d4cc1ab255 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2017-11-30 H.J. Lu <hongjiu.lu@intel.com>
+
+ * debug/longjmp_chk.c: Include <setjmpP.h> instead of
+ <setjmp.h>.
+ * setjmp/longjmp.c: Include <setjmpP.h> instead of <setjmp.h>.
+ (__libc_siglongjmp): Cast &env[0].__saved_mask to "sigset_t *".
+ * setjmp/sigjmp.c: Include <setjmpP.h> instead of <setjmp.h>.
+ (__sigjmp_save): Cast &env[0].__saved_mask to "sigset_t *".
+ * sysdeps/generic/setjmpP.h: New file.
+ * sysdeps/unix/sysv/linux/x86/jmp_buf-ssp.sym: Likewise.
+ * sysdeps/unix/sysv/linux/x86/setjmpP.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86/tst-saved_mask-1.c: Likewise.
+ * sysdeps/unix/sysv/linux/x86/Makefile (gen-as-const-headers):
+ Add jmp_buf-ssp.sym.
+ (tests): Add tst-saved_mask-1.
+
2017-11-30 Arjun Shankar <arjun@redhat.com>
[BZ #22375]
diff --git a/debug/longjmp_chk.c b/debug/longjmp_chk.c
index 1cea6c05ef..61be0da0cd 100644
--- a/debug/longjmp_chk.c
+++ b/debug/longjmp_chk.c
@@ -15,7 +15,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <setjmp.h>
+#include <setjmpP.h>
#define __longjmp ____longjmp_chk
#define __libc_siglongjmp __longjmp_chk
diff --git a/setjmp/longjmp.c b/setjmp/longjmp.c
index 2453c2c124..e144a874d7 100644
--- a/setjmp/longjmp.c
+++ b/setjmp/longjmp.c
@@ -16,7 +16,7 @@
<http://www.gnu.org/licenses/>. */
#include <stddef.h>
-#include <setjmp.h>
+#include <setjmpP.h>
#include <signal.h>
@@ -31,7 +31,8 @@ __libc_siglongjmp (sigjmp_buf env, int val)
if (env[0].__mask_was_saved)
/* Restore the saved signal mask. */
- (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask,
+ (void) __sigprocmask (SIG_SETMASK,
+ (sigset_t *) &env[0].__saved_mask,
(sigset_t *) NULL);
/* Call the machine-dependent function to restore machine state. */
diff --git a/setjmp/sigjmp.c b/setjmp/sigjmp.c
index 30839ae819..32b727fae8 100644
--- a/setjmp/sigjmp.c
+++ b/setjmp/sigjmp.c
@@ -16,7 +16,7 @@
<http://www.gnu.org/licenses/>. */
#include <stddef.h>
-#include <setjmp.h>
+#include <setjmpP.h>
#include <signal.h>
/* This function is called by the `sigsetjmp' macro
@@ -28,7 +28,7 @@ __sigjmp_save (sigjmp_buf env, int savemask)
{
env[0].__mask_was_saved = (savemask &&
__sigprocmask (SIG_BLOCK, (sigset_t *) NULL,
- &env[0].__saved_mask) == 0);
+ (sigset_t *) &env[0].__saved_mask) == 0);
return 0;
}
diff --git a/sysdeps/generic/setjmpP.h b/sysdeps/generic/setjmpP.h
new file mode 100644
index 0000000000..a878ce6b35
--- /dev/null
+++ b/sysdeps/generic/setjmpP.h
@@ -0,0 +1,24 @@
+/* Internal header file for <setjmp.h>. Generic version.
+ 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/>. */
+
+#ifndef _SETJMPP_H
+#define _SETJMPP_H 1
+
+#include <setjmp.h>
+
+#endif /* setjmpP.h */
diff --git a/sysdeps/unix/sysv/linux/x86/Makefile b/sysdeps/unix/sysv/linux/x86/Makefile
index c069570683..c55a43e58d 100644
--- a/sysdeps/unix/sysv/linux/x86/Makefile
+++ b/sysdeps/unix/sysv/linux/x86/Makefile
@@ -19,3 +19,8 @@ endif
ifeq ($(subdir),elf)
sysdep_routines += dl-vdso
endif
+
+ifeq ($(subdir),setjmp)
+gen-as-const-headers += jmp_buf-ssp.sym
+tests += tst-saved_mask-1
+endif
diff --git a/sysdeps/unix/sysv/linux/x86/jmp_buf-ssp.sym b/sysdeps/unix/sysv/linux/x86/jmp_buf-ssp.sym
new file mode 100644
index 0000000000..12829196db
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86/jmp_buf-ssp.sym
@@ -0,0 +1,5 @@
+#include <setjmpP.h>
+#undef __saved_mask
+
+--
+SHADOW_STACK_POINTER_OFFSET offsetof(struct __jmp_buf_tag, __saved_mask.__saved.__shadow_stack_pointer)
diff --git a/sysdeps/unix/sysv/linux/x86/setjmpP.h b/sysdeps/unix/sysv/linux/x86/setjmpP.h
new file mode 100644
index 0000000000..69a46d0ce2
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86/setjmpP.h
@@ -0,0 +1,67 @@
+/* Internal header file for <setjmp.h>. Linux/x86 version.
+ 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/>. */
+
+#ifndef _SETJMPP_H
+#define _SETJMPP_H 1
+
+#include <bits/types/__sigset_t.h>
+
+/* The biggest signal number + 1. As of kernel 4.14, x86 _NSIG is 64.
+ Define it to 513 to leave some rooms for future use. */
+#define _JUMP_BUF_SIGSET_NSIG 513
+/* Number of longs to hold all signals. */
+#define _JUMP_BUF_SIGSET_NWORDS \
+ ((_JUMP_BUF_SIGSET_NSIG - 1 + 7) / (8 * sizeof (unsigned long int)))
+
+typedef struct
+ {
+ unsigned long int __val[_JUMP_BUF_SIGSET_NWORDS];
+ } __jmp_buf_sigset_t;
+
+typedef union
+ {
+ __sigset_t __saved_mask_compat;
+ struct
+ {
+ __jmp_buf_sigset_t __saved_mask;
+ /* Used for shadow stack pointer. */
+ unsigned long int __shadow_stack_pointer;
+ } __saved;
+ } __jmpbuf_arch_t;
+
+#undef __sigset_t
+#define __sigset_t __jmpbuf_arch_t
+#include <setjmp.h>
+#undef __saved_mask
+#define __saved_mask __saved_mask.__saved.__saved_mask
+
+#include <signal.h>
+
+#define _SIGPROCMASK_NSIG_WORDS (_NSIG / (8 * sizeof (unsigned long int)))
+
+typedef struct
+ {
+ unsigned long int __val[_SIGPROCMASK_NSIG_WORDS];
+ } __sigprocmask_sigset_t;
+
+extern jmp_buf ___buf;
+extern __typeof (___buf[0].__saved_mask) ___saved_mask;
+_Static_assert (sizeof (___saved_mask) >= sizeof (__sigprocmask_sigset_t),
+ "size of ___saved_mask < size of __sigprocmask_sigset_t");
+
+#endif /* setjmpP.h */
diff --git a/sysdeps/unix/sysv/linux/x86/tst-saved_mask-1.c b/sysdeps/unix/sysv/linux/x86/tst-saved_mask-1.c
new file mode 100644
index 0000000000..f383408b63
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86/tst-saved_mask-1.c
@@ -0,0 +1,55 @@
+/* Test that sigprocmask does not read from the unused part of jmpbuf.
+ 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/>. */
+
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <setjmpP.h>
+#include <support/next_to_fault.h>
+
+#define SIZEOF_SIGSET_T sizeof (__jmp_buf_sigset_t)
+
+static int
+do_test (void)
+{
+ sigjmp_buf sj;
+ struct support_next_to_fault sigset_t_buf
+ = support_next_to_fault_allocate (SIZEOF_SIGSET_T);
+ sigset_t *m_p = (sigset_t *) sigset_t_buf.buffer;
+ sigset_t m;
+
+ sigemptyset (&m);
+ memcpy (m_p, &m, SIZEOF_SIGSET_T);
+ sigprocmask (SIG_SETMASK, m_p, NULL);
+ memcpy (&m, m_p, SIZEOF_SIGSET_T);
+ if (sigsetjmp (sj, 0) == 0)
+ {
+ sigaddset (&m, SIGUSR1);
+ memcpy (m_p, &m, SIZEOF_SIGSET_T);
+ sigprocmask (SIG_SETMASK, m_p, NULL);
+ memcpy (&m, m_p, SIZEOF_SIGSET_T);
+ siglongjmp (sj, 1);
+ return EXIT_FAILURE;
+ }
+ sigprocmask (SIG_SETMASK, NULL, m_p);
+ memcpy (&m, m_p, SIZEOF_SIGSET_T);
+ return sigismember (&m, SIGUSR1) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+#include <support/test-driver.c>