Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2394125pxb; Sun, 17 Oct 2021 13:40:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkGPBGv0PHEBsxsG4mvL59Bxy5LElAZ6WALNka6YMAhep5aadAexM1C6fq9X6qrWfBCCEI X-Received: by 2002:a17:906:314e:: with SMTP id e14mr23959461eje.165.1634503226198; Sun, 17 Oct 2021 13:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634503226; cv=none; d=google.com; s=arc-20160816; b=lTx8Kh1+THqHOmzuXA+JOJ19uxxFF/3eipATWKRjuFLgMOrfLeLAk4I1eubuW9uR22 mD1aFiHlt/Nh3M5ENsi+E4SAR3umKQSx3orqEAVIFuZr6iwTajPkL+iGHmtKG/jJPs/K VcTwUbg1nVJ0UD9cP1k1b89d3Lxvd7uX7TQjPoXWRvkVsU6tGP+S1AUs5ShcvGvGb0Xu 2FvGcdn5GDfWMNovoT9mB5NPQoppxrcwyUcXhWi4FTg7nqXPhmo2eg/b1UuyJbxDf78m lRfERekEkDtuWef+nLTNCyAWTXWy/WWubEe6xdp30etMbjTBPyAu6/jhgpKL0aL8HdcY b4nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=HBzr0B3tGGPW4EBa2LvZed6scqvnq5Oml+sl03YQDio=; b=eYMQJYH/ocvvjJGDKgfMUnDk1O3FUJ0YOhv9+w2irJhIKMaR2uBhYVvr3QGM29aN7X NpXgU19lOYkulXjdEcUJXlraz/q+fKDRKXcMB52bS5AWAFotB+5NicdBLQLYxP+EwX9U UWu0VxmU6fob2mbLA10olX5mSUKatEECgwSJe+ja+wsA0zki9jnGoPawUyyIjd2Cz46+ l8qkgS+y51CjykWj16EE5Hq/BODlVOeVxEgWuzAOOFO4ZeIqfn5Uep565Tr6u5sA5xZy MLfPlCAblxBdGZP9hmet7o3BrDjqKZ+CNZ9JM33OJtmVznMOhYIZUggWhDkTlDNfcwRt O1vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="BA/5lSdu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i24si17699692ejy.159.2021.10.17.13.40.01; Sun, 17 Oct 2021 13:40:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="BA/5lSdu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230439AbhJOTQA (ORCPT + 99 others); Fri, 15 Oct 2021 15:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242668AbhJOTPy (ORCPT ); Fri, 15 Oct 2021 15:15:54 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D345C061570 for ; Fri, 15 Oct 2021 12:13:46 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id n8so45516189lfk.6 for ; Fri, 15 Oct 2021 12:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HBzr0B3tGGPW4EBa2LvZed6scqvnq5Oml+sl03YQDio=; b=BA/5lSdu+5ROrNUsKhvi+0xgDXMbeH1IeW/bUOWfcmhvn1b5gplsN/lhjVCre6mi7A T02zPFwlJIn5jPNjwH4oOtQyucvs6lBBcy+OrsPY3YL/FYdY0J233zlFzQbbtj4HgTc2 L9417guhXF0JmPaEr+m4IC2Neu+S/CP0pe8W1DeWsGEaRfcbKuXMoiVVLIsmZUAZYhDW i839MhmZ7hNt4oiL/fD/Ou4ujKkHeGGDRRmS1Lm9czlqguFwu1qDQyHbuiiIuclaTR8n zgTo8mkTKOfB8QZ+Z9qaTsaUNQSAUoM7AdYTjJhuqe3g1u8w9OuBkFHS5pOcW6IIJz3a cmzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HBzr0B3tGGPW4EBa2LvZed6scqvnq5Oml+sl03YQDio=; b=knKxQy4e2pT148EqRtCag84syxUzG5f/n8Hm/QMuysXHlkVFjFVQazIXo+eZ6QEF0o vI9OzKKl/mMV7ZmP8mrRtnj98hnoj7UaJi0UiEbMNzwAiilBMP9fbEz0dBLF5Cek2zsM 3YH+dSk//hIJi8ZWzYRrwZGTgGYJNeyKMJLp7lXvUqklFp0HcpE6dRHAUFbE1EaepZvA J++bAEdzVbdnL7Ibkgs9dexOqVgzuRYROu8YAlcP1EsaVSHj3XeZnwHYGr9l0D5bWpvl ZmZCTySAMop73/E+TtVsMaYOmFXdV4L1zOGVHXKNTbf100i3z9LxOzj9LaqHKqbl0Ard yyTQ== X-Gm-Message-State: AOAM5319cTR0QJ80Lrr3ykJAGoqzvK32pcHB1U2Qola9iGnnzQU709VS Oznfauw1LoeXavi/XUoIeaPr4bUEjo5EVvhLRd+JmQ== X-Received: by 2002:a05:6512:3ba3:: with SMTP id g35mr13415925lfv.651.1634325224740; Fri, 15 Oct 2021 12:13:44 -0700 (PDT) MIME-Version: 1.0 References: <1634167668-60198-1-git-send-email-ashimida@linux.alibaba.com> <722d9662-e27c-2efb-e8cf-d505b6950475@linux.alibaba.com> In-Reply-To: <722d9662-e27c-2efb-e8cf-d505b6950475@linux.alibaba.com> From: Nick Desaulniers Date: Fri, 15 Oct 2021 12:13:33 -0700 Message-ID: Subject: Re: [PATCH] [PATCH V4]ARM64: SCS: Add gcc plugin to support Shadow Call Stack To: Dan Li Cc: masahiroy@kernel.org, michal.lkml@markovi.net, catalin.marinas@arm.com, will@kernel.org, keescook@chromium.org, nathan@kernel.org, tglx@linutronix.de, akpm@linux-foundation.org, samitolvanen@google.com, frederic@kernel.org, rppt@kernel.org, mark.rutland@arm.com, yifeifz2@illinois.edu, rostedt@goodmis.org, viresh.kumar@linaro.org, andreyknvl@gmail.com, colin.king@canonical.com, ojeda@kernel.org, luc.vanoostenryck@gmail.com, elver@google.com, nivedita@alum.mit.edu, ardb@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hardening@vger.kernel.org, clang-built-linux@googlegroups.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 15, 2021 at 11:29 AM Dan Li wrote: > > > > On 10/15/21 2:44 AM, Nick Desaulniers wrote: > > On Wed, Oct 13, 2021 at 4:28 PM Dan Li wrote: > >> --- a/include/linux/compiler-gcc.h > >> +++ b/include/linux/compiler-gcc.h > >> @@ -50,6 +50,10 @@ > >> #define __latent_entropy __attribute__((latent_entropy)) > >> #endif > >> > >> +#if defined(SHADOW_CALL_STACK_PLUGIN) && !defined(__CHECKER__) > >> +#define __noscs __attribute__((no_shadow_call_stack)) > >> +#endif > > > > Cool this is a nice addition, and something I don't think that clang > > has. For any new feature, having a function attribute to disable it > > at the function granularity is nice, and plays better with LTO than -f > > group flags. Though that begs the question: what happens if a __noscs > > callee is inlined into a non-__noscs caller, or vice versa? > Thanks Nick, > > According to my understanding, all inline optimizations in gcc should > happen before inserting scs insns (scs and paciasp/autiasp use the > same insertion point). Therefore, the check for the __noscs attribute > will also occur after all inlining is completed. > > As in the following example: > - Since __noscs attribute is specified, scs_test1 does not insert scs insns > - Since normal functions scs_test2/3 uses x30, it needs to insert scs insns > - Since __noscs attribute is specified, scs_test4 after inlining does not > need to insert scs insns > > __always_inline __noscs void scs_test1(void) > { > asm volatile("mov x1, x1\n\t":::"x30"); > } > > //scs insns inserted after function inline > void scs_test2(void) > { > scs_test1(); > } That may be surprising to developers. Perhaps __always_inline on scs_test1 is distracting this test case, but I suspect it may not make a difference. This particular issue comes up time and again with stack protectors; ie. the callee is marked no stack protector, then gets inlined into a caller and suddenly gets a stack protector. > > __always_inline void scs_test3(void) > { > asm volatile("mov x3, x3\n\t":::"x30"); > } > > //no scs insns inserted > __noscs void scs_test4(void) > { > scs_test3(); > } > > ffff800010012900 : > ffff800010012900: a9bf7bfd stp x29, x30, [sp, #-16]! > ffff800010012904: 910003fd mov x29, sp > ffff800010012908: aa0103e1 mov x1, x1 > ffff80001001290c: a8c17bfd ldp x29, x30, [sp], #16 > ffff800010012910: d65f03c0 ret > > ffff800010012914 : > ffff800010012914: f800865e str x30, [x18], #8 > ffff800010012918: a9bf7bfd stp x29, x30, [sp, #-16]! > ffff80001001291c: 910003fd mov x29, sp > ffff800010012920: aa0103e1 mov x1, x1 > ffff800010012924: a8c17bfd ldp x29, x30, [sp], #16 > ffff800010012928: f85f8e5e ldr x30, [x18, #-8]! > ffff80001001292c: d65f03c0 ret > > ffff800010012930 : > ffff800010012930: f800865e str x30, [x18], #8 > ffff800010012934: a9bf7bfd stp x29, x30, [sp, #-16]! > ffff800010012938: 910003fd mov x29, sp > ffff80001001293c: aa0303e3 mov x3, x3 > ffff800010012940: a8c17bfd ldp x29, x30, [sp], #16 > ffff800010012944: f85f8e5e ldr x30, [x18, #-8]! > ffff800010012948: d65f03c0 ret > ffff80001001294c: d503201f nop > > ffff800010012950 : > ffff800010012950: a9bf7bfd stp x29, x30, [sp, #-16]! > ffff800010012954: 910003fd mov x29, sp > ffff800010012958: aa0303e3 mov x3, x3 > ffff80001001295c: a8c17bfd ldp x29, x30, [sp], #16 > ffff800010012960: d65f03c0 ret > > I noticed that __noscs isn't actually applied anywhere in the kernel, > > yet, at least in this series. Were there any places necessary that > > you've found thus far? > At present, I have not found a function that must use the __noscs > attribute in the kernel. I have only used this attribute in test cases. -- Thanks, ~Nick Desaulniers