From patchwork Thu Feb 8 18:14:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 25875 Received: (qmail 50785 invoked by alias); 8 Feb 2018 18:14:47 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 50292 invoked by uid 89); 8 Feb 2018 18:14:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f170.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=jb1Wa5AKFO+cP+R4GFnBxrn2zEuSh+0yxI9iIPryIHo=; b=oBYWtKv9WR6R+HIgSZ75xvaUGsZY55bOq6Kt2TtIWx7nnT8jvK2CSCGh/Hm4UetJDh QOS+mpCVr6eDSwBEk6dLppqvruCaQHY2t2ZeOnFe+G9srbxKpgc3zDWoA+oS86FmVUU9 TnxrcUV/JjxzC1/jLPRPjqEjbHUrieEW0tWUSc03xNejHj4O/MiJTUSJDZ/FAghcLaBe oz2OOlmYFBBoI0VBEHNI/N9D2YeKoDOm+IBl/BUxVkxQgXgJvjUsbm1x2DVsxdezVJBR vOnmDC8vYY7PbhGEhQ9/rBTc6gk3jrsptnCRJNinerlAaWqfHzZmWJ/j3c8GK8QIteeG izNA== X-Gm-Message-State: APf1xPAQLSJXqo9NcWvw8IiHqN5mf16icA2I6azXkw9Newqe9i6tGmvt jSOql516cvvxIWiiePuoZuGo/Y4Bu8ND64S+vso= X-Google-Smtp-Source: AH8x225ZmVlGGb1hvbBKyw4qI7xLcHjeSmfLOA6IZGrWHr6AERJeSQv+0vjHG6ftHeBQnOjC2ClIHSSt9gorQUBFBoc= X-Received: by 10.157.50.132 with SMTP id u4mr62125otb.133.1518113681565; Thu, 08 Feb 2018 10:14:41 -0800 (PST) MIME-Version: 1.0 From: "H.J. Lu" Date: Thu, 8 Feb 2018 10:14:40 -0800 Message-ID: Subject: [PATCH 1/2] Revert and update "Revert Intel CET changes to __jmp_buf_tag (Bug 22743)" To: "Carlos O'Donell" Cc: GNU C Library On Thu, Feb 8, 2018 at 5:27 AM, H.J. Lu wrote: > On Thu, Feb 8, 2018 at 1:25 AM, Carlos O'Donell wrote: ils: >> >> The name NEED_SAVED_MASK_IN_CANCEL_JMP_BUF while true is slightly >> misleading IMO. While it is true that you need the saved mask there, the >> actual logical goal is to make the structure match in layout with the >> non-cancel jmp_buf. I would rename this to NEED_SETJMP_LAYOUT or something > > Will do. > Here is the updated patch to revert commit 2ec0e7eade0ea1258acd5c6f5e5e9bfaeb5041a8 Author: Carlos O'Donell Date: Wed Jan 24 20:35:22 2018 -0800 Revert Intel CET changes to __jmp_buf_tag (Bug 22743) OK for trunk? Thanks. From 438aa89a52ea0ff382e3d57d05d4e879f2c71991 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 26 Jan 2018 05:19:15 -0800 Subject: [PATCH 1/2] Revert and update "Revert Intel CET changes to __jmp_buf_tag (Bug 22743)" This reverts commit 2ec0e7eade0ea1258acd5c6f5e5e9bfaeb5041a8, renames sysdeps/unix/sysv/linux/x86/pthreaddef.h to sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h and defines/checks NEED_SETJMP_JMP_BUF_LAYOUT instead of NEED_SAVED_MASK_IN_CANCEL_JMP_BUF. This is needed to save and restore shadow stack register in setjmp and longjmp. [BZ #22563] * sysdeps/i386/nptl/tcb-offsets.sym (FEATURE_1_OFFSET): New. * sysdeps/i386/nptl/tls.h (tcbhead_t): Add feature_1. * sysdeps/x86_64/nptl/tcb-offsets.sym (FEATURE_1_OFFSET): New. * sysdeps/x86_64/nptl/tls.h (tcbhead_t): Rename __glibc_unused1 to feature_1. [BZ #22563] * bits/types/__cancel_jmp_buf_tag.h: New file. * sysdeps/nptl/cancel_jmp_buf.h: Likewise. * sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h: Likewise. * sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h: Likewise. * sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h: Likewise. * nptl/Makefile (headers): Add bits/types/__cancel_jmp_buf_tag.h. * nptl/descr.h: Include . [NEED_SETJMP_JMP_BUF_LAYOUT] (pthread_unwind_buf): Add saved_mask to cancel_jmp_buf. * sysdeps/nptl/pthread.h: Include . (__pthread_unwind_buf_t): Use struct __cancel_jmp_buf_tag with __cancel_jmp_buf. * sysdeps/unix/sysv/linux/hppa/pthread.h: Likewise. --- bits/types/__cancel_jmp_buf_tag.h | 28 +++++++++++++++++ nptl/Makefile | 3 +- nptl/descr.h | 4 +++ sysdeps/i386/nptl/tcb-offsets.sym | 1 + sysdeps/i386/nptl/tls.h | 4 +++ sysdeps/nptl/cancel_jmp_buf.h | 20 ++++++++++++ sysdeps/nptl/pthread.h | 7 ++--- sysdeps/unix/sysv/linux/hppa/pthread.h | 7 ++--- .../linux/x86/bits/types/__cancel_jmp_buf_tag.h | 31 +++++++++++++++++++ sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h | 20 ++++++++++++ sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h | 36 ++++++++++++++++++++++ sysdeps/x86_64/nptl/tcb-offsets.sym | 1 + sysdeps/x86_64/nptl/tls.h | 5 ++- 13 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 bits/types/__cancel_jmp_buf_tag.h create mode 100644 sysdeps/nptl/cancel_jmp_buf.h create mode 100644 sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h create mode 100644 sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h create mode 100644 sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h diff --git a/bits/types/__cancel_jmp_buf_tag.h b/bits/types/__cancel_jmp_buf_tag.h new file mode 100644 index 0000000000..62f5c61f83 --- /dev/null +++ b/bits/types/__cancel_jmp_buf_tag.h @@ -0,0 +1,28 @@ +/* Define struct __cancel_jmp_buf_tag. + Copyright (C) 2017-2018 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 + . */ + +#ifndef ____cancel_jmp_buf_tag_defined +#define ____cancel_jmp_buf_tag_defined 1 + +struct __cancel_jmp_buf_tag + { + __jmp_buf __cancel_jmp_buf; + int __mask_was_saved; + }; + +#endif diff --git a/nptl/Makefile b/nptl/Makefile index 6fc2c8bb6a..7940b3d26b 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -22,7 +22,8 @@ subdir := nptl include ../Makeconfig -headers := pthread.h semaphore.h bits/semaphore.h +headers := pthread.h semaphore.h bits/semaphore.h \ + bits/types/__cancel_jmp_buf_tag.h extra-libs := libpthread extra-libs-others := $(extra-libs) diff --git a/nptl/descr.h b/nptl/descr.h index 64ba29e1cb..f56ac69379 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "../nptl_db/thread_db.h" #include @@ -65,6 +66,9 @@ struct pthread_unwind_buf { __jmp_buf jmp_buf; int mask_was_saved; +#if NEED_SETJMP_JMP_BUF_LAYOUT + __sigset_t saved_mask; +#endif } cancel_jmp_buf[1]; union diff --git a/sysdeps/i386/nptl/tcb-offsets.sym b/sysdeps/i386/nptl/tcb-offsets.sym index 695a810386..250f1a6e13 100644 --- a/sysdeps/i386/nptl/tcb-offsets.sym +++ b/sysdeps/i386/nptl/tcb-offsets.sym @@ -15,3 +15,4 @@ POINTER_GUARD offsetof (tcbhead_t, pointer_guard) #ifndef __ASSUME_PRIVATE_FUTEX PRIVATE_FUTEX offsetof (tcbhead_t, private_futex) #endif +FEATURE_1_OFFSET offsetof (tcbhead_t, feature_1) diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h index fcda135b7c..30643d452a 100644 --- a/sysdeps/i386/nptl/tls.h +++ b/sysdeps/i386/nptl/tls.h @@ -50,6 +50,10 @@ typedef struct void *__private_tm[4]; /* GCC split stack support. */ void *__private_ss; + /* Bit 0: IBT. + Bit 1: SHSTK. + */ + unsigned int feature_1; } tcbhead_t; # define TLS_MULTIPLE_THREADS_IN_TCB 1 diff --git a/sysdeps/nptl/cancel_jmp_buf.h b/sysdeps/nptl/cancel_jmp_buf.h new file mode 100644 index 0000000000..a6612bb60b --- /dev/null +++ b/sysdeps/nptl/cancel_jmp_buf.h @@ -0,0 +1,20 @@ +/* Macros for cancel_jmp_buf. Generic version. + Copyright (C) 2018 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 + . */ + +/* No need to use the same setjmp jmp_buf layout in cancel_jmp_buf. */ +#define NEED_SETJMP_JMP_BUF_LAYOUT 0 diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index df049abf74..c8ba5a75c5 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -27,6 +27,7 @@ #include #include #include +#include /* Detach state. */ @@ -523,11 +524,7 @@ extern void pthread_testcancel (void); typedef struct { - struct - { - __jmp_buf __cancel_jmp_buf; - int __mask_was_saved; - } __cancel_jmp_buf[1]; + struct __cancel_jmp_buf_tag __cancel_jmp_buf[1]; void *__pad[4]; } __pthread_unwind_buf_t __attribute__ ((__aligned__)); diff --git a/sysdeps/unix/sysv/linux/hppa/pthread.h b/sysdeps/unix/sysv/linux/hppa/pthread.h index 11a024db59..3df5e7c2ac 100644 --- a/sysdeps/unix/sysv/linux/hppa/pthread.h +++ b/sysdeps/unix/sysv/linux/hppa/pthread.h @@ -27,6 +27,7 @@ #include #include #include +#include /* Detach state. */ @@ -499,11 +500,7 @@ extern void pthread_testcancel (void); typedef struct { - struct - { - __jmp_buf __cancel_jmp_buf; - int __mask_was_saved; - } __cancel_jmp_buf[1]; + struct __cancel_jmp_buf_tag __cancel_jmp_buf[1]; void *__pad[4]; } __pthread_unwind_buf_t __attribute__ ((__aligned__)); diff --git a/sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h b/sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h new file mode 100644 index 0000000000..70efbb190c --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h @@ -0,0 +1,31 @@ +/* Define struct __cancel_jmp_buf_tag. + Copyright (C) 2017-2018 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 + . */ + +#ifndef ____cancel_jmp_buf_tag_defined +#define ____cancel_jmp_buf_tag_defined 1 + +#include + +struct __cancel_jmp_buf_tag + { + __jmp_buf __cancel_jmp_buf; + int __mask_was_saved; + __sigset_t __saved_mask; + }; + +#endif diff --git a/sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h b/sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h new file mode 100644 index 0000000000..362f12d0ac --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/cancel_jmp_buf.h @@ -0,0 +1,20 @@ +/* Macros for cancel_jmp_buf. Linux/x86 version. + Copyright (C) 2018 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 + . */ + +/* Need the same setjmp jmp_buf layout in cancel_jmp_buf. */ +#define NEED_SETJMP_JMP_BUF_LAYOUT 1 diff --git a/sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h b/sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h new file mode 100644 index 0000000000..247a62e9a0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h @@ -0,0 +1,36 @@ +/* Internal pthread header. Linux/x86 version. + Copyright (C) 2017-2018 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 + . */ + +#include_next + +#ifndef _PTHREADP_H_X86 +#define _PTHREADP_H_X86 1 + +extern struct pthread_unwind_buf ____pthread_unwind_buf_private; + +_Static_assert (sizeof (____pthread_unwind_buf_private.cancel_jmp_buf) + >= sizeof (struct __jmp_buf_tag), + "size of cancel_jmp_buf < sizeof __jmp_buf_tag"); + +extern __pthread_unwind_buf_t ____pthread_unwind_buf; + +_Static_assert (sizeof (____pthread_unwind_buf.__cancel_jmp_buf) + >= sizeof (struct __jmp_buf_tag), + "size of __cancel_jmp_buf < sizeof __jmp_buf_tag"); + +#endif diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym index 8a25c482cb..03b6dba5c3 100644 --- a/sysdeps/x86_64/nptl/tcb-offsets.sym +++ b/sysdeps/x86_64/nptl/tcb-offsets.sym @@ -15,6 +15,7 @@ VGETCPU_CACHE_OFFSET offsetof (tcbhead_t, vgetcpu_cache) #ifndef __ASSUME_PRIVATE_FUTEX PRIVATE_FUTEX offsetof (tcbhead_t, private_futex) #endif +FEATURE_1_OFFSET offsetof (tcbhead_t, feature_1) -- Not strictly offsets, but these values are also used in the TCB. TCB_CANCELSTATE_BITMASK CANCELSTATE_BITMASK diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h index bdd02376f9..7f0b292f42 100644 --- a/sysdeps/x86_64/nptl/tls.h +++ b/sysdeps/x86_64/nptl/tls.h @@ -56,7 +56,10 @@ typedef struct # else int __glibc_reserved1; # endif - int __glibc_unused1; + /* Bit 0: IBT. + Bit 1: SHSTK. + */ + unsigned int feature_1; /* Reservation of some values for the TM ABI. */ void *__private_tm[4]; /* GCC split stack support. */ -- 2.14.3