Message ID | 20231220145701.740912-1-hjl.tools@gmail.com |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A34A3858D20 for <patchwork@sourceware.org>; Wed, 20 Dec 2023 14:57:26 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id D4CD23858439 for <libc-alpha@sourceware.org>; Wed, 20 Dec 2023 14:57:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4CD23858439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D4CD23858439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703084227; cv=none; b=GUn3G4ruTsUjZ/8P87PzpigFYuWelBV1iPRbTZLOv57XjEsTk7ZLJoTBnL45cTNQdcdYMYqKcXHZsmyaqU6COeyNmcPCdm6nLjkon1bN8xVDon4zorT/Nb2lLfSB/4pGkMPI98ORZzPAyKehC2EIycFK/5RyPx1NFmOI9t9ISaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703084227; c=relaxed/simple; bh=L+68DYFHKPkxjsq3SWGMJdhuWnCRNoX/A1wtm2Bhj9M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OSoQAoyjweYP3Wr/N6oi01bgcKA028aGo6lqkDd7ZeGglKMxClcNlkLWxVeQcSLLwIvwlPbe57eBn4k1Wcb+ttjFj1UrKGy6BqRKEEy0foPNd2X8aPTZoFgXC0ifi+ofsHF6r6Utp/kBg7u4FT7gGr19w+x9NzpRGcfP4O66++8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d3eabe9321so6969935ad.2 for <libc-alpha@sourceware.org>; Wed, 20 Dec 2023 06:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703084225; x=1703689025; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nw+WMSY4wL/sb1Iknf+cbTpybI+cqBx8UFfnX+2I2YY=; b=d9hRsMOStqMszaJJ6uGHK+0Eha6WV0avkexFD1mvfT/xfVjKlI5j+2PKqpZgn4nT// Yjbx/CjiremJ2Vy4hXEHrb9Vh8IHMj8xIXLdLhvNKO4PH8I403xKUnLgAs2R/PTLWcXm Ui9wuUjkDLFIBOxYt5FqrtFL7mDzVUd1pPwdRn70tokx6o6xR+2q9n+75M67xQjBdJ8P lcORDR3TlD5yG2Sk+lZrIgV1ylqGV/+DdV169QWnFh3IHQjaFD1B1+tjomCjUz9/wVqG cAS9N7iEDJ0Gq6V6AxOHfHt7xx74HG9biCKp6/b+tKxOyUVtc5PsU6aa7RGfpu20zjBF if7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703084225; x=1703689025; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nw+WMSY4wL/sb1Iknf+cbTpybI+cqBx8UFfnX+2I2YY=; b=Y9x6WOtMG5DyQ4pZ0wTDXoEupffe/lkbARSdw9GYz787OQm7/bTLK8fxTftg2Bi5jW Womu8oFDrVH1Pi8Z+hsWQgcFxeGuDklbZDJdnQj0YMXafU7B0GxRt11M9Jm39fMuXMEP yVWVxrjO5bB1/nnRo/F2sejeHmwMzONoUVYdli5aBtMnychBLM8bZm/l/6ez7bukxDmX uvqxEpcjFVH+zTbWLwfsZBdfJBk36ot3bmncOTr4G+0sCskbDd0oo/JBmXYvM2C1G3/I hOEeDh6o/1e63MCqiXvtGZpEr4yekbgNL8Amd6Pi9BMLyineSWMRaqNrp8qnca4LL/kQ WF3g== X-Gm-Message-State: AOJu0Yx8n6Dug3Zz1/+Z+Ty6DTLvHkYxlgpke1FkO8YqfrN2CttASRnD 8pH7JgfNe2EApqDOj4m8OlMnPn+ouiM= X-Google-Smtp-Source: AGHT+IGwHpC6sJc9ShkzCN0eF97RInYgj5NEDzqCcHvHc0bsoCAYjxbl2Gd48wJaHxITRDFIJxDNvg== X-Received: by 2002:a17:903:2288:b0:1d3:fe37:7560 with SMTP id b8-20020a170903228800b001d3fe377560mr13063plh.30.1703084224876; Wed, 20 Dec 2023 06:57:04 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.59.129.147]) by smtp.gmail.com with ESMTPSA id s22-20020a170902989600b001d0b6ba60fdsm23094620plp.175.2023.12.20.06.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:57:03 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 6D5CB7402E6; Wed, 20 Dec 2023 06:57:01 -0800 (PST) From: "H.J. Lu" <hjl.tools@gmail.com> To: libc-alpha@sourceware.org Cc: rick.p.edgecombe@intel.com, goldstein.w.n@gmail.com Subject: [PATCH v4 0/6] x86/cet: Update CET kernel interface Date: Wed, 20 Dec 2023 06:56:55 -0800 Message-ID: <20231220145701.740912-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3018.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
Series |
x86/cet: Update CET kernel interface
|
|
Message
H.J. Lu
Dec. 20, 2023, 2:56 p.m. UTC
Changes in v4. 1. Rebase. 2. Remove 3 patches which have been checked into master branch. Changes in v3: 1. Remove 7 test patches which have been checked into master branch. Changes in v2: 1. Add add extra 20 stack frames in shadow stack for signal handlers when allocating shadow stack for ucontexts. 2. Remove the "x86: Check PT_GNU_PROPERTY early" patch which has been checked into master branch. Linux kernel 6.6 added SHSTK support for x86-64. This patch set updates CET kernel interface to Linux kernel 6.6. The main difference from the current glibc assumption is that SHSTK is enabled by glibc, instead of kernel. Glibc enables SHSTK after verifying that the application and all dependency libraries are CET enabled. SHSTK can only be enabled in a function which will never return. Otherwise, shadow stack will underflow at the function return. Not all CET enabled applications and libraries have been properly tested in CET enabled environments. Some CET enabled applications or libraries will crash or misbehave when CET is enabled. Don't set CET active by default so that all applications and libraries will run normally regardless of whether CET is active or not. Shadow stack can be enabled by $ export GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK at run-time if shadow stack can be enabled by kernel. Since only x86-64 is supported, i386 shadow stack codes are unchanged and CET shouldn't be enabled for i386. NB: This change can be reverted if it is OK to enable CET by default for all applications and libraries. Tested on Intel Tiger Lake under Linux kernel 6.6.7. H.J. Lu (6): x86/cet: Sync with Linux kernel 6.6 shadow stack interface elf: Always provide _dl_get_dl_main_map in libc.a x86/cet: Enable shadow stack during startup x86/cet: Check feature_1 in TCB for active IBT and SHSTK x86/cet: Don't set CET active by default x86/cet: Run some CET tests with shadow stack elf/dl-support.c | 2 - sysdeps/generic/ldsodefs.h | 8 +- sysdeps/unix/sysv/linux/x86/Makefile | 1 + .../sysv/linux/x86/allocate-shadow-stack.c | 62 +++++++++++++++ ...cpu-features.c => allocate-shadow-stack.h} | 33 ++------ sysdeps/unix/sysv/linux/x86/bits/mman.h | 5 ++ sysdeps/unix/sysv/linux/x86/dl-cet.h | 39 +++++++++- .../unix/sysv/linux/x86/include/asm/prctl.h | 37 ++++----- .../sysv/linux/x86/tst-cet-setcontext-1.c | 17 ++-- .../unix/sysv/linux/x86_64/__start_context.S | 38 ++------- sysdeps/unix/sysv/linux/x86_64/dl-cet.h | 47 +++++++++++ sysdeps/unix/sysv/linux/x86_64/getcontext.S | 30 ++------ sysdeps/unix/sysv/linux/x86_64/makecontext.c | 29 +++---- sysdeps/unix/sysv/linux/x86_64/swapcontext.S | 22 +----- sysdeps/x86/Makefile | 14 ++++ sysdeps/x86/bits/platform/x86.h | 8 ++ sysdeps/x86/cpu-features-offsets.sym | 1 + sysdeps/x86/cpu-features.c | 48 +----------- sysdeps/x86/cpu-tunables.c | 15 +++- sysdeps/x86/dl-cet.c | 77 +++++++++---------- sysdeps/x86/get-cpuid-feature-leaf.c | 13 +++- sysdeps/x86/include/cpu-features.h | 3 + sysdeps/x86/libc-start.h | 54 ++++++++++++- sysdeps/x86/sys/platform/x86.h | 17 ++++ sysdeps/x86/tst-shstk-legacy-1e-static.sh | 1 + sysdeps/x86/tst-shstk-legacy-1e.sh | 1 + sysdeps/x86/tst-shstk-legacy-1g.sh | 1 + sysdeps/x86_64/dl-machine.h | 12 ++- sysdeps/x86_64/nptl/tls.h | 2 +- 29 files changed, 391 insertions(+), 246 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/x86/allocate-shadow-stack.c rename sysdeps/unix/sysv/linux/x86/{cpu-features.c => allocate-shadow-stack.h} (53%) create mode 100644 sysdeps/unix/sysv/linux/x86_64/dl-cet.h