From patchwork Mon Oct 27 04:26:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Huang X-Patchwork-Id: 122659 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 2E75E3858C25 for ; Mon, 27 Oct 2025 04:30:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E75E3858C25 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=AUtphDiQ X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 4AEA73858D29 for ; Mon, 27 Oct 2025 04:26:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AEA73858D29 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4AEA73858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1031 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761539210; cv=none; b=H1XOv/+cobYsReDRX8ud4b8yFj9eB2559dbIyWd5I6tyuMu+tbiEmX4mKYRjLrw5WMxeLMk0+g/mINN38Rc1uxfuUVk6HZDYlbW8vlOmfoyPHrLsTr//I37XhxxgIImMPbxEX2NdOHpd7R9sA1HTgHTdzJApE89424k1sGy+xBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761539210; c=relaxed/simple; bh=AzMpxCdVdRx99adNgp6X0Gukjwb7fcs5+a4UYCHOO6I=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mptySd+CqERT+xdpK/X6MFwdaajQf9Gr3m3vRlJ/6XD/mHX64TOHNfxxkFYUqUOMOPgPqGG2B9ur19ZYJirhYCaNWnkh1Yz/9E4Un/7U+OAqeqDuozD6iiPyh9xm7at6xXv4BUYmRSU/GdAfFzAeSGVBx7wRKm89qhOAlc2zd/Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AEA73858D29 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-33b9dc8d517so4079091a91.0 for ; Sun, 26 Oct 2025 21:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1761539209; x=1762144009; 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=TYIqkSvL6dMejsPs1syz/elcm5s9TMaQpYdIkm4RbH8=; b=AUtphDiQIf6wSlNmDWkByJKPxg2e8ZI1AdkzeKWprmI7riuaaOd1Q6lqldvfl+mdTf H00+umeTzxXYHGJ0Nnhc34bXRek8mMNsz6M/tYkXLr679LSXqcD0q7LiH/pE47Z6Fv4S iaTmdkg0joPg+AN66gSwhhTPbA4VJAPoe4tdbswrLR/z7DesECacYXovnvSuHk51oenT mfmC4zKrioCBtKIAnyGD1J8+bVwS5H2xq1TauvS+zQ8wUOW+cYIPhyX2ziJMku2+t9WP RMme4l68ycSnIyN5tt3OYuxXttEx8b/UXWPB/1PN2f5SarrI/TFjiYHq1KiQZQisQgoQ /p5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761539209; x=1762144009; 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=TYIqkSvL6dM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4/mV/5ZRc/5FD2UiTYQT126o2U7qnGJV7HABjVol3P LCo+cObCKBXK+SipxzX4ltHNs55hYViSlqKKGcmwExf6jnAk8jqP1alvN6uj9wvNtAAVEVpdDJH VeiDFM2LL7UzvFn6YN4 X-Google-Smtp-Source: AGHT+IEdpETuCSwMacwEvX1OZcE3cU+xeaITagmulahYJW47aRFO0KKhqAntSPdC681JxhUacnNC0w== X-Received: by 2002:a17:90b:5386:b0:33b:b308:7655 with SMTP id 98e67ed59e1d1-33bcf861fc3mr47576056a91.8.1761539208671; Sun, 26 Oct 2025 21:26:48 -0700 (PDT) Received: from sw08.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-33fed80df16sm6765734a91.15.2025.10.26.21.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Oct 2025 21:26:47 -0700 (PDT) From: Jesse Huang To: libc-alpha@sourceware.org Cc: andrew@sifive.com, darius@bluespec.com, debug@rivosinc.com, jlaw@ventanamicro.com, kito.cheng@sifive.com, palmer@dabbelt.com, Jesse Huang Subject: [PATCH v3 01/16] riscv: Add --enable-cfi option for controlling cfi features Date: Sun, 26 Oct 2025 21:26:19 -0700 Message-Id: <20251027042634.2665717-2-jesse.huang@sifive.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20251027042634.2665717-1-jesse.huang@sifive.com> References: <20251027042634.2665717-1-jesse.huang@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 --- INSTALL | 13 +++++++++++++ NEWS | 3 +++ configure | 12 ++++++++++++ configure.ac | 6 ++++++ manual/install.texi | 12 ++++++++++++ 5 files changed, 46 insertions(+) diff --git a/INSTALL b/INSTALL index d3200f271f..476861b521 100644 --- a/INSTALL +++ b/INSTALL @@ -155,6 +155,19 @@ passed to 'configure'. For example: NOTE: '--enable-cet' is only supported on x86_64 and x32. +'--enable-cfi' + Enable RISC-V Control Flow Integrity Extensions (Zicfilp/Zicfiss) + support. When the GNU C Library is built with '--enable-cfi', the + resulting library is protected with landing pad and shadow stack. + This feature is currently supported on RV64 with GCC 15 and + binutils 2.45 or later. With '--enable-cfi', it is an error to + dlopen a non CFI enabled shared library in CFI enabled application. + The restriction can be loosen by setting to permissive mode with + the use of the glibc tunables, see glibc tunables section for more + information. + + NOTE: '--enable-cfi' is only supported on RV64. + '--enable-memory-tagging' Enable memory tagging support if the architecture supports it. When the GNU C Library is built with this option then the resulting diff --git a/NEWS b/NEWS index 521fbd5e07..02a39b05e4 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,9 @@ Major new features: * The ISO C2Y family of unsigned abs functions, i.e. uabs, ulabs, ullabs and uimaxabs, are now supported. +* Added --enable-cfi option to enable the RISC-V CFI extensions + (Zicfilp/Zicfiss) support on RV64 Linux. + Deprecated and removed features, and other changes affecting compatibility: * The glibc.rtld.execstack now supports a compatibility mode to allow diff --git a/configure b/configure index 7cda641fce..5a996c8f25 100755 --- a/configure +++ b/configure @@ -818,6 +818,7 @@ enable_nscd enable_pt_chown enable_mathvec enable_cet +enable_cfi enable_scv enable_fortify_source with_cpu @@ -1499,6 +1500,7 @@ Optional Features: depends on architecture] --enable-cet enable Intel Control-flow Enforcement Technology (CET), x86 only + --enable-cfi enable Control Flow Integrity (CFI), RISC-V only --disable-scv syscalls will not use scv instruction, even if the kernel supports it, powerpc only --enable-fortify-source[=1|2|3] @@ -4853,6 +4855,16 @@ esac fi +# Check whether --enable-cfi was given. +if test ${enable_cfi+y} +then : + enableval=$enable_cfi; enable_cfi=$enableval +else case e in #( + e) enable_cfi=no ;; +esac +fi + + # Check whether --enable-scv was given. if test ${enable_scv+y} then : diff --git a/configure.ac b/configure.ac index 0b0d8875cc..9bda3d1520 100644 --- a/configure.ac +++ b/configure.ac @@ -421,6 +421,12 @@ AC_ARG_ENABLE([cet], [enable_cet=$enableval], [enable_cet=$libc_cv_compiler_default_cet]) +AC_ARG_ENABLE([cfi], + AS_HELP_STRING([--enable-cfi], + [enable Control Flow Integrity (CFI), RISC-V only]), + [enable_cfi=$enableval], + [enable_cfi=no]) + AC_ARG_ENABLE([scv], AS_HELP_STRING([--disable-scv], [syscalls will not use scv instruction, even if the kernel supports it, powerpc only]), diff --git a/manual/install.texi b/manual/install.texi index 7fcdda9146..d3e7153365 100644 --- a/manual/install.texi +++ b/manual/install.texi @@ -185,6 +185,18 @@ non CET enabled shared library in CET enabled application. NOTE: @option{--enable-cet} is only supported on x86_64 and x32. +@item --enable-cfi +Enable RISC-V Control Flow Integrity Extensions (Zicfilp/Zicfiss) support. +When @theglibc{} is built with @option{--enable-cfi}, the resulting +library is protected with landing pad and shadow stack@. +This feature is currently supported on RV64 with GCC 15 and binutils 2.45 +or later. With @option{--enable-cfi}, it is an error to dlopen a non CFI +enabled shared library in CFI enabled application. The restriction can be +loosen by setting to permissive mode with the use of the glibc tunables, +see glibc tunables section for more information. + +NOTE: @option{--enable-cfi} is only supported on RV64. + @item --enable-memory-tagging Enable memory tagging support if the architecture supports it. When @theglibc{} is built with this option then the resulting library will