From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0E57C433F5 for ; Wed, 9 Mar 2022 20:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SNAMkdlOBiPydEEy1h0snNgtqAH0nk9EB3DnXo5buZE=; b=HuuPQnwu10zmFl iv5KjgdcjpCs2Wt6wTQlHgH6d4QleT4gNXfWShksFKBZeDsFH75myc4AVZmNYBUTWLHXgZ4dwi9Op t3wXNKRXdxIOHSbhH5TaFF5mRqWdTTgHJIyxFlkxz5+W9y8S4WD5kQbDMbWyFHJl7J0ZXfXkeV7Dn t8qCPtpQKDWrEgV7hg15oIlNdFao2c8M9Ofyts08LVEYDgE0xphbDdmr8LBM49El4HBngl9mnz9qO D6gWXwCmrYtnp+/1eYzyNnZAal6JfAoLxxnGzlZID55YxZd7JjHBLgtbkQXj8TacXw4aO0eIAY++m PRVxf75GcvjRV6rax3YA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS2ju-00AOTP-Ab; Wed, 09 Mar 2022 20:16:54 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS2jr-00AOS4-6U for linux-arm-kernel@lists.infradead.org; Wed, 09 Mar 2022 20:16:52 +0000 Received: by mail-pg1-x52a.google.com with SMTP id o23so2869402pgk.13 for ; Wed, 09 Mar 2022 12:16:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6BaluqbU/Z25J2R97A+4bgdc+ob1O3EWcsEpPLgF3pk=; b=ISdtbAOwnBbYGM4PCvpKrrw5HmGmfUq3wg3g9OLspUaLc+zFWwDqcVsYfOgzslDf9L 8ZVKnke21o94g0bfC8pnuFzNLInuTyhowTRNulQ+CAFOHtaG0pSBOXjDS2XuX6b8YzvF ilTdwW3UUTtdTskFFMnGU9GNP34o5UgoK+vm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6BaluqbU/Z25J2R97A+4bgdc+ob1O3EWcsEpPLgF3pk=; b=DL9bPKQ/h40cThuFF8ZFS7ep2WnMWrorMj27qJoNCKm7ZzzgWKVjpDPOH9LS6Q090a o/ca8LU00BumOmCeEQ6VhQTI8zUmqfFlxxl0y4pYf8QklJTe9UZCoQeGaB/K5wqqMcQ3 Vjdl3C9G+iSYIEJ3eNhTo72o/atkmE/O6WaWF5ql/lvrzGJN7MrfyJrCdbaUReYzea/g hrpnyjCe+gdYBlUT3YcuzaEUwe6NzGt/v1RX2TcQc58tksnno9XDwPPxemhnWn+GxbFM rloZTTcFPbsHUO+NjumQ7WndzsVRNh19smv5if8Ue0wxwNs4TNz31MUxXQpdvZWQRSew VPAg== X-Gm-Message-State: AOAM530uy5WFos2qJs0xOrIyzD2CENqqzWwEHB0UDoceoVWSPBvzGbvV LDFFVJ0S26Gmx2KL31A32GVmbA== X-Google-Smtp-Source: ABdhPJwlFCfuaoDPFowRrKqu5kBpvMkL/ybtBrvNihxj3zKsFGRIqd0H9DrqrIK7H2SCt/BiTczTZA== X-Received: by 2002:a05:6a00:2168:b0:4f6:eb64:71dd with SMTP id r8-20020a056a00216800b004f6eb6471ddmr1450854pff.40.1646857008474; Wed, 09 Mar 2022 12:16:48 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e6-20020a63aa06000000b00380c8bed5a6sm1650747pgf.46.2022.03.09.12.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Mar 2022 12:16:48 -0800 (PST) Date: Wed, 9 Mar 2022 12:16:47 -0800 From: Kees Cook To: Dan Li Cc: akpm@linux-foundation.org, arnd@arndb.de, catalin.marinas@arm.com, gregkh@linuxfoundation.org, linux@roeck-us.net, luc.vanoostenryck@gmail.com, elver@google.com, mark.rutland@arm.com, masahiroy@kernel.org, ojeda@kernel.org, nathan@kernel.org, npiggin@gmail.com, ndesaulniers@google.com, samitolvanen@google.com, shuah@kernel.org, tglx@linutronix.de, will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH v3 2/2] lkdtm: Add Shadow Call Stack tests Message-ID: <202203091211.4F00F560@keescook> References: <20220303073340.86008-1-ashimida@linux.alibaba.com> <20220303074339.86337-1-ashimida@linux.alibaba.com> <202203031010.0A492D114@keescook> <202203031105.A1B4CAE6@keescook> <92a767c4-09e1-8783-2581-9848bb72890d@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <92a767c4-09e1-8783-2581-9848bb72890d@linux.alibaba.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220309_121651_251767_678D2C7D X-CRM114-Status: GOOD ( 23.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Mar 07, 2022 at 07:16:36AM -0800, Dan Li wrote: > The following code seems to work fine under clang/gcc, x86_64/aarch64 > (also tested in lkdtm_CFI_BACKWARD_SHADOW): > > #include > > static __attribute__((noinline)) > void set_return_addr(unsigned long *expected, unsigned long *addr) > { > /* Use of volatile is to make sure final write isn't seen as a dead store. */ > unsigned long * volatile *ret_addr = (unsigned long **)__builtin_frame_address(0) + 1; > > /* Make sure we've found the right place on the stack before writing it. */ > if(*ret_addr == expected) > *ret_addr = (addr); > } > > static volatile int force_label; > > int main(void) > { > void *array[] = {0, &&normal, &&redirected}; > > if (force_label) { > /* Call it with a NULL to avoid parameters being treated as constants in -02. */ > set_return_addr(NULL, NULL); > goto * array[force_label]; > } Hah! I like that. :) I had a weird switch statement that was working for me; this is cleaner. > > do { > > set_return_addr(&&normal, &&redirected); > > normal: > printf("I should be skipped\n"); > break; > > redirected: > printf("Redirected\n"); > > } while (0); > > return 0; > } > > But currently it still crashes when I try to enable > "-mbranch-protection=pac-ret+leaf+bti". > > Because the address of "&&redirected" is not encrypted under pac, > the autiasp check will fail when set_return_addr returns, and > eventually cause the function to crash when it returns to "&&redirected" > ("&&redirected" as a reserved label always seems to start with a bti j > insn). Strictly speaking, this is entirely correct. :) > For lkdtm, if we're going to handle both cases in one function, maybe > it would be better to turn off the -mbranch-protection=pac-ret+leaf+bti > and maybe also turn off -O2 options for the function :) If we can apply a function attribute to turn off pac for the "does this work without protections", that should be sufficient. -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel