From patchwork Mon Dec 18 21:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 24996 Received: (qmail 87675 invoked by alias); 18 Dec 2017 21:19:27 -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 87303 invoked by uid 89); 18 Dec 2017 21:19:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 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, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f193.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:in-reply-to:references:from:date :message-id:subject:to:cc; bh=/ygIBW7Ec4Ry2prWojPw5AqMre5R3glNVTbmhur3EkM=; b=iP5DFKXKsnDo0eONlMfhXsh08WP56vIhm0BNnf2LgvWEscQq0uikqQ0gPsNWL7ZHTg NZP5hCIo5T/SQPTTu3lXMeFQz0H6KD1N/6Y6qY3o4v478HKqgT2vS4OGKSeXqW/q5zhU IRCKughn5mJv914hUK3zKztzjJJ7i9eOYCCi6hKAWMlPClyKXk1o1JG5HaaQ6y/vOTVo ApDg48Hzk5GbzKzm4eoH5sWJRBZAgcM0384f4X35xYTYo/AiZnpeKKsc2HtBphfFwGp3 rxzu1msWggyJyCMZh4ZfWzSJp4vvOPAR0qD+ThHaPrigQTJMdjekaiAV0RAUyDuScrAb GkgA== X-Gm-Message-State: AKGB3mIZW24qAWiiLvOz7xL3Hbbyutpv+jIs/KYM1qBx7f0acwh6efuw UKf9V4/A8VWSDl+J9xBC2yvZIzHdn0RW9y4NdIYHJA== X-Google-Smtp-Source: ACJfBovyRSBjEIeeY+AFzaAIBYjfw+o0LROds7k8fHS0hgj8as1FhFxqXuD//jWZ55hKUAQiaZ3C1fu0SF28iWhWG0E= X-Received: by 10.157.65.241 with SMTP id v46mr742593oti.365.1513631962817; Mon, 18 Dec 2017 13:19:22 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <20171207174057.GA32196@gmail.com> <7e890f53-c331-d86e-ad13-b380a69d99eb@redhat.com> <814691a7-d946-1794-d6d8-7861f9ed2067@redhat.com> <08cf7c54-8bf0-27c0-863a-65cb76dd0728@redhat.com> <4e80a87a-c90a-85a6-daf1-cbbf71d0bf58@redhat.com> From: "H.J. Lu" Date: Mon, 18 Dec 2017 13:19:21 -0800 Message-ID: Subject: Re: [PATCH 1/2] Linux/x86: Update cancel_jmp_buf to match __jmp_buf_tag [BZ #22563] To: Joseph Myers Cc: Florian Weimer , GNU C Library On Mon, Dec 18, 2017 at 9:37 AM, Joseph Myers wrote: > I think any change applied to sysdeps/nptl/pthread.h should also be > applied to sysdeps/unix/sysv/linux/hppa/pthread.h to avoid divergence > between those header versions. > Here is the updated patch with sysdeps/unix/sysv/linux/hppa/pthread.h change. Tested natively on i386, x86_64 and x32. Tested hppa-linux-gnu with build-many-glibcs.py. I am checking it in tomorrow. From 2fc9116c385b43e69628dfcbfa7d9f7f8c32a03d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 6 Dec 2017 15:00:46 -0800 Subject: [PATCH] Linux/x86: Update cancel_jmp_buf to match __jmp_buf_tag [BZ #22563] On x86, padding in struct __jmp_buf_tag is used for shadow stack pointer to support shadow stack in Intel Control-flow Enforcemen Technology. Since the cancel_jmp_buf array is passed to setjmp and longjmp by casting it to pointer to struct __jmp_buf_tag, it should be as large as struct __jmp_buf_tag. Otherwise when shadow stack is enabled, setjmp and longjmp will write and read beyond cancel_jmp_buf when saving and restoring shadow stack pointer. This patch adds bits/types/__cancel_jmp_buf_tag.h to define struct __cancel_jmp_buf_tag so that Linux/x86 can add saved_mask to cancel_jmp_buf. Tested natively on i386, x86_64 and x32. Tested hppa-linux-gnu with build-many-glibcs.py. [BZ #22563] * bits/types/__cancel_jmp_buf_tag.h: New file. * sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h * sysdeps/unix/sysv/linux/x86/pthreaddef.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 [NEED_SAVED_MASK_IN_CANCEL_JMP_BUF] (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 | 3 ++ 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/nptl/pthreadP.h | 36 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/x86/pthreaddef.h | 22 +++++++++++++ 8 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 bits/types/__cancel_jmp_buf_tag.h create mode 100644 sysdeps/unix/sysv/linux/x86/bits/types/__cancel_jmp_buf_tag.h create mode 100644 sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h create mode 100644 sysdeps/unix/sysv/linux/x86/pthreaddef.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..c843f44239 --- /dev/null +++ b/bits/types/__cancel_jmp_buf_tag.h @@ -0,0 +1,28 @@ +/* Define struct __cancel_jmp_buf_tag. + 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 + . */ + +#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 570a42301c..60d036a1ea 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 c83b17b674..fdeb397eab 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -65,6 +65,9 @@ struct pthread_unwind_buf { __jmp_buf jmp_buf; int mask_was_saved; +#ifdef NEED_SAVED_MASK_IN_CANCEL_JMP_BUF + __sigset_t saved_mask; +#endif } cancel_jmp_buf[1]; union diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index 2b2b386ab3..787ac6e4cd 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 d1973741cd..3d69ddcd00 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..830a6ec90c --- /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 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/nptl/pthreadP.h b/sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h new file mode 100644 index 0000000000..8c36ba3a5d --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/nptl/pthreadP.h @@ -0,0 +1,36 @@ +/* Internal pthread header. 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 + . */ + +#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/unix/sysv/linux/x86/pthreaddef.h b/sysdeps/unix/sysv/linux/x86/pthreaddef.h new file mode 100644 index 0000000000..89d19d60a1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/pthreaddef.h @@ -0,0 +1,22 @@ +/* Pthread macros. 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 + . */ + +#include_next + +/* Need saved_mask in cancel_jmp_buf. */ +#define NEED_SAVED_MASK_IN_CANCEL_JMP_BUF 1 -- 2.14.3