Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1995961pxp; Mon, 21 Mar 2022 09:09:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2vREWcK/cjHyUhy0rh7yuVL5Qxo6UymCvpIfUH6l7dTkFg62yA7RWVV/u5XvKlR4+hb+b X-Received: by 2002:a63:c24:0:b0:382:2a04:3dbe with SMTP id b36-20020a630c24000000b003822a043dbemr13456664pgl.158.1647878940404; Mon, 21 Mar 2022 09:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647878940; cv=none; d=google.com; s=arc-20160816; b=QKdLZU9RLMtzjwY3AyCAcz3XqMj8x1fTBO2L/GxFwjKm5wFW4WFaugOS+igTbyf+QE undwyLllDyj8YEV5B30QiM/mCcVyAPEaRwy5p7MMugJBa3tGtrKpB0VM3Tusae4z0IWV vLBejPj7ZM2gznHLMJuGnxasW5GMeDfGGxCYl4bMM/pL1/RNJQfPJIm5u+nvNep+SSTs tKumDTzQxlCm7ukX7ldotzgRcNn+FED0DGErGE9e2tcZzqUs8f6pxFcEUf0ow7KP36qG 34zvf/GMXDBDtN1laDNOsEBwY29yNk+2/U5GiMX+44ztVpnjFI5201ehA93iHHDZEosI GqNQ== 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=Uu3NPXS3YIK/joqnoO2dCxxZrdruyUVh70Rwb4NqWi8=; b=BrbjpmDKsEyb0T0qhqqyxkqWkLT4BcDWhQMLV/R30CGUzSgwUFbwoKOL+9AkKBXCnT +s+pmC9GCh3xlKhitFkIKnRZURkOLxnLLppa05KJPCHIONnO9i3+g2DfkxHa7N+D/OMm v/Azi0KnFGycOYGEKcnyNaKpdrCM3oXvsSK4TWvsF7Y9Nifl1US2EAZPf8ajUGHg7TA1 ofAASmQErmiqmLIo36/+MBI8vdvQyOsRI0T7NNl3bu0Rnh2NVAnHyGSjOWolcU12zXgY /OFX3g4/DAHt51yK9LWn5AqpCYpZjSn8bEJgCgOVBuoEfcLgyCFhBVncDC6oE/4Xrvkx R1jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=peCpeuak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a655c48000000b003816043eea8si12294630pgr.157.2022.03.21.09.08.44; Mon, 21 Mar 2022 09:09:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=peCpeuak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343690AbiCTVLL (ORCPT + 99 others); Sun, 20 Mar 2022 17:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244091AbiCTVLI (ORCPT ); Sun, 20 Mar 2022 17:11:08 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63EED46145 for ; Sun, 20 Mar 2022 14:09:44 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id k25so14811487iok.8 for ; Sun, 20 Mar 2022 14:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Uu3NPXS3YIK/joqnoO2dCxxZrdruyUVh70Rwb4NqWi8=; b=peCpeuakEvX6D9DkWAvoxRIedMD/39lVZWCnWMzXtri03y9r62H6zmrugVSd2V6Hnl yNgQlrRrkY5LOSfKIyB0mcQWaLclmNYbtS7Df8eBRfi86fUcUomspIvZeeMvSeYnj0in nDF7eZNpiFFCY/pjp6ygoxeX9KEC7hglQY1MN7LvMqX7SUur4xKzkWFvSSHIcgKt5CKK v6+ptK9uDU0LA9ECsg46r4NCs/Gxy4hQQtQ3XG5NJvScH196cq0hbQ7SE4TQYIBumZBV Vk/MJcmAZlhdSbuXePQoJqG7CWuQiogqYCmhdv574+F3DX+e+JE5bixYQtJtbH/UaKF1 nvyA== 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=Uu3NPXS3YIK/joqnoO2dCxxZrdruyUVh70Rwb4NqWi8=; b=cJEvYT1Xe5w5MXl3wVC/c5mT9QKFJMfACwDKuiPEE0wKbN43W8xBSLrEdjXyWALsW8 MI8g8MflriJomw7MiCuPtd2hzRtcEZagIDr9ekS4cc5K4svRxR2QFH5MP9qfLUH3lapi Rcrf5cKBlacy9C+6PBrB84geK3Um963bs6/lEdc3ScreY3cAcwAR9F2gGUHqEL5bG7Ec nEjtEvgmRoasq2lV/ytwZLHEl/7bKL1st6EJNhr9OKJdWqmGaZbXoiQFd8EB32Olj2XU p3Aj/1LzlVAGcgeQfjz3ChJLAIBCo9FdTO44lQQ8YLyvTj2TpaS2RZSZ1iFwZenskcn0 FkcA== X-Gm-Message-State: AOAM533ymKitaalsvqiHczLW2ROLGLx3CH9xkTE2qcN02uWdzFWsch4y xzwGWY+XFsFmrCp8UWMqcBz6ddYkB8I/N1NIWWI= X-Received: by 2002:a05:6638:210a:b0:31a:536e:4714 with SMTP id n10-20020a056638210a00b0031a536e4714mr10058666jaj.71.1647810583809; Sun, 20 Mar 2022 14:09:43 -0700 (PDT) MIME-Version: 1.0 References: <57133fafc4d74377a4a08d98e276d58fe4a127dc.1647115974.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Sun, 20 Mar 2022 22:09:33 +0100 Message-ID: Subject: Re: [PATCH] kasan, scs: collect stack traces from shadow stack To: Marco Elver Cc: andrey.konovalov@linux.dev, Alexander Potapenko , Andrew Morton , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Vincenzo Frascino , Catalin Marinas , Will Deacon , Mark Rutland , Sami Tolvanen , Peter Collingbourne , Evgenii Stepanov , Linux Memory Management List , LKML , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 14, 2022 at 8:01 AM Marco Elver wrote: > > > Instead of invoking the unwinder, collect the stack trace by copying > > frames from the Shadow Call Stack whenever it is enabled. This reduces > > boot time by 30% for all KASAN modes when Shadow Call Stack is enabled. > > This is impressive. I was surprised too. > > We could integrate shadow stack trace collection into kernel/stacktrace.c > > as e.g. stack_trace_save_shadow(). However, using stack_trace_consume_fn > > leads to invoking a callback on each saved from, which is undesirable. > > The plain copy loop is faster. > > Why is stack_trace_consume_fn required? This is an internal detail of > arch_stack_walk(), but to implement stack_trace_save_shadow() that's > not used at all. > > I think having stack_trace_save_shadow() as you have implemented in > kernel/stacktrace.c or simply in kernel/scs.c itself would be > appropriate. The other stack trace routines consistently use on stack_trace_consume_fn. But I think you're right, we don't need it. Will do in v2. > > We could add a command line flag to switch between stack trace collection > > modes. I noticed that Shadow Call Stack might be missing certain frames > > in stacks originating from a fault that happens in the middle of a > > function. I am not sure if this case is important to handle though. > > I think SCS should just work - and if it doesn't, can we fix it? It is > unclear to me what would be a deciding factor to choose between stack > trace collection modes, since it is hard to quantify when and if SCS > doesn't work as intended. So I fear it'd just be an option that's > never used because we don't understand when it's required to be used. Let's just rely on SCS for now and reconsider in case any significant limitations are discovered. > > +#ifdef CONFIG_SHADOW_CALL_STACK > > + > > +#ifdef CONFIG_ARM64_PTR_AUTH > > +#define PAC_TAG_RESET(x) (x | GENMASK(63, CONFIG_ARM64_VA_BITS)) > > This should go into arch/arm64/include/asm/kasan.h, and here it should > then just do > > #ifndef PAC_TAG_RESET > #define ... > > > > +#else > > +#define PAC_TAG_RESET(x) (x) > > +#endif > > But perhaps there's a better, more generic location for this macro? Will move in v2. Thanks!