From patchwork Tue May 26 06:16:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Huang X-Patchwork-Id: 135659 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B07C4BA79AA for ; Tue, 26 May 2026 06:22:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B07C4BA79AA 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=hhKiHGXm X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dy1-x1336.google.com (mail-dy1-x1336.google.com [IPv6:2607:f8b0:4864:20::1336]) by sourceware.org (Postfix) with ESMTPS id 70E304BA79A1 for ; Tue, 26 May 2026 06:18:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70E304BA79A1 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 70E304BA79A1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1336 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779776282; cv=none; b=JnQLm42DUwqRcyw5gquYWdPEz7Pb/c1ZHN5vZESkiAhW/GFxk5lWV8Moqyn5q64uDVEYamPyl2jpWAl69zeiXk1GItRj4Y8o9jI5Gyro0QtVNBY10ifGU2jFX32Ke9lVwyIH5wMe/4FrMxCzm7O4FQbqvUR7JLZyoyTLJIVX2QA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779776282; c=relaxed/simple; bh=RDIwUMeHESk0wv8j7+GAqTI3RhsopgJsnJKXBodulyo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Dbimngt51mmXTDW5aGMc0h9lIfOBzy7r5gI7l7HjdNV9Q/BgBy1/oOSuFCJfZMuN11xwM3+bBGCC2MGtFw3rr/vRFR4vT1oAFZ743VudaWqgs97EVLllesKlyvXxbMgawbwsjFwq9zCbyTPabNwqKU779IV1GU58nc9Tk5a9p60= ARC-Authentication-Results: i=1; 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=hhKiHGXm DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70E304BA79A1 Received: by mail-dy1-x1336.google.com with SMTP id 5a478bee46e88-30455f77e0eso6908156eec.0 for ; Mon, 25 May 2026 23:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1779776281; x=1780381081; 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=BrFi0O5XNtH7f5Nk5ng1mh9zqw79iodt4J0GIi0xKpo=; b=hhKiHGXm/YS8mtjtGqcibSC+gGlqXYbQ6x4/kygeN7cz8YGNYN1mCs8Butfdqy5Lh9 byDC4qdMAzeu7RxoN+VGRrLLNkNBFcID8hVd+Pa9l+EsIIED3tWLqqemJAwD+PoOW3FZ aUgqVB/wroecuF3p8weyuVL0dGF4ky+OMv6Pxc+Tq8UdNWvFr5K0b2UJr+gj8mMnaMhK 5UU94NulT9rq+FKrTAxKARuVIeFujJjWnoLYgmh1U+4t4ZuRAwuUwy9qVkOHqS0/u5hj J/G/BE4/EEtwYkS7xxO/TVLljx8wrYec7Ti+ciHmtNHKnsUrv7le/Ytq/jn9f4upF8Fm JJvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779776281; x=1780381081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BrFi0O5XNtH7f5Nk5ng1mh9zqw79iodt4J0GIi0xKpo=; b=Aue6cgXlHRLxGuvsByQD2qEjF36waux8+1M+TJhneDFTFYGF76B61FmSXnC5LAiVNR Xv2lJxr/OThECu8c49fzMj1cU29KOfHTP1xe8x36iF/VCzkP+ZIYIbqI79wvv/x29+3o dvThePerFedEiDytmk/CIovnHDxTb6rZVZNTtg0IHDJAwBNVpiPjepKC/R5zNwUKl24C 2USTGZ1Q0pT4rLcUK5cvw1SDZWlrYlqHz21tt0NSdwud1cPu3jRu8D/7qUlJnnV8yQD3 D5XWCOTqV8SVLCjEWPy/Yu77IAs/0cJL7KdIu1rNG2WwAZqKPtU3jDaseeCixCDWikOC QbrQ== X-Gm-Message-State: AOJu0YzirNKNrwpo2Y8JHEZgSfQwIVooBZuGZDIxqemjR5SP0sim4l+9 fSJcdAM5tbc7C4zTc5JNRmBaAvaVB4kC64qhnXHJWtDD29+7GlO+t19hbbk4R0MLp1Ef50T58ZZ UJgLiyXbBqGBLMyQkikbseDe30D6hazPI2XLQx74AMydBgpukYHhpPTQae+YpTBCBFTsfvdPyOd Vpmde4lkV/AA33eOw7IUSFw+a1RBLY6rCFmuJ7i/i2p/O3ENgC X-Gm-Gg: Acq92OFeje+pDKBVgBL+FKt+VGTwbpUA2JWHEIKUK9/fIoVJHh/9/ds2BCAK1lrn7p7 Uu0KWJQ0mb0jS31D2qlIEswbsVgtqMpT1IBDNOwYpgOpAyGo6iY0e3CZPsgnqLkSLN/Y6A4sV4t dfsH2J8sjSgSXpKG1T237bNWWR0Xo84JQMJeuqdcvcttdskSIiCZLxzsikKt0yc3k3So8e10ozZ SnthwcpibIlJ6WQyYWN5HnQpjjizynQRD+ZOjCUxHL6PF4JBnngMkRyS7t/QegqWCfykMAH7sS3 6Ar3WLVOkUYnbr0iM1nmHhmGSTh+hLsBFRuayfJuXus+baNyr+n2r/zlMDHMUU/wwhJaDDqr1aQ lEbN4aAGbG7NAJS4qhBqFjgXpvb9TnoCGC8p3Cb4fE8YgJEk27GnMY3RIaM1Jv6RN6s0rZL42nj yEKeqaOhUJuAdldfXDS7Ff4yZhHXgBy9JWGLjTbUaK X-Received: by 2002:a05:7300:3b06:b0:2e6:e504:5431 with SMTP id 5a478bee46e88-30449149080mr8540724eec.22.1779776281311; Mon, 25 May 2026 23:18:01 -0700 (PDT) Received: from sw08.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30452461cb5sm14062504eec.31.2026.05.25.23.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 23:17:59 -0700 (PDT) From: Jesse Huang To: libc-alpha@sourceware.org Cc: andrew@sifive.com, darius@bluespec.com, debug@rivosinc.com, jeffreyalaw@gmail.com, kito.cheng@sifive.com, palmer@dabbelt.com, Jesse Huang Subject: [PATCH v4 06/17] riscv/cfi: Add prctl definitions for RISC-V CFI Date: Mon, 25 May 2026 23:16:52 -0700 Message-Id: <20260526061703.2188042-7-jesse.huang@sifive.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260526061703.2188042-1-jesse.huang@sifive.com> References: <20260526061703.2188042-1-jesse.huang@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 These operations are for setting/retrieving/locking the status of the landing pad and the shadow stack extensions. --- .../unix/sysv/linux/riscv/include/asm/prctl.h | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/riscv/include/asm/prctl.h diff --git a/sysdeps/unix/sysv/linux/riscv/include/asm/prctl.h b/sysdeps/unix/sysv/linux/riscv/include/asm/prctl.h new file mode 100644 index 0000000000..091a21b70d --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/include/asm/prctl.h @@ -0,0 +1,48 @@ +/* + * Get the current shadow stack configuration for the current thread, + * this will be the value configured via PR_SET_SHADOW_STACK_STATUS. + */ +#define PR_GET_SHADOW_STACK_STATUS 74 + +/* + * Set the current shadow stack configuration. Enabling the shadow + * stack will cause a shadow stack to be allocated for the thread. + */ +#define PR_SET_SHADOW_STACK_STATUS 75 +# define PR_SHADOW_STACK_ENABLE (1UL << 0) +# define PR_SHADOW_STACK_WRITE (1UL << 1) +# define PR_SHADOW_STACK_PUSH (1UL << 2) + +/* + * Prevent further changes to the specified shadow stack + * configuration. All bits may be locked via this call, including + * undefined bits. + */ +#define PR_LOCK_SHADOW_STACK_STATUS 76 + +/* + * Get the current indirect branch tracking configuration for the current + * thread, this will be the value configured via PR_SET_INDIR_BR_LP_STATUS. + */ +#define PR_GET_INDIR_BR_LP_STATUS 79 + +/* + * Set the indirect branch tracking configuration. PR_INDIR_BR_LP_ENABLE will + * enable cpu feature for user thread, to track all indirect branches and ensure + * they land on arch defined landing pad instruction. + * x86 - If enabled, an indirect branch must land on `ENDBRANCH` instruction. + * arch64 - If enabled, an indirect branch must land on `BTI` instruction. + * riscv - If enabled, an indirect branch must land on `lpad` instruction. + * PR_INDIR_BR_LP_DISABLE will disable feature for user thread and indirect + * branches will no more be tracked by cpu to land on arch defined landing pad + * instruction. + */ +#define PR_SET_INDIR_BR_LP_STATUS 80 +# define PR_INDIR_BR_LP_ENABLE (1UL << 0) + +/* + * Prevent further changes to the specified indirect branch tracking + * configuration. All bits may be locked via this call, including + * undefined bits. + */ +#define PR_LOCK_INDIR_BR_LP_STATUS 81