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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07B4FCA9EC9 for ; Mon, 4 Nov 2019 21:35:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE5EC214D8 for ; Mon, 4 Nov 2019 21:35:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WQqOCU6q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729740AbfKDVfl (ORCPT ); Mon, 4 Nov 2019 16:35:41 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]:36748 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728778AbfKDVfl (ORCPT ); Mon, 4 Nov 2019 16:35:41 -0500 Received: by mail-vs1-f66.google.com with SMTP id q21so12018739vsg.3 for ; Mon, 04 Nov 2019 13:35:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+iM6UF9mA8yEqKM2m+szbX2ng9KhnEZYRb5X/ojWJG0=; b=WQqOCU6qrDuZG8nuHgiV+CHsG7gWSoR72oOp+M0wKsltRJK+cGqjt2t0ZxI2LM6V8C 1RQXAzRnu6jhZem6MHYFf5TI8O0Eb0LMsQH/RUeNBQLsild5ptqHR2+8pjmiMbj3JxhX gRUGg1RmBpVc1Q1nhoC4mIIl7umwH3N3gETvGBsHefq3zid8veGm9BMAaqqXtchvboU3 oe82rt/ua0dQOwqs4AcW0tswAhd4f8FEmYPR+Wai5JGF1id5ch5hL+dBrDB6AtOUJFPg GiGCKXyOExBSa2rtb1uirhcrkQbT6A5dkDAwpPptAzVGzCMyH1PZXR7LWJ4+2g7vZ1c1 epJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+iM6UF9mA8yEqKM2m+szbX2ng9KhnEZYRb5X/ojWJG0=; b=dAYCsqZ0tu4FU3BfSTWDQbLFfZXeR5wOoRhEmQFs2PN3wLzRkfDi3UZD8KxfihE4+p Gs6vNYss+Q0fsCE2g32WQ+AzARsUQMtwq/R0pa5ozXzY66im4YWaXGlbjNwyckxL19f/ dcarseMaXPaZAJzNA2qHKw1Os2gUDxLSGrcqDvGSNAmh0xHUBhofXgPapXU8/uOkd1xM nd6rSKLWpbZgmNyrppQMCqueYq2hQvjFcyDkcFIKjuyeQxicEVkLgfDfj93Uqq0pbF1M QCr+12ngkPeAZIOlPlM0XfJ+eZ6nJkvtJi6uOBG/pDcOFDEDOoW4ELqj89DbtcxEVQUD h4nw== X-Gm-Message-State: APjAAAX/Sx2/eDnbsACU543ZHyMMPYOa3qJjklVBmkToEOcLrCWPwK56 Xpjgi5geudBEIAly/jIhLxLiv4v4I29GdWESZn3INg== X-Google-Smtp-Source: APXvYqw2qurgJaO5Z50222coqPPYraifWu1WpUrqJjCs3EdmK1uhIyv2tT4xgK/tp1HQy+BY+QUyECFV9cgzh+9tP6o= X-Received: by 2002:a05:6102:36a:: with SMTP id f10mr9282538vsa.44.1572903339925; Mon, 04 Nov 2019 13:35:39 -0800 (PST) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191101221150.116536-1-samitolvanen@google.com> <20191101221150.116536-8-samitolvanen@google.com> <20191104124017.GD45140@lakrids.cambridge.arm.com> In-Reply-To: <20191104124017.GD45140@lakrids.cambridge.arm.com> From: Sami Tolvanen Date: Mon, 4 Nov 2019 13:35:28 -0800 Message-ID: Subject: Re: [PATCH v4 07/17] scs: add support for stack usage debugging To: Mark Rutland Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux , Kernel Hardening , linux-arm-kernel , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 4, 2019 at 4:40 AM Mark Rutland wrote: > > +#ifdef CONFIG_DEBUG_STACK_USAGE > > +static inline unsigned long scs_used(struct task_struct *tsk) > > +{ > > + unsigned long *p = __scs_base(tsk); > > + unsigned long *end = scs_magic(tsk); > > + uintptr_t s = (uintptr_t)p; > > As previously, please use unsigned long for consistency. Ack. > > + while (p < end && *p) > > + p++; > > I think this is the only place where we legtimately access the shadow > call stack directly. There's also scs_corrupted, which checks that the end magic is intact. > When using SCS and KASAN, are the > compiler-generated accesses to the SCS instrumented? > > If not, it might make sense to make this: > > while (p < end && READ_ONCE_NOCKECK(*p)) > > ... and poison the allocation from KASAN's PoV, so that we can find > unintentional accesses more easily. Sure, that makes sense. I can poison the allocation for the non-vmalloc case, I'll just need to refactor scs_set_magic to happen before the poisoning. Sami 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 X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF4A8CA9ED3 for ; Mon, 4 Nov 2019 21:35:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A3E1E20663 for ; Mon, 4 Nov 2019 21:35:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Eh+Kb289"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="WQqOCU6q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3E1E20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LQtLa4Uqp9O6Y2NxDidkJzli778MlXyRxPIutc2WJqg=; b=Eh+Kb289WNhJ2w ArbYE2I/2TzWajm7fq6LIZs0fQ/049NUnq4T75he8CqbwnkBjX9FsZgYcdr0PnAcyQpjWfXnbj9eA CEj7h067RKHUDpoSyXqulXBuNC153NcoAfBgF/LQ1nHGv3IW9AHkURA8CnYi3nXnTp9HH3IQqN3TN JRzmqZBt9f94olzc5EbTTY5tkU+RIvwn57lC0e5yw4WybTi3BETPwIP2YUdLqZpEaetfsGA4ZDPcN iCl41R9bcoZN5z3x84mn2nZtXeKNF47uIlwIg2Szgljvm+0cV+VoXo1ypsX2haDYIesKveXjjYZn0 gmnaq4dIaV/OPiiB5IRw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRk0m-0007GW-84; Mon, 04 Nov 2019 21:35:44 +0000 Received: from mail-vs1-xe43.google.com ([2607:f8b0:4864:20::e43]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRk0j-0007G4-MP for linux-arm-kernel@lists.infradead.org; Mon, 04 Nov 2019 21:35:42 +0000 Received: by mail-vs1-xe43.google.com with SMTP id m6so5456690vsn.13 for ; Mon, 04 Nov 2019 13:35:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+iM6UF9mA8yEqKM2m+szbX2ng9KhnEZYRb5X/ojWJG0=; b=WQqOCU6qrDuZG8nuHgiV+CHsG7gWSoR72oOp+M0wKsltRJK+cGqjt2t0ZxI2LM6V8C 1RQXAzRnu6jhZem6MHYFf5TI8O0Eb0LMsQH/RUeNBQLsild5ptqHR2+8pjmiMbj3JxhX gRUGg1RmBpVc1Q1nhoC4mIIl7umwH3N3gETvGBsHefq3zid8veGm9BMAaqqXtchvboU3 oe82rt/ua0dQOwqs4AcW0tswAhd4f8FEmYPR+Wai5JGF1id5ch5hL+dBrDB6AtOUJFPg GiGCKXyOExBSa2rtb1uirhcrkQbT6A5dkDAwpPptAzVGzCMyH1PZXR7LWJ4+2g7vZ1c1 epJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+iM6UF9mA8yEqKM2m+szbX2ng9KhnEZYRb5X/ojWJG0=; b=mzXy6AScm4WQdgzgCvmWBNLb4vB3TZ9xywLsOfKGAJ4OuhlT2FfTMQtJkBfETSVgml V5n42ner9TBYulRNeyouXtxYeGvnc6dYM63x1sGvkPP1kyt0QuHRwOq75dE9PZvs6Oo9 3lbimYNpA+uoDfHCo/KdzAPH4BqQ2K6sUwy89UKvoBGc9+AWYLQYIRi9po0vZrA2eGqG acVUHOPKW/pRpcNPcbqEpR2W5IF4Fw1UZ7+8h9ZjXGZhshYK19+itAnSFa1vr5UXgyA4 R7lone3P08fh0hpnnX6PduqnVhJlFxOAzW9MrADykihkK+Z/06sq6Wmy9z8YazRKobay wlpg== X-Gm-Message-State: APjAAAUJXgH9L3ZmEGLveEMcIPdLyIdvB45INEWeYtZ5ZwAgIOaja8wD CfxrbayEiplNBfZwojxn4iUo1y74PCYhYLhQUb2DSg== X-Google-Smtp-Source: APXvYqw2qurgJaO5Z50222coqPPYraifWu1WpUrqJjCs3EdmK1uhIyv2tT4xgK/tp1HQy+BY+QUyECFV9cgzh+9tP6o= X-Received: by 2002:a05:6102:36a:: with SMTP id f10mr9282538vsa.44.1572903339925; Mon, 04 Nov 2019 13:35:39 -0800 (PST) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191101221150.116536-1-samitolvanen@google.com> <20191101221150.116536-8-samitolvanen@google.com> <20191104124017.GD45140@lakrids.cambridge.arm.com> In-Reply-To: <20191104124017.GD45140@lakrids.cambridge.arm.com> From: Sami Tolvanen Date: Mon, 4 Nov 2019 13:35:28 -0800 Message-ID: Subject: Re: [PATCH v4 07/17] scs: add support for stack usage debugging To: Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191104_133541_757677_A23D340E X-CRM114-Status: GOOD ( 13.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kees Cook , Ard Biesheuvel , Masahiro Yamada , Catalin Marinas , Jann Horn , Nick Desaulniers , LKML , Steven Rostedt , Miguel Ojeda , clang-built-linux , Masami Hiramatsu , Marc Zyngier , Kernel Hardening , Laura Abbott , Will Deacon , Dave Martin , linux-arm-kernel Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 4, 2019 at 4:40 AM Mark Rutland wrote: > > +#ifdef CONFIG_DEBUG_STACK_USAGE > > +static inline unsigned long scs_used(struct task_struct *tsk) > > +{ > > + unsigned long *p = __scs_base(tsk); > > + unsigned long *end = scs_magic(tsk); > > + uintptr_t s = (uintptr_t)p; > > As previously, please use unsigned long for consistency. Ack. > > + while (p < end && *p) > > + p++; > > I think this is the only place where we legtimately access the shadow > call stack directly. There's also scs_corrupted, which checks that the end magic is intact. > When using SCS and KASAN, are the > compiler-generated accesses to the SCS instrumented? > > If not, it might make sense to make this: > > while (p < end && READ_ONCE_NOCKECK(*p)) > > ... and poison the allocation from KASAN's PoV, so that we can find > unintentional accesses more easily. Sure, that makes sense. I can poison the allocation for the non-vmalloc case, I'll just need to refactor scs_set_magic to happen before the poisoning. Sami _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76EA6CA9EC9 for ; Mon, 4 Nov 2019 21:36:00 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id BD90B20663 for ; Mon, 4 Nov 2019 21:35:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WQqOCU6q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD90B20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-17275-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 22071 invoked by uid 550); 4 Nov 2019 21:35:53 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Received: (qmail 22048 invoked from network); 4 Nov 2019 21:35:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+iM6UF9mA8yEqKM2m+szbX2ng9KhnEZYRb5X/ojWJG0=; b=WQqOCU6qrDuZG8nuHgiV+CHsG7gWSoR72oOp+M0wKsltRJK+cGqjt2t0ZxI2LM6V8C 1RQXAzRnu6jhZem6MHYFf5TI8O0Eb0LMsQH/RUeNBQLsild5ptqHR2+8pjmiMbj3JxhX gRUGg1RmBpVc1Q1nhoC4mIIl7umwH3N3gETvGBsHefq3zid8veGm9BMAaqqXtchvboU3 oe82rt/ua0dQOwqs4AcW0tswAhd4f8FEmYPR+Wai5JGF1id5ch5hL+dBrDB6AtOUJFPg GiGCKXyOExBSa2rtb1uirhcrkQbT6A5dkDAwpPptAzVGzCMyH1PZXR7LWJ4+2g7vZ1c1 epJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+iM6UF9mA8yEqKM2m+szbX2ng9KhnEZYRb5X/ojWJG0=; b=osWYieTtCJnURKEzSBDABDnD5hJgzGGViPtbXzOhY4L3c+LSmVJDtEJXcVTEQJTkN3 y59VokBqtAZqNwOg4Q4DrO+iHIslKwJUPi/Yal/03GNynspitl0pXBIEctqEzNCW7OTk 8eOikMrTRKTEOxhew8AYHn4TaTuGPFGlC5vIBLDGWrsxa+CyeufXwlEpO8lFXCGSRrv/ uHabir0JP6vNL5O8SHndNNifu2YbSAW1rCf5hKbjzc3fUObGkCs7evjL/4CflhZyP9yE JrK5UsKxLMmKhEhevjoVyTUAoO6ooIoQs5K+A1dTCe0aX3us+lsHqZWGnqG4vdzRtub+ Agog== X-Gm-Message-State: APjAAAWaXoDB2PFN/XfAc2mGXPVVrQdaIT767mBiGwqlmWKvLHQi2QU5 QQewu/0y6lTJAD3WzTqMC6Ue0bIlojLfg/2lMiHkAg== X-Google-Smtp-Source: APXvYqw2qurgJaO5Z50222coqPPYraifWu1WpUrqJjCs3EdmK1uhIyv2tT4xgK/tp1HQy+BY+QUyECFV9cgzh+9tP6o= X-Received: by 2002:a05:6102:36a:: with SMTP id f10mr9282538vsa.44.1572903339925; Mon, 04 Nov 2019 13:35:39 -0800 (PST) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191101221150.116536-1-samitolvanen@google.com> <20191101221150.116536-8-samitolvanen@google.com> <20191104124017.GD45140@lakrids.cambridge.arm.com> In-Reply-To: <20191104124017.GD45140@lakrids.cambridge.arm.com> From: Sami Tolvanen Date: Mon, 4 Nov 2019 13:35:28 -0800 Message-ID: Subject: Re: [PATCH v4 07/17] scs: add support for stack usage debugging To: Mark Rutland Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux , Kernel Hardening , linux-arm-kernel , LKML Content-Type: text/plain; charset="UTF-8" On Mon, Nov 4, 2019 at 4:40 AM Mark Rutland wrote: > > +#ifdef CONFIG_DEBUG_STACK_USAGE > > +static inline unsigned long scs_used(struct task_struct *tsk) > > +{ > > + unsigned long *p = __scs_base(tsk); > > + unsigned long *end = scs_magic(tsk); > > + uintptr_t s = (uintptr_t)p; > > As previously, please use unsigned long for consistency. Ack. > > + while (p < end && *p) > > + p++; > > I think this is the only place where we legtimately access the shadow > call stack directly. There's also scs_corrupted, which checks that the end magic is intact. > When using SCS and KASAN, are the > compiler-generated accesses to the SCS instrumented? > > If not, it might make sense to make this: > > while (p < end && READ_ONCE_NOCKECK(*p)) > > ... and poison the allocation from KASAN's PoV, so that we can find > unintentional accesses more easily. Sure, that makes sense. I can poison the allocation for the non-vmalloc case, I'll just need to refactor scs_set_magic to happen before the poisoning. Sami