From patchwork Sun Jun 8 01:03:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 894802 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp1175773wrb; Sat, 7 Jun 2025 18:06:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCJSHuoHEev7lohxQEvyzl2E0HWvIH7YHNgq02YFsx6vNGRUkZ88jPnrhiad0E/eK8pSQvjw==@linaro.org X-Google-Smtp-Source: AGHT+IG1Cd3UCB4bkwu7Us3Rv/bE9VJu0tyf6UWsxIxQFkhndfI/UUqMSBtvpjftYldv5HpAsT7P X-Received: by 2002:a05:6214:5298:b0:6fa:ccb6:602c with SMTP id 6a1803df08f44-6fb08fcca5emr148545096d6.32.1749344803016; Sat, 07 Jun 2025 18:06:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1749344803; cv=pass; d=google.com; s=arc-20240605; b=HsIG7M0JhTZPDbZC2lISsKHLKxqrkvOl9AKf9LHJ1iIO4wIDSsJfsnECrC7/M/wSdi GQdSzpASQLPqJUE+0/PL5CL99ubh0Oe+DR14hUb0fEReH5C71mC5/0KCWBz8WM0YVyTg 63gP7CxGzVxZhFWMdyww4ZUtyIjNYyASU0XId5phSAPW9OQ5TmprIXpdfwtJVxV/R2Ac TVfc3EvVHlQaAhpHbUqVpmQ/ZNKlaoCzSaMX+BNzdTVGrLMYJVKD6vT0i9nJ2WW5FJhl pLCjcCdeYn8J4jDKWigxXYP2lpDXbNUPmHxXOi7nnWXS34NBzii1NJkqwYFSnnxmwXua oquA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=lQdHUdBUzq+IIjnDCdTlLmyIEiWgtdK1kf0hur+/9xU=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=DuvlzCNnjmRbQ9dHCN1WqPyGhH2D1XZhkZ/X297ZRrN2tyxVWQo87GtZKF6t/ni2bh esBrrauoUAvwP3gll5ix8Taoi+o1KQ+uAsWBDfeYNMmovvaW8iAErw+0fAD1lfxReJW6 5IXo35UnpbpkhqltpfK7OzkoXtNGARkCnk8Xw2xEPgkcjjkiXANMvewGe3p2PF4QcDYx leeMj9Fe8mb3SS3y1kGmUwnMl3aEfJXPjzAw+UF1r9cJgzrcXxVBIJ5JwNTf46x7TbQ5 D+42hjtLylaEgLJUO3K6Fj/OXIlSy3HX2fIPjPpGU/JGtQkgCkw7VKbO59rUrLq+aLfj vBRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qIP8JkHb; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 6a1803df08f44-6fb09b16cf5si48690496d6.182.2025.06.07.18.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jun 2025 18:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qIP8JkHb; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F4093858D26 for ; Sun, 8 Jun 2025 01:06:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F4093858D26 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qIP8JkHb X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by sourceware.org (Postfix) with ESMTPS id 39D633858D26 for ; Sun, 8 Jun 2025 01:03:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39D633858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 39D633858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::e32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749344622; cv=none; b=NcFAyqPEExhDlZvOSe7ncHG4Nu4BKlLPkzN0ZskaojEr8XF7E6p8eeZ0Hqu5QbvLwvN1moXAUQgqWWnKdHJF4VekSOQXj2C0Dv7AEB61JN0bmgu6eWhsJ/NZc7Q598ib0M3HftLMuI+0U2rMgx8yGRI3u8ng2A2UfxDIqKK1DJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749344622; c=relaxed/simple; bh=bsOYo0IGlkLpppRHiiAFPh7FEAldfVQCNmILGMoLcRs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uyuqoaz1GMdajv8UHbW66AHhDEoW9Klhjq4KqDeybTu5f/9BeH26QTvJeeabfP8/H0Qls0z6FOn8CBxohKe3k5N9BZNyu4XpAcaPjSmPGz3gkjkjXmFZBGMU3UAvF1bvkek7gfJZeDE7/querVHYTCTCIsmrfnr1MBGDzL60uzg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39D633858D26 Received: by mail-vs1-xe32.google.com with SMTP id ada2fe7eead31-4e6312895d0so946730137.3 for ; Sat, 07 Jun 2025 18:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749344621; x=1749949421; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=lQdHUdBUzq+IIjnDCdTlLmyIEiWgtdK1kf0hur+/9xU=; b=qIP8JkHbSWGOQeK7yKZgiISnMEH/AP8gu4EiRlgZgG2KRAPFhV1j2y/TRjNCj9EPLH PGErh7lWI2u8dDTfSBOjeC65O3I2dj2ifRhQIZxPM8Grw0VXWXoYCMeE3wiCAFe8uqa+ wILctH2mTlNvvz8QHwnPZVBMktysRpoxDpo1ruSZl/I6K0McW3xlKdn5GAI+B9n7JyYZ K8yy2nUr8AlefFeiRN1Qx6Ck2vhxmXTXG0WHZOTnmAotx8l84askGD/aFd31y2zVevMo hK16XckAlHqz3VQKBWsMtIqwywagTaea64GYeSsdXQ78qrFAQrPA0rQa2FpP7/+vMPrC aZrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749344621; x=1749949421; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lQdHUdBUzq+IIjnDCdTlLmyIEiWgtdK1kf0hur+/9xU=; b=kmchgAhiV8sohhBtAeacRKmk57eNFsKjm+SxH3HvXyzb1McRecYmnHth2oiwsZQfKO ZFgyKdaW39q1JSu1hNWkNH6e7klW+xOZdvy2dNgSdsmjW0Iep/R+YXyz615B6ZYcaP3l fBregCxpcbEGiOwiFDu5v6TSJ16/oVlAOx/A1nt00k5JifEwLwOtyIssItdtldsuQhF+ LwxMYT+SD4cvLkH9r5D31RpTGnKOjSeegMG30xWn17Sl3Y1KF0DJSRhOjwUfz00julmg CL/BLM/Gzb36ejEN76AQDkxuC+KhIAT6TbOH2PeeKUIYAZpzEI8ZUijcHJ0KQS1n4rQX sBtA== X-Gm-Message-State: AOJu0YwQDBcB0pbadIwdrV9wmkwdqsJabSt3YrsjZjrtOIakMp7kSeKF unFs5evRyKQgNhl+28pJcTj8b9xxMri0c7OubTHW/txUxr1Zmpigbfv/HJ9XdhZ2jZQ1Pp4O/Gk JZ/DH X-Gm-Gg: ASbGncv1QOUAPAviLaa7qFxn1NmuVNka0l0sxoXO11nLQAz4TG86lfgOTKJhXypri+P N5299NntX1XRCoxwfSrCW8YdVecr6X414MDv7+UhpXZ+bDW/7tHK6GFvSqAFTUzFhVb0toqkXrm gp0BSaQVC7Tvh9pBr+Wtu0BsgJQ2LoHHTXeA6ogd4Qp0WFXJ3mCKgFCUfmPWjicLo4x1X5x/6yy 0uj1S4nBMUo/ocCQXezYrSZijtqgB2DY5d1EUxGQqRIIvFBh7nXTrxrE/U5Ay50BN86ES7PqSkB NqInKnTgPMIJbBvkgjl+lQBm+vWbgFV4+FkxBKMfxKnNZMvR7mjk8HM7HrCDJQ== X-Received: by 2002:a05:6102:3f87:b0:4e5:963b:738a with SMTP id ada2fe7eead31-4e7729cb504mr7281823137.16.1749344621371; Sat, 07 Jun 2025 18:03:41 -0700 (PDT) Received: from localhost ([2804:14d:7e39:88d6:8cb1:1e8e:e951:f687]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4e77394bd1esm3120164137.24.2025.06.07.18.03.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jun 2025 18:03:40 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [PATCH 0/8] AArch64 Guarded Control Stack support Date: Sat, 7 Jun 2025 22:03:11 -0300 Message-ID: <20250608010338.2234530-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patch=linaro.org@sourceware.org Hello, This patch series adds support for AArch64's Guarded Control Stack (GCS) feature in GDB and gdbserver. With it enabled, a processor will keep a secondary stack just for return addresses and push into it when a function is called, so that on function return it can check whether control is returning to the correct location. This protects against corrupted stacks and return-oriented programming. Intel has a similar Shadow Stack feature. The Linux kernel supports GCS in userspace since v6.13. This patch series applies on top of Christina Schimpe's "[PATCH v3 00/11] Add CET shadow stack support"¹ series. For convenience, I pushed the branch users/bauermann/gcs to the GDB repo containing the whole stack. I know we're somewhat close to the branch day, but it would be great if this series could get in the GDB 17.1 release... To this end I split the GCS patches in two series, and this one contains the more straightforward patches. I have a second, small series that applies on top of this one which adds a few new commands to work with GCS/shadow stacks, and also a new frame "decoration" to help the user see when a frame's return address doesn't match the one on the stack. These changes may need some discussion so I'll send them separately in the near future. Tested on aarch64-linux-gnu, both native and with native-extended-gdbserver. I'm still running regression tests for native-extended-gdbserver, and will report here if I find any issue. ¹ https://inbox.sourceware.org/gdb-patches/20250507164620.2394003-1-christina.schimpe@intel.com/ Thiago Jung Bauermann (8): bfd/aarch64-linux: Support reading and writing the GCS core file note GDB: doc: Improve AArch64 and ARM subsubsection titles in gdb.texinfo GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support GDB: aarch64-linux: GCS support in Linux signals GDB: aarch64-linux: Implement GCS support in displaced stepping GDB: testsuite: Add gdb.arch/aarch64-gcs.exp testcase GDB: testsuite: Add gdb.arch/aarch64-gcs-core.exp testcase GDB: testsuite: Add gdb.arch/aarch64-gcs-disp-step.exp testcase bfd/elf.c | 31 ++++ gdb/NEWS | 3 + gdb/aarch64-linux-nat.c | 79 ++++++++ gdb/aarch64-linux-tdep.c | 136 +++++++++++++- gdb/aarch64-tdep.c | 148 ++++++++++++++- gdb/aarch64-tdep.h | 14 ++ gdb/arch/aarch64-gcs-linux.h | 48 +++++ gdb/arch/aarch64.c | 8 + gdb/arch/aarch64.h | 10 +- gdb/doc/gdb.texinfo | 110 +++++++++--- gdb/features/Makefile | 2 + gdb/features/aarch64-gcs-linux.c | 21 +++ gdb/features/aarch64-gcs-linux.xml | 18 ++ gdb/features/aarch64-gcs.c | 14 ++ gdb/features/aarch64-gcs.xml | 11 ++ gdb/linux-tdep.h | 7 + gdb/testsuite/gdb.arch/aarch64-gcs-core.c | 124 +++++++++++++ gdb/testsuite/gdb.arch/aarch64-gcs-core.exp | 105 +++++++++++ .../gdb.arch/aarch64-gcs-disp-step.c | 140 +++++++++++++++ .../gdb.arch/aarch64-gcs-disp-step.exp | 90 ++++++++++ gdb/testsuite/gdb.arch/aarch64-gcs.c | 168 ++++++++++++++++++ gdb/testsuite/gdb.arch/aarch64-gcs.exp | 78 ++++++++ gdb/testsuite/lib/gdb.exp | 62 ++++++- gdbserver/linux-aarch64-low.cc | 46 +++++ include/elf/common.h | 3 + 25 files changed, 1435 insertions(+), 41 deletions(-) create mode 100644 gdb/arch/aarch64-gcs-linux.h create mode 100644 gdb/features/aarch64-gcs-linux.c create mode 100644 gdb/features/aarch64-gcs-linux.xml create mode 100644 gdb/features/aarch64-gcs.c create mode 100644 gdb/features/aarch64-gcs.xml create mode 100644 gdb/testsuite/gdb.arch/aarch64-gcs-core.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-gcs-core.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-gcs.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-gcs.exp