From patchwork Fri Jul 11 13:52:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Huang X-Patchwork-Id: 116135 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 540A83858C98 for ; Fri, 11 Jul 2025 13:56:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 540A83858C98 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=UxwS55MN X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 46EEE3858D20 for ; Fri, 11 Jul 2025 13:53:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46EEE3858D20 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 46EEE3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752241984; cv=none; b=ARaDL/mU6Nv/ABLjQbq8fou++WIdowToNfcom5mRluESdZJNR7uiRdPx4NZSowXl/dIknc1/HJ5jY6x9k7RRfaJlBu9HVxPqP+6dzdOa4ggUoaWANPd2krsm0WVQrgHD6d13PpQCrKJREbOA4M1GFizK8e7xuK8QaV0dEqY3thc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752241984; c=relaxed/simple; bh=AzMpxCdVdRx99adNgp6X0Gukjwb7fcs5+a4UYCHOO6I=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GrH0PzCNUu1cgNHDs9775BQ8EeGIylL0Eynah5IQVJM44taW9ibbQybGNKe59fo5I8WO0weOXebxkmQ1RtUHqM9/NA8EiGwux2U9ETFbSqNYvTvoE60kdO4Tm+F+y/DujN5tcgSSELHaYvuD4lz3aRnLwI4Se5WY5853c3HOrTM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46EEE3858D20 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-234f17910d8so22255675ad.3 for ; Fri, 11 Jul 2025 06:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1752241983; x=1752846783; 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=UxwS55MNH0x8L6fq45egK8klGZI5MVdCszcpz7ImkPUvet9Y4bkCG+C8N/ReMom8mA n9EQmID0Ty+WEkbTPkk9MoiL/tQY4lseESu+HkYwSGLFJk29kMHcdZHJahfRlim2xjkw IAe25dzqa6kHAiv8o7FcPKa+riPc2vd83W+yBJfb/805ojXZcL2RybxNgKzipUy36qrx o20mYiRCt0ZRF83LkvgY1S1mmObipN+iU7NWSz8FVY3YlaON/eb4Is0c4kRZBxZ4hbL3 ayWHXV3dyjsTRrOcNVKU5Jg9Hc76AwZadBrqxdTjf57dQwwCBArI6aR0HE2/U1yEjCGU gRkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752241983; x=1752846783; 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=TYIqkSvL6dMejsPs1syz/elcm5s9TMaQpYdIkm4R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AGHT+IGM6PxNEdmGXouTOWhW7kA5oOjyhdqkEIUz5TtjDc54K66BtLLEJq9FunddG9ThfbDQLf0CRw== X-Received: by 2002:a17:902:c94b:b0:235:f3df:bbff with SMTP id d9443c01a7336-23dede2eb8cmr47819735ad.4.1752241982599; Fri, 11 Jul 2025 06:53:02 -0700 (PDT) Received: from sw08.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4283b67sm48058295ad.3.2025.07.11.06.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 06:53:02 -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 v2 01/14] riscv: Add --enable-cfi option for controlling cfi features Date: Fri, 11 Jul 2025 06:52:42 -0700 Message-Id: <20250711135255.1732496-2-jesse.huang@sifive.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250711135255.1732496-1-jesse.huang@sifive.com> References: <20250711135255.1732496-1-jesse.huang@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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