From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 9B2653858D1E for ; Fri, 30 Sep 2022 19:34:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B2653858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1029.google.com with SMTP id x32-20020a17090a38a300b00209dced49cfso2550212pjb.0 for ; Fri, 30 Sep 2022 12:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=hxsllICQwFXPvnSYU6uGhWp0J8pUo6TWGKC/ynF8s4g=; b=hHRK91NvDWtqZv5v7TNPNcoqpbTJWzb1nea68OABs1upZSLkSCYs6fvgSAmRXeurqP bb1U1+1fk6wwhKlGgss4y7LoDwcpHVp3cKcpg0A8HMfTI14hXgIrotFu6VFE1Fd1gmlx FDujMecggDzbU+d39MWdU7jYbjpfiKPy7ahIwxt1xLR8RDgYACjVdBUIGHnwwVz6WvxV Ts7zXZT+Ih0oYxub81yVETURZbBAjktM/J/39ZptBR/nhJkabWDngwA/OQeZ5krgZkke oMvKew9iw6eDqexXsxS0XC82WO/xE3Obhw3KLcse3i1hNtZBegKA5PaxtaNAwWft0jgP y7fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=hxsllICQwFXPvnSYU6uGhWp0J8pUo6TWGKC/ynF8s4g=; b=0wVCgwCajzpnDsEepnW5V8vWHghek8TzGBgweqH0Z0r6pRICzX5/P6APjDKohsOQdP 44GrAlVPFEmBeRpxP45OyYkyqTOdHQzpQx0ZDzsM67oTL3HtcFERW7QO0s+A6MbnWFEv KjXE2/4iZAMD1/gq1/TxQRhvJZ7j7jmQlywMRmgPZnmgUQFQEvT9BtJrPP/BLA90Yt3A 6ioMXRDeOKLWuiwbIz7rTL9p06wmMjBn8YSJxbL4W1hUSbDJcDJtZmsLRofDES93j2sx 4VZv1nX6Src1bWf9OepGlPDX0Ke++w/ocCpoub0pGkSTnNdCUZ+tpPEM6lFdkYVDVCPw 7xxw== X-Gm-Message-State: ACrzQf0YUuk/bSjhc4pN+nfXvsYkfgpNgWucJfGhI3UEpnE9AEJjYtwm GI1d7zDTSrUuhIGsl8+STlQmC7q6bbmb7w== X-Google-Smtp-Source: AMsMyM5YXaOSeRNjxT8l2K6pvlMGHFSq7BN85s3ZlQb4YWEfYk3YVklejf5R3JHegGC+k5IEQpanGg== X-Received: by 2002:a17:902:d2d2:b0:177:4940:cc0f with SMTP id n18-20020a170902d2d200b001774940cc0fmr10228929plc.4.1664566440159; Fri, 30 Sep 2022 12:34:00 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id 7-20020a620507000000b0055de3e207c9sm804060pff.35.2022.09.30.12.33.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Sep 2022 12:33:59 -0700 (PDT) Message-ID: Date: Fri, 30 Sep 2022 13:33:58 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH] x86: Check corrupted return address when unwinding stack Content-Language: en-US To: gcc-patches@gcc.gnu.org References: <20220921204206.95480-1-hjl.tools@gmail.com> From: Jeff Law In-Reply-To: <20220921204206.95480-1-hjl.tools@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,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 List-Id: On 9/21/22 14:42, H.J. Lu via Gcc-patches wrote: > If shadow stack is enabled, when unwinding stack, we count how many stack > frames we pop to reach the landing pad and adjust shadow stack by the same > amount. When counting the stack frame, we compare the return address on > normal stack against the return address on shadow stack. If they don't > match, return _URC_FATAL_PHASE2_ERROR for the corrupted return address on > normal stack. Don't check the return address for > > 1. Non-catchable exception where exception_class == 0. Process will be > terminated. > 2. Zero return address which marks the outermost stack frame. > 3. Signal stack frame since kernel puts a restore token on shadow stack. > > * unwind-generic.h (_Unwind_Frames_Increment): Add the EXC > argument. > * unwind.inc (_Unwind_RaiseException_Phase2): Pass EXC to > _Unwind_Frames_Increment. > (_Unwind_ForcedUnwind_Phase2): Likewise. > * config/i386/shadow-stack-unwind.h (_Unwind_Frames_Increment): > Take the EXC argument. Return _URC_FATAL_PHASE2_ERROR if the > return address on normal stack doesn't match the return address > on shadow stack. The generic bits are fine.  While I'm aware of one other target that _might_ need adjustment, it's an out-of-tree target and thus clearly not your responsibility. jeff