From patchwork Wed Dec 6 17:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 81537 Return-Path: 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 3BA193865C2C for ; Wed, 6 Dec 2023 17:21:15 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 91E843858005 for ; Wed, 6 Dec 2023 17:20:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91E843858005 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 91E843858005 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::530 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701883221; cv=none; b=i9vy0AgiLaV6oUwwAKQrVbyX27eKP4rpCZBuiehsEBGr+thsfVoXfZdZAFj8EE8oJzLtbWWkfti4WB77Dpu5UHzoxJVGXZRwq0ksFGsKXMJ09CQcTfHVFcjDEr7EhCmYdZM43AFUHcgMHw6xVat3odyd1oV9EUO43rBPyscV2hU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701883221; c=relaxed/simple; bh=U7KtRUd4W+8d58U0hiS7FViS0HH/Rp0YE4Is1fguNT0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=inh/C+C9lJ7zGILul4s78cWUfBqsDZRMvqEQGYmXnppnXNSUduh7Hv+PTgQZ/ZUk1uyqvphPHN8dhRbr2xr2wE+7RNweaF+Yg8mUZpyr0LITVbdtICQmg+t9q8L/T2+HHEdGRdiVuc5zxZ+yMC7QIswBBz5Il59dJhOXNmT071s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5c690c3d113so2857903a12.1 for ; Wed, 06 Dec 2023 09:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701883217; x=1702488017; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WokAJGlqrtoizPOZj4+PiZkzpP7EhDImCNe72omnP0M=; b=Lep+32rPeAU1PBfpkmKlhRyWmoIL0PwApc9KdGU3iSgZzBM3ldQjcUIFJDbexcu4sB oDYjnpE8+NSTwz08oZ6ebExLUazz/YSo+KsQG/resKvYDCmN0h8OdhiBdMnA6mnMPiat YlrwHmk7YjO5b/twAxmD8hie02j8A5AbWfyW9t2v8V4pbVj4etRy5y1ox+ZJV5olR8Ua BIbQXMBcUBqFog6+yzg0GbgzoLO+QORfxcDE1JdQzeU/t7XobnfvkYAtieeyjzJk/oa/ otVqkxXrcU/G4YkgB6PStDGRkSRcL5EXV2YGU3chyaXr7MeMnH86zHah5T8EzzPk3KDs Gf1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701883217; x=1702488017; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WokAJGlqrtoizPOZj4+PiZkzpP7EhDImCNe72omnP0M=; b=ccENnoLtZ1EEOxe9ndhJM6bOZNR/xltRmih1C9nJ389bW2YGeaOHJdc8leibCF4xfa Jrprt7JO6xKvG1nT3Cun4OMmUVJHqbrGI7gvfYaPSiMvMWRcWPscSCPBqfdWEfGhjZBF 1zD0U+WZgtgr6vpCjSa57QkBmn+rOc3B+PfG7YLONSg3IyM1DRSCrYZ9IRILIVPqZN80 TMPDxx+o2Q0Plybw8cJSlhx2FW2e2pCuCRgnFoarzFkA1Jnjc1XdLMZeu38oDrxD/t/C Ah6UPAGeoEH3VeDmi5io+OteeFcZCCnJgiC2aRyu2RXsKwBxTWLUhVN+6p0B/G0z0iwQ uNZA== X-Gm-Message-State: AOJu0YyliPSILGOK8Asz9+LGXOUTZ4U73M+fr5njk3oUK4tcul0YVP1Q /I5Y9n41363d6aTDI5PiNugPFLCxeW8= X-Google-Smtp-Source: AGHT+IHo/IyWWYLJLequpoDC2FJU2xdxoTMA72TvcIMEy4Un00JIhSazGq0tjLx+b7hwP7oe6STcmQ== X-Received: by 2002:a05:6a20:c1a6:b0:187:604a:3add with SMTP id bg38-20020a056a20c1a600b00187604a3addmr1466443pzb.24.1701883217499; Wed, 06 Dec 2023 09:20:17 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.59.161.253]) by smtp.gmail.com with ESMTPSA id a1-20020a637f01000000b005ac384b71cbsm150150pgd.60.2023.12.06.09.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 09:20:16 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id BCF5C740633; Wed, 6 Dec 2023 09:20:10 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: rick.p.edgecombe@intel.com Subject: [PATCH 10/17] x86: Modularize sysdeps/x86/dl-cet.c Date: Wed, 6 Dec 2023 09:20:03 -0800 Message-ID: <20231206172010.1023415-11-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231206172010.1023415-1-hjl.tools@gmail.com> References: <20231206172010.1023415-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3025.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Improve readability and make maintenance easier for dl-feature.c by modularizing sysdeps/x86/dl-cet.c: 1. Support processors with: a. Only IBT. Or b. Only SHSTK. Or c. Both IBT and SHSTK. 2. Lock CET features only if IBT or SHSTK are enabled and are not enabled permissively. --- sysdeps/x86/dl-cet.c | 456 ++++++++++++++++++++++++++----------------- 1 file changed, 280 insertions(+), 176 deletions(-) diff --git a/sysdeps/x86/dl-cet.c b/sysdeps/x86/dl-cet.c index 60ea1cb558..67c51ee8c2 100644 --- a/sysdeps/x86/dl-cet.c +++ b/sysdeps/x86/dl-cet.c @@ -32,206 +32,310 @@ # error GNU_PROPERTY_X86_FEATURE_1_SHSTK != X86_FEATURE_1_SHSTK #endif -/* Check if object M is compatible with CET. */ +struct dl_cet_info +{ + const char *program; + + /* Check how IBT and SHSTK should be enabled. */ + enum dl_x86_cet_control enable_ibt_type; + enum dl_x86_cet_control enable_shstk_type; + + /* If IBT and SHSTK were previously enabled. */ + unsigned int feature_1_enabled; + + /* If IBT and SHSTK should be enabled. */ + unsigned int enable_feature_1; + + /* If there are any legacy shared object. */ + unsigned int feature_1_legacy; + + /* Which shared object is the first legacy shared object. */ + unsigned int feature_1_legacy_ibt; + unsigned int feature_1_legacy_shstk; +}; + +/* Check if the object M and its dependencies are legacy object. */ static void -dl_cet_check (struct link_map *m, const char *program) +dl_check_legacy_object (struct link_map *m, + struct dl_cet_info *info) { - /* Check how IBT should be enabled. */ - enum dl_x86_cet_control enable_ibt_type - = GL(dl_x86_feature_control).ibt; - /* Check how SHSTK should be enabled. */ - enum dl_x86_cet_control enable_shstk_type - = GL(dl_x86_feature_control).shstk; - - /* No legacy object check if both IBT and SHSTK are always on. */ - if (enable_ibt_type == cet_always_on - && enable_shstk_type == cet_always_on) + unsigned int i; + struct link_map *l = NULL; + + i = m->l_searchlist.r_nlist; + while (i-- > 0) { - THREAD_SETMEM (THREAD_SELF, header.feature_1, GL(dl_x86_feature_1)); - return; - } + /* Check each shared object to see if IBT and SHSTK are enabled. */ + l = m->l_initfini[i]; - /* Check if IBT is enabled by kernel. */ - bool ibt_enabled - = (GL(dl_x86_feature_1) & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0; - /* Check if SHSTK is enabled by kernel. */ - bool shstk_enabled - = (GL(dl_x86_feature_1) & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0; + if (l->l_init_called) + continue; - if (ibt_enabled || shstk_enabled) - { - struct link_map *l = NULL; - unsigned int ibt_legacy = 0, shstk_legacy = 0; - bool found_ibt_legacy = false, found_shstk_legacy = false; - - /* Check if IBT and SHSTK are enabled in object. */ - bool enable_ibt = (ibt_enabled - && enable_ibt_type != cet_always_off); - bool enable_shstk = (shstk_enabled - && enable_shstk_type != cet_always_off); - if (program) +#ifdef SHARED + /* Skip check for ld.so since it has the features enabled. The + features will be disabled later if they are not enabled in + executable. */ + if (l == &GL(dl_rtld_map) + || l->l_real == &GL(dl_rtld_map) + || (info->program != NULL && l == m)) + continue; +#endif + + /* IBT and SHSTK set only if enabled in executable and all DSOs. + NB: cet_always_on is handled outside of the loop. */ + info->enable_feature_1 &= ((l->l_x86_feature_1_and + & (GNU_PROPERTY_X86_FEATURE_1_IBT + | GNU_PROPERTY_X86_FEATURE_1_SHSTK)) + | ~(GNU_PROPERTY_X86_FEATURE_1_IBT + | GNU_PROPERTY_X86_FEATURE_1_SHSTK)); + if ((info->feature_1_legacy + & GNU_PROPERTY_X86_FEATURE_1_IBT) == 0 + && ((info->enable_feature_1 + & GNU_PROPERTY_X86_FEATURE_1_IBT) + != (info->feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_IBT))) { - /* Enable IBT and SHSTK only if they are enabled in executable. - NB: IBT and SHSTK may be disabled by environment variable: - - GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK - */ - enable_ibt &= (CPU_FEATURE_USABLE (IBT) - && (enable_ibt_type == cet_always_on - || (m->l_x86_feature_1_and - & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0)); - enable_shstk &= (CPU_FEATURE_USABLE (SHSTK) - && (enable_shstk_type == cet_always_on - || (m->l_x86_feature_1_and - & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0)); + info->feature_1_legacy_ibt = i; + info->feature_1_legacy |= GNU_PROPERTY_X86_FEATURE_1_IBT; } - /* ld.so is CET-enabled by kernel. But shared objects may not - support IBT nor SHSTK. */ - if (enable_ibt || enable_shstk) - { - unsigned int i; + if ((info->feature_1_legacy + & GNU_PROPERTY_X86_FEATURE_1_SHSTK) == 0 + && ((info->enable_feature_1 + & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + != (info->feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_SHSTK))) + { + info->feature_1_legacy_shstk = i; + info->feature_1_legacy |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; + } + } - i = m->l_searchlist.r_nlist; - while (i-- > 0) - { - /* Check each shared object to see if IBT and SHSTK are - enabled. */ - l = m->l_initfini[i]; + /* Handle cet_always_on. */ + if ((info->feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0 + && info->enable_ibt_type == cet_always_on) + { + info->feature_1_legacy &= ~GNU_PROPERTY_X86_FEATURE_1_IBT; + info->enable_feature_1 |= GNU_PROPERTY_X86_FEATURE_1_IBT; + } - if (l->l_init_called) - continue; + if ((info->feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0 + && info->enable_shstk_type == cet_always_on) + { + info->feature_1_legacy &= ~GNU_PROPERTY_X86_FEATURE_1_SHSTK; + info->enable_feature_1 |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; + } +} #ifdef SHARED - /* Skip CET check for ld.so since ld.so is CET-enabled. - CET will be disabled later if CET isn't enabled in - executable. */ - if (l == &GL(dl_rtld_map) - || l->l_real == &GL(dl_rtld_map) - || (program && l == m)) - continue; +/* Enable IBT and SHSTK only if they are enabled in executable. Set + feature bits properly at the start of the program. */ + +static void +dl_cet_check_startup (struct link_map *m, struct dl_cet_info *info) +{ + /* NB: IBT and SHSTK may be disabled by environment variable: + + GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK. + */ + if (CPU_FEATURE_USABLE (IBT)) + { + if (info->enable_ibt_type == cet_always_on) + info->enable_feature_1 |= GNU_PROPERTY_X86_FEATURE_1_IBT; + else + info->enable_feature_1 &= ((m->l_x86_feature_1_and + & GNU_PROPERTY_X86_FEATURE_1_IBT) + | ~GNU_PROPERTY_X86_FEATURE_1_IBT); + } + else + info->enable_feature_1 &= ~GNU_PROPERTY_X86_FEATURE_1_IBT; + + if (CPU_FEATURE_USABLE (SHSTK)) + { + if (info->enable_shstk_type == cet_always_on) + info->enable_feature_1 |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; + else + info->enable_feature_1 &= ((m->l_x86_feature_1_and + & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + | ~GNU_PROPERTY_X86_FEATURE_1_SHSTK); + } + else + info->enable_feature_1 &= ~GNU_PROPERTY_X86_FEATURE_1_SHSTK; + + if (info->enable_feature_1 != 0) + dl_check_legacy_object (m, info); + + unsigned int disable_feature_1 + = info->enable_feature_1 ^ info->feature_1_enabled; + if (disable_feature_1 != 0) + { + /* Disable features in the kernel because of legacy objects or + cet_always_off. */ + if (dl_cet_disable_cet (disable_feature_1) != 0) + _dl_fatal_printf ("%s: can't disable x86 Features\n", + info->program); + + /* Clear the disabled bits. Sync dl_x86_feature_1 and + info->feature_1_enabled with info->enable_feature_1. */ + info->feature_1_enabled = info->enable_feature_1; + GL(dl_x86_feature_1) = info->enable_feature_1; + } + + if (HAS_CPU_FEATURE (IBT) || HAS_CPU_FEATURE (SHSTK)) + { + /* Lock CET features only if IBT or SHSTK are enabled and are not + enabled permissively. */ + unsigned int feature_1_lock = 0; + + if (((info->feature_1_enabled & GNU_PROPERTY_X86_FEATURE_1_IBT) + != 0) + && info->enable_ibt_type != cet_permissive) + feature_1_lock |= GNU_PROPERTY_X86_FEATURE_1_IBT; + + if (((info->feature_1_enabled & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + != 0) + && info->enable_shstk_type != cet_permissive) + feature_1_lock |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; + + if (feature_1_lock != 0 + && dl_cet_lock_cet () != 0) + _dl_fatal_printf ("%s: can't lock CET\n", info->program); + } + + THREAD_SETMEM (THREAD_SELF, header.feature_1, GL(dl_x86_feature_1)); +} #endif - /* IBT is enabled only if it is enabled in executable as - well as all shared objects. */ - enable_ibt &= (enable_ibt_type == cet_always_on - || (l->l_x86_feature_1_and - & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0); - if (!found_ibt_legacy && enable_ibt != ibt_enabled) - { - found_ibt_legacy = true; - ibt_legacy = i; - } - - /* SHSTK is enabled only if it is enabled in executable as - well as all shared objects. */ - enable_shstk &= (enable_shstk_type == cet_always_on - || (l->l_x86_feature_1_and - & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0); - if (enable_shstk != shstk_enabled) - { - found_shstk_legacy = true; - shstk_legacy = i; - } - } - } +/* Check feature bits when dlopening the shared object M. */ + +static void +dl_cet_check_dlopen (struct link_map *m, struct dl_cet_info *info) +{ + /* Check if there are any legacy objects loaded. */ + if (info->enable_feature_1 != 0) + { + dl_check_legacy_object (m, info); - bool cet_feature_changed = false; + /* Skip if there are no legacy shared objects loaded. */ + if (info->feature_1_legacy == 0) + return; + } - if (enable_ibt != ibt_enabled || enable_shstk != shstk_enabled) - { - if (!program) - { - if (enable_ibt_type != cet_permissive) - { - /* When IBT is enabled, we cannot dlopen a shared - object without IBT. */ - if (found_ibt_legacy) - _dl_signal_error (0, - m->l_initfini[ibt_legacy]->l_name, - "dlopen", - N_("rebuild shared object with IBT support enabled")); - } - - if (enable_shstk_type != cet_permissive) - { - /* When SHSTK is enabled, we cannot dlopen a shared - object without SHSTK. */ - if (found_shstk_legacy) - _dl_signal_error (0, - m->l_initfini[shstk_legacy]->l_name, - "dlopen", - N_("rebuild shared object with SHSTK support enabled")); - } - - if (enable_ibt_type != cet_permissive - && enable_shstk_type != cet_permissive) - return; - } - - /* Disable IBT and/or SHSTK if they are enabled by kernel, but - disabled in executable or shared objects. */ - unsigned int cet_feature = 0; - - if (!enable_ibt) - cet_feature |= GNU_PROPERTY_X86_FEATURE_1_IBT; - if (!enable_shstk) - cet_feature |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; - - int res = dl_cet_disable_cet (cet_feature); - if (res != 0) - { - if (program) - _dl_fatal_printf ("%s: can't disable CET\n", program); - else - { - if (found_ibt_legacy) - l = m->l_initfini[ibt_legacy]; - else - l = m->l_initfini[shstk_legacy]; - _dl_signal_error (-res, l->l_name, "dlopen", - N_("can't disable CET")); - } - } - - /* Clear the disabled bits in dl_x86_feature_1. */ - GL(dl_x86_feature_1) &= ~cet_feature; - - cet_feature_changed = true; - } + unsigned int disable_feature_1 = 0; + unsigned int legacy_obj = 0; + const char *msg = NULL; -#ifdef SHARED - if (program && (ibt_enabled || shstk_enabled)) + if ((info->feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0 + && (info->feature_1_legacy + & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0) + { + if (info->enable_ibt_type != cet_permissive) { - if ((!ibt_enabled - || enable_ibt_type != cet_permissive) - && (!shstk_enabled - || enable_shstk_type != cet_permissive)) - { - /* Lock CET if IBT or SHSTK is enabled in executable unless - IBT or SHSTK is enabled permissively. */ - int res = dl_cet_lock_cet (); - if (res != 0) - _dl_fatal_printf ("%s: can't lock CET\n", program); - } - - /* Set feature_1 if IBT or SHSTK is enabled in executable. */ - cet_feature_changed = true; + legacy_obj = info->feature_1_legacy_ibt; + msg = N_("rebuild shared object with IBT support enabled"); } -#endif + else + disable_feature_1 |= GNU_PROPERTY_X86_FEATURE_1_IBT; + } - if (cet_feature_changed) + /* Check the next feature only if there is no error. */ + if (msg == NULL + && (info->feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0 + && (info->feature_1_legacy + & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0) + { + if (info->enable_shstk_type != cet_permissive) { - unsigned int feature_1 = 0; - if (enable_ibt) - feature_1 |= GNU_PROPERTY_X86_FEATURE_1_IBT; - if (enable_shstk) - feature_1 |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; - struct pthread *self = THREAD_SELF; - THREAD_SETMEM (self, header.feature_1, feature_1); + legacy_obj = info->feature_1_legacy_shstk; + msg = N_("rebuild shared object with SHSTK support enabled"); } + else + disable_feature_1 |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; + } + + /* If there is an error, long jump back to the caller. */ + if (msg != NULL) + _dl_signal_error (0, m->l_initfini[legacy_obj]->l_name, "dlopen", + msg); + + if (disable_feature_1 != 0) + { + int res = dl_cet_disable_cet (disable_feature_1); + if (res) + { + if ((disable_feature_1 + & GNU_PROPERTY_X86_FEATURE_1_IBT) != 0) + msg = N_("can't disable IBT"); + else + msg = N_("can't disable SHSTK"); + /* Long jump back to the caller on error. */ + _dl_signal_error (-res, m->l_initfini[legacy_obj]->l_name, + "dlopen", msg); + } + + /* Clear the disabled bits in dl_x86_feature_1. */ + GL(dl_x86_feature_1) &= ~disable_feature_1; + + THREAD_SETMEM (THREAD_SELF, header.feature_1, + GL(dl_x86_feature_1)); + } +} + +static void +dl_cet_check (struct link_map *m, const char *program) +{ + struct dl_cet_info info; + + /* Check how IBT and SHSTK should be enabled. */ + info.enable_ibt_type = GL(dl_x86_feature_control).ibt; + info.enable_shstk_type = GL(dl_x86_feature_control).shstk; + + info.feature_1_enabled = GL(dl_x86_feature_1); + + /* No legacy object check if IBT and SHSTK are always on. */ + if (info.enable_ibt_type == cet_always_on + && info.enable_shstk_type == cet_always_on) + { +#ifdef SHARED + /* Set it only during startup. */ + if (program != NULL) + THREAD_SETMEM (THREAD_SELF, header.feature_1, + info.feature_1_enabled); +#endif + return; } + + /* Check if IBT and SHSTK were enabled by kernel. */ + if (info.feature_1_enabled == 0) + return; + + info.program = program; + + /* Check which features should be enabled. */ + info.enable_feature_1 = 0; + if (info.enable_ibt_type != cet_always_off) + info.enable_feature_1 |= (info.feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_IBT); + if (info.enable_shstk_type != cet_always_off) + info.enable_feature_1 |= (info.feature_1_enabled + & GNU_PROPERTY_X86_FEATURE_1_SHSTK); + + /* Start with no legacy objects. */ + info.feature_1_legacy = 0; + info.feature_1_legacy_ibt = 0; + info.feature_1_legacy_shstk = 0; + +#ifdef SHARED + if (program) + dl_cet_check_startup (m, &info); + else +#endif + dl_cet_check_dlopen (m, &info); } void