From patchwork Wed Jun 18 05:54:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 897539 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f54:0:b0:3a4:ee3f:8f15 with SMTP id cm20csp135135wrb; Tue, 17 Jun 2025 22:57:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIBxxG2urNwa1HJ3jSXWQXfGNwTz0KILfjpVN5m+jBRzke84x/awfeJVGz1pAuEl9qxrZswg==@linaro.org X-Google-Smtp-Source: AGHT+IFqMKrajNcNN6hCrf+LKOwYjGHU4rzFhjHQ0jN0uvFo+Ba4cd929rEMPAlx1Pg6AiwQkJEB X-Received: by 2002:a05:620a:4385:b0:7c4:bca3:6372 with SMTP id af79cd13be357-7d3e9219e34mr259331485a.0.1750226226514; Tue, 17 Jun 2025 22:57:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1750226226; cv=pass; d=google.com; s=arc-20240605; b=Q4xGzxPu4/PeDjtkSagnQLmxnXubrl5ebGLp1gwCU8GiCnDOfKLwGMevNgDxxCG9Um rzSL2DOtMszwGg6Yd7Yl4XGfF08iSzeC+orTagufgp/LhMRPAVlsxm7bZhd0kMjNppj/ /RONoqkWqp5Lc0spw4faQkaTAVF6OshEt8UZlcjNZuCYU99ZK4+6iYPEyMhmdhq8IUOA D6MJ+LuPl49X01CtutflaZCuMKdc7IOHxtaNdN36V4iMB+6PLxdpKORZ3jT6SbVcYWVM P3F6pU0WCEHrjJA5bQ8EnBCl2vOXg4MV7+NixcVweXna3NbWzxydkqmM3LEbXWRu2H+U NK+g== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=TFZwSzq/KDbGqApCaY7nwS7NEJ592QNeaA48FD4nUyo=; fh=v0Swrqm/HGzmFfs2Lyn4KGEK39u4NVWMm4qGXeDZh/s=; b=P8RmKCn5irFTUjgrGRrs7dFMTkdoNr6a8vsPkVI8YeeiLPBymNBQ/BToz/FVaXAIxF NJ2RVFssO9azUEdOw7+3TKrxjX0txHW/33GSnYNq3prpTWOlAYEI1K3Z+SACPYOw4ftx 1OrfKmPLqeLkcNeHBbTP91IX/qoO8wu/WklFF93x7XN0iZ7pimIp157+x/5rihFJs1VS XI+0ZmiA2WgnR/itjuIOuxt+Y1tHgbr0i+OWv5uQRPbtuvh3s+OXvatZproW7csAOXZA VJ4s1lu5PHA8QQTc5/D1CUTuRlIoti8ucjR3k7YOGeYxVlakEjJlOHHS28gcGPZAecwe 0LXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d0ZECguQ; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id af79cd13be357-7d3b8ef3ec8si1368891285a.393.2025.06.17.22.57.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 22:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d0ZECguQ; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 B55193835C25 for ; Wed, 18 Jun 2025 05:57:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B55193835C25 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=d0ZECguQ X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 389763835C25 for ; Wed, 18 Jun 2025 05:54:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 389763835C25 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 389763835C25 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::535 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750226092; cv=none; b=byF9V6uJVGP2qpJ3+hMdyHfJSsJB44SXs6xw2zwEW7BTx4NISc7EqBIwm5JSqYduOhjThMGXDFcM+lh/Q9W+A6YuHNWPUf8OZr0hkwQOPBgTO4oeSDR4Vi5aP7YjP/bfrVqzBkP//OktWZL90ZRjWOdiVIl3FvRhVfByAkeXJmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750226092; c=relaxed/simple; bh=1rJftsMxCQzy/QNhjpamBDi/m3aCMOlBnDvqvXuLXtQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oTTY+iQi2Zt/jDhKqPqocdftNpIwWUHzmuA9I62stLtvymTdVdODScq1JMbiizTsyODyQh0NllOrk0XBrUWw4FRp07b2PbzJMDcDsR33rwGovehfHnGUWmMYwYRJiRm8BK+PSuuFjSCjg80g4CbVVp5ZyW/9MNviUSl/YzoWKbk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 389763835C25 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-b2c4476d381so308506a12.0 for ; Tue, 17 Jun 2025 22:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1750226091; x=1750830891; 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=TFZwSzq/KDbGqApCaY7nwS7NEJ592QNeaA48FD4nUyo=; b=d0ZECguQnWOXPZdfV9tMAQYLCbumBVgksktNhlASa9UT4/gCIuWhUZmwMS3HlyA1AX ok9Rba/vwWUgxuwks5VUJ44NotNYtHl1m6gCqyPWu2RCRGJxP9mrjEFHQdHr2jnoeoMz KpA31oP05bXS2cRzDkzK/S7yS5FzrV2ShP6ytHJTW5pu0DFTSyWERnp/dcT/+bwo6yC/ HIAKgTZVdaSdzAemzsletXGejqOAzpTPcvlXTrmgIiHuvExl1oeWTGPlVgstVBxI7ogn VLRf7S0mbwIHTjZzO2j2eekuZ0sF5LHvrBCREly3zXDjRSlgytSkiTyXdM1lOYVxdpzG Wxmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750226091; x=1750830891; 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=TFZwSzq/KDbGqApCaY7nwS7NEJ592QNeaA48FD4nUyo=; b=f14EmwDCi8vbmnFjJ/1XXh5SrGBHvXTDWYuaqPqPUMs6niJ9NhJciKXkOV7d2vJX6b PvRT3aQW0gZx90zK0VYpm8hdGaZoqMV5QyOYQnjeeq+TdhWS276f4cMzsLdY686QGkUg fXwpQCxZriu9V5Q7zSScIvNMlBpDb+pgznI//JyPAMSDZ1QS+9VoolrrLcArwNk16VeI jNkO17zFKDtrpSUslv+ATIQRBEYzSGF5qik/qiSap6bRnY4i8pmmvR2xaMsAtTMyuDUd tOFthqeMP4PQ5OYFVQk2fy120xGhnQEohwFzlVkXK6/KNIdx6PpzDy9NyPYXggX8vO8i e0vw== X-Gm-Message-State: AOJu0YwAvTe2+AdFIjV3YquGacKhIdHgCcyCiUOii8B4m9WwuOmR25Po 1s//gDLbybrWffY5B778LcRTIjHI269kf26sADKkanmdSsoNHw3YpnkVp1S4hJmJXMWPZh+ptbY c+SIr X-Gm-Gg: ASbGncs0ibF9LGc5aWz2F22FRQo20ZZ5pQ0OFcvUqLfz6Zd/Wktwe+fHEayL5AK28MT CgC/CQ38riaDG57ZpeWdS9/9zShUx8EiwI+b01snQKLVyVXb1CAFmeqA2BV/yQsV2Bs8ukcfHJB rLOQYYUjgbXDhIgZEbcaH8T8igtmyGeSEijYXIojHlBMC0vILFlDuljY1XA2F/C/DfYSXx8VdKk NyOnmQ7JMLQ7BaVMjfgMKWclFCp7ffDLd1s6m5ZEbpyjPWFQTSTiqdo6d0zxzLxhCkhKXdu3AgF JPnM3tM3WEj+Gi7qQD4zXJtHjeVueGOpFT9m8Uk8/wwCXXDMfy1zxF25LwpoJh0yAiCn X-Received: by 2002:a17:90b:3c48:b0:311:ab20:1591 with SMTP id 98e67ed59e1d1-3157c86a744mr2164125a91.15.1750226091072; Tue, 17 Jun 2025 22:54:51 -0700 (PDT) Received: from localhost ([2804:14d:7e39:88d6:ae12:97ab:a9:43c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-313c1c5e2ebsm11782643a91.33.2025.06.17.22.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 22:54:50 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Eli Zaretskii , "Schimpe, Christina" , Luis Machado Subject: [PATCH v2 1/9] GDB: Linux: Add function linux_address_in_shadow_stack_mem_range Date: Wed, 18 Jun 2025 02:54:37 -0300 Message-ID: <20250618055445.709416-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250618055445.709416-1-thiago.bauermann@linaro.org> References: <20250618055445.709416-1-thiago.bauermann@linaro.org> 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 From: Christina Schimpe The function comes from the following patch from the Intel CET shadow stack support series: [PATCH v4 07/11] gdb: Handle shadow stack pointer register unwinding for amd64 linux. AArch64 also needs the function for unwinding the GCSPR, so include it in this patch series. Abridged-by: Thiago Jung Bauermann --- gdb/linux-tdep.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ gdb/linux-tdep.h | 7 +++++++ 2 files changed, 54 insertions(+) This is the patch mentioned above: https://inbox.sourceware.org/gdb-patches/20250617121147.1956686-8-christina.schimpe@intel.com/ Minus the change in amd64-linux-tdep.c and the testcase. Patch 8 in this series adds the corresponding AArch64 change and testcase. diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 1e339b59e2e8..c532b8758bfa 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -47,6 +47,7 @@ #include "gdbsupport/unordered_map.h" #include +#include /* This enum represents the values that the user can choose when informing the Linux kernel about which memory mappings will be @@ -96,6 +97,10 @@ struct smaps_vmflags /* Memory map has memory tagging enabled. */ unsigned int memory_tagging : 1; + + /* Memory map used for shadow stack. */ + + unsigned int shadow_stack_memory : 1; }; /* Data structure that holds the information contained in the @@ -537,6 +542,8 @@ decode_vmflags (char *p, struct smaps_vmflags *v) v->shared_mapping = 1; else if (strcmp (s, "mt") == 0) v->memory_tagging = 1; + else if (strcmp (s, "ss") == 0) + v->shadow_stack_memory = 1; } } @@ -3036,6 +3043,46 @@ show_dump_excluded_mappings (struct ui_file *file, int from_tty, " flag is %s.\n"), value); } +/* See linux-tdep.h. */ + +bool +linux_address_in_shadow_stack_mem_range + (CORE_ADDR addr, std::pair *range) +{ + if (!target_has_execution () || current_inferior ()->fake_pid_p) + return false; + + const int pid = current_inferior ()->pid; + + std::string smaps_file = string_printf ("/proc/%d/smaps", pid); + + gdb::unique_xmalloc_ptr data + = target_fileio_read_stralloc (nullptr, smaps_file.c_str ()); + + if (data == nullptr) + return false; + + const std::vector smaps + = parse_smaps_data (data.get (), std::move (smaps_file)); + + auto find_addr_mem_range = [&addr] (const smaps_data &map) + { + bool addr_in_mem_range + = (addr >= map.start_address && addr < map.end_address); + return (addr_in_mem_range && map.vmflags.shadow_stack_memory); + }; + auto it = std::find_if (smaps.begin (), smaps.end (), find_addr_mem_range); + + if (it != smaps.end ()) + { + range->first = it->start_address; + range->second = it->end_address; + return true; + } + + return false; +} + /* To be called from the various GDB_OSABI_LINUX handlers for the various GNU/Linux architectures and machine types. diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h index 7485fc132a63..7083635b976c 100644 --- a/gdb/linux-tdep.h +++ b/gdb/linux-tdep.h @@ -117,4 +117,11 @@ extern CORE_ADDR linux_get_hwcap2 (); extern struct link_map_offsets *linux_ilp32_fetch_link_map_offsets (); extern struct link_map_offsets *linux_lp64_fetch_link_map_offsets (); +/* Returns true if ADDR belongs to a shadow stack memory range. If this + is the case, assign the shadow stack memory range to RANGE + [start_address, end_address). */ + +extern bool linux_address_in_shadow_stack_mem_range + (CORE_ADDR addr, std::pair *range); + #endif /* GDB_LINUX_TDEP_H */