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.4 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,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 6167ACA9EA0 for ; Tue, 22 Oct 2019 19:26:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D0642053B for ; Tue, 22 Oct 2019 19:26:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BdV4+MNe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732970AbfJVT0R (ORCPT ); Tue, 22 Oct 2019 15:26:17 -0400 Received: from mail-ua1-f65.google.com ([209.85.222.65]:40370 "EHLO mail-ua1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbfJVT0Q (ORCPT ); Tue, 22 Oct 2019 15:26:16 -0400 Received: by mail-ua1-f65.google.com with SMTP id i13so5265449uaq.7 for ; Tue, 22 Oct 2019 12:26:16 -0700 (PDT) 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=NTGK4hML4ErU1yKOstvLOpiuT4DQy76v/C1+bofd9Cw=; b=BdV4+MNeQ9Io6FliaBVrpzdd/Nr1h8xWmmKPqLZavn/hHAkGLeJ2uet5e2jLmOj9uw 02VQSR42rlo3yyUxFWTBfUTG3kVtJp3J8w5R83ssOsenjeWTSoQZInKliiV+bqAG6hAA Cr0weCMeiEXT18hJy2vPqHUUe6n/7iKNV049vCXj2gJk8nyiep6jgB1jyPz0y6wDHnrH rp0x4DaWxgo9yWNjpZs5w6HMi+jVBQ6IUSdEhuv49ICHNrBPrHc5lLVdYfbNEBO09Rzu SMDk455vF04OVHUuXspa8XLEm5+OmO4KDEHRSmANl4blw+d+0MpTjuEcoQ56sSkWU7a6 4HCQ== 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=NTGK4hML4ErU1yKOstvLOpiuT4DQy76v/C1+bofd9Cw=; b=g0wVIpi2yBwEwzneo+ecGB+DbNCnaIAbgZxStfL4j3GkXT7jrFHhR90GzGiZ4cZW1J zNUmIldsQ/inGgW3jIx35WKy/0JSEYBJ0Zx+0vmzAHtOCufDyPrdo72yRpxcZ7gJB3xC uIv+a/u0JBtjbcedqwLN0LQQXqAvN1pq2UB4T1YvIPIYww9Ci0c6Zwr/KPZrgVhuCyJ7 +atwgfWZSgMhfH9m7xjPHGpTTyZBYN5J58jO+zDKgwlLWtyeDFdzNx2QShX3TGLdmwaP P1NYSBtXH1E9I9JIXVdJ+JrSL58jMi7HGX8Y/a0+45cAQu/Yd8+1Dlb2wwFK0g6/Szr4 2J0w== X-Gm-Message-State: APjAAAU1aycc2PQwwyJ8mt3FR8glbdHw+kGVFOPXxWMNPG+4Hqs52DXD KGNGOMyWRgKMNqEkvcNujdB47D8ZpcDG4+5vyrtgIQ== X-Google-Smtp-Source: APXvYqyhEGmciM5Qsci/BRxLCe2CZGxby7wB0F2s67O2j0nanCSBoYG8VKU/rHobm0lJBKjWBGnRu61RnSLD1gIaItA= X-Received: by 2002:ab0:5981:: with SMTP id g1mr2987226uad.98.1571772374889; Tue, 22 Oct 2019 12:26:14 -0700 (PDT) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191018161033.261971-7-samitolvanen@google.com> <20191022162826.GC699@lakrids.cambridge.arm.com> In-Reply-To: <20191022162826.GC699@lakrids.cambridge.arm.com> From: Sami Tolvanen Date: Tue, 22 Oct 2019 12:26:02 -0700 Message-ID: Subject: Re: [PATCH 06/18] add support for Clang's Shadow Call Stack (SCS) To: Mark Rutland Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Nick Desaulniers , 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 Tue, Oct 22, 2019 at 9:28 AM Mark Rutland wrote: > I think it would be preferable to follow the example of CC_FLAGS_FTRACE > so that this can be filtered out, e.g. > > ifdef CONFIG_SHADOW_CALL_STACK > CFLAGS_SCS := -fsanitize=shadow-call-stack > KBUILD_CFLAGS += $(CFLAGS_SCS) > export CC_FLAGS_SCS > endif Sure, SGTM. > > +choice > > + prompt "Return-oriented programming (ROP) protection" > > + default ROP_PROTECTION_NONE > > + help > > + This option controls kernel protections against return-oriented > > + programming (ROP) attacks. > > Are we expecting more options here in future? Yes, I believe we'd be interested in seeing PAC support too once hardware is more readily available. > I think it would be better to ./make that depend on !SHADOW_CALL_STACK, as > it's plausible that we can add a different ROP protection mechanism that > is compatible with kretprobes. OK, I can change that and remove the choice. We can always add it back when other alternatives are added. > > +config SHADOW_CALL_STACK > > + bool "Clang Shadow Call Stack" > > + depends on ARCH_SUPPORTS_SHADOW_CALL_STACK > > + depends on CC_IS_CLANG && CLANG_VERSION >= 70000 > > Is there a reason for an explicit version check rather than a > CC_HAS_ check? e.g. was this available but broken in prior > versions of clang? No, this feature was added in Clang 7. However, -fsanitize=shadow-call-stack might require architecture-specific flags, so a simple $(cc-option, -fsanitize=shadow-call-stack) in arch/Kconfig is not going to work. I could add something like this to arch/arm64/Kconfig though: select ARCH_SUPPORTS_SHADOW_CALL_STACK if CC_HAVE_SHADOW_CALL_STACK ... config CC_HAVE_SHADOW_CALL_STACK def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18) And then drop CC_IS_CLANG and version check entirely. Thoughts? > > +#define SCS_GFP (GFP_KERNEL | __GFP_ZERO) > > Normally GFP_ is a prefix. For consistency, GFP_SCS would be preferable. Ack. > > +extern unsigned long init_shadow_call_stack[]; > > Do we need this exposed here? IIUC this is only assigned by assembly in > arch code. True, it's not needed. > [...] > > > +void scs_set_init_magic(struct task_struct *tsk) > > +{ > > + scs_save(tsk); > > + scs_set_magic(tsk); > > + scs_load(tsk); > > +} > > Can we initialize this at compile time instead? We can. I'll change this and drop the function. 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.8 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 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 0F11ACA9EA0 for ; Tue, 22 Oct 2019 19:26:24 +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 D241D2053B for ; Tue, 22 Oct 2019 19:26:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="M6BEzxeJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="BdV4+MNe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D241D2053B 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=+MxC7zxxunKWWx3Avj8EF/fimpYSYc3YRiWg1FafZVk=; b=M6BEzxeJMCalgk ZZVk5ojAzBLb8GDX0aJwOayl0jQH+6JcstssvBL3Y8v0vLTmGYaaMALSJCSN99POUr0oX/vKmOXJJ IF8A0Vr67qpcSfaht+XYptKLGFIgnQp62quFKSOCd0Z4wBfrOh4UMO1+bYcvOSG548Hso0fRpP7Zl K/0P4cRi2N1TfVSoAqU62Yr7aNSYdoTJoQxhylcth/9eAI6BFocfuaXYTpD/tWdk0GWurmz4mlI/r tp5VYGRlBPEOot+Y4TWaZI86pftlWIeZARKCmkQ3FWS1cPX4t2z/Z42xV2iTBVZdeRL9brsGo2Deo C3V0eJubFvxnMlrB55bw==; 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 1iMznQ-0000uU-OF; Tue, 22 Oct 2019 19:26:20 +0000 Received: from mail-ua1-x944.google.com ([2607:f8b0:4864:20::944]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iMznM-0000tj-Vo for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2019 19:26:18 +0000 Received: by mail-ua1-x944.google.com with SMTP id k24so5263899uag.10 for ; Tue, 22 Oct 2019 12:26:16 -0700 (PDT) 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=NTGK4hML4ErU1yKOstvLOpiuT4DQy76v/C1+bofd9Cw=; b=BdV4+MNeQ9Io6FliaBVrpzdd/Nr1h8xWmmKPqLZavn/hHAkGLeJ2uet5e2jLmOj9uw 02VQSR42rlo3yyUxFWTBfUTG3kVtJp3J8w5R83ssOsenjeWTSoQZInKliiV+bqAG6hAA Cr0weCMeiEXT18hJy2vPqHUUe6n/7iKNV049vCXj2gJk8nyiep6jgB1jyPz0y6wDHnrH rp0x4DaWxgo9yWNjpZs5w6HMi+jVBQ6IUSdEhuv49ICHNrBPrHc5lLVdYfbNEBO09Rzu SMDk455vF04OVHUuXspa8XLEm5+OmO4KDEHRSmANl4blw+d+0MpTjuEcoQ56sSkWU7a6 4HCQ== 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=NTGK4hML4ErU1yKOstvLOpiuT4DQy76v/C1+bofd9Cw=; b=XDx5kiDM8X9rGjoShwupbeVthkimJRj6pyyt1oqFqCxzwuJ9lm+F9hzt/QNvlm+IC/ r6BaBNj+LyE/C/u1jbDQBV9ttDw9c3PS6Y8kADzeZSUoNbmYDzrNOaOOK3lruKzR2lBY 4v+39PwrFhMJVv+vH9Hud/FTG5c8t6SLXffxKEiEvsC4PZRrPlQM0n2N89QFH25zoNyS J0wkKmLGpv566G0Lg1YW3lBFO+KfqObcBvcmtBqdvYzXDl1/QL2m8TleVhzUjd2hqMKp RhYaCtiG82UAUv9gwZMmdD0hJxAgE7Ps9X1MdI1SLTztC1ma6mAi79Yj0VZTVRNITQow e1rQ== X-Gm-Message-State: APjAAAUG+nAhSAYzoqCAS9NbgY3m0iR9m6NNPc25/6nx+JQ2e5+sheYm gkdLTDyceJg6rS6xXRybHMbK+XZ6fJGRzdxovfcPmA== X-Google-Smtp-Source: APXvYqyhEGmciM5Qsci/BRxLCe2CZGxby7wB0F2s67O2j0nanCSBoYG8VKU/rHobm0lJBKjWBGnRu61RnSLD1gIaItA= X-Received: by 2002:ab0:5981:: with SMTP id g1mr2987226uad.98.1571772374889; Tue, 22 Oct 2019 12:26:14 -0700 (PDT) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191018161033.261971-7-samitolvanen@google.com> <20191022162826.GC699@lakrids.cambridge.arm.com> In-Reply-To: <20191022162826.GC699@lakrids.cambridge.arm.com> From: Sami Tolvanen Date: Tue, 22 Oct 2019 12:26:02 -0700 Message-ID: Subject: Re: [PATCH 06/18] add support for Clang's Shadow Call Stack (SCS) To: Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191022_122617_048138_EDE24F89 X-CRM114-Status: GOOD ( 17.74 ) 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 , Catalin Marinas , Kernel Hardening , Nick Desaulniers , LKML , Steven Rostedt , clang-built-linux , 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 Tue, Oct 22, 2019 at 9:28 AM Mark Rutland wrote: > I think it would be preferable to follow the example of CC_FLAGS_FTRACE > so that this can be filtered out, e.g. > > ifdef CONFIG_SHADOW_CALL_STACK > CFLAGS_SCS := -fsanitize=shadow-call-stack > KBUILD_CFLAGS += $(CFLAGS_SCS) > export CC_FLAGS_SCS > endif Sure, SGTM. > > +choice > > + prompt "Return-oriented programming (ROP) protection" > > + default ROP_PROTECTION_NONE > > + help > > + This option controls kernel protections against return-oriented > > + programming (ROP) attacks. > > Are we expecting more options here in future? Yes, I believe we'd be interested in seeing PAC support too once hardware is more readily available. > I think it would be better to ./make that depend on !SHADOW_CALL_STACK, as > it's plausible that we can add a different ROP protection mechanism that > is compatible with kretprobes. OK, I can change that and remove the choice. We can always add it back when other alternatives are added. > > +config SHADOW_CALL_STACK > > + bool "Clang Shadow Call Stack" > > + depends on ARCH_SUPPORTS_SHADOW_CALL_STACK > > + depends on CC_IS_CLANG && CLANG_VERSION >= 70000 > > Is there a reason for an explicit version check rather than a > CC_HAS_ check? e.g. was this available but broken in prior > versions of clang? No, this feature was added in Clang 7. However, -fsanitize=shadow-call-stack might require architecture-specific flags, so a simple $(cc-option, -fsanitize=shadow-call-stack) in arch/Kconfig is not going to work. I could add something like this to arch/arm64/Kconfig though: select ARCH_SUPPORTS_SHADOW_CALL_STACK if CC_HAVE_SHADOW_CALL_STACK ... config CC_HAVE_SHADOW_CALL_STACK def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18) And then drop CC_IS_CLANG and version check entirely. Thoughts? > > +#define SCS_GFP (GFP_KERNEL | __GFP_ZERO) > > Normally GFP_ is a prefix. For consistency, GFP_SCS would be preferable. Ack. > > +extern unsigned long init_shadow_call_stack[]; > > Do we need this exposed here? IIUC this is only assigned by assembly in > arch code. True, it's not needed. > [...] > > > +void scs_set_init_magic(struct task_struct *tsk) > > +{ > > + scs_save(tsk); > > + scs_set_magic(tsk); > > + scs_load(tsk); > > +} > > Can we initialize this at compile time instead? We can. I'll change this and drop the function. 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.4 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,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 BD22ECA9EA0 for ; Tue, 22 Oct 2019 19:26:35 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 07A16218AE for ; Tue, 22 Oct 2019 19:26:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BdV4+MNe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07A16218AE 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-17093-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 20286 invoked by uid 550); 22 Oct 2019 19:26:28 -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 20268 invoked from network); 22 Oct 2019 19:26:27 -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=NTGK4hML4ErU1yKOstvLOpiuT4DQy76v/C1+bofd9Cw=; b=BdV4+MNeQ9Io6FliaBVrpzdd/Nr1h8xWmmKPqLZavn/hHAkGLeJ2uet5e2jLmOj9uw 02VQSR42rlo3yyUxFWTBfUTG3kVtJp3J8w5R83ssOsenjeWTSoQZInKliiV+bqAG6hAA Cr0weCMeiEXT18hJy2vPqHUUe6n/7iKNV049vCXj2gJk8nyiep6jgB1jyPz0y6wDHnrH rp0x4DaWxgo9yWNjpZs5w6HMi+jVBQ6IUSdEhuv49ICHNrBPrHc5lLVdYfbNEBO09Rzu SMDk455vF04OVHUuXspa8XLEm5+OmO4KDEHRSmANl4blw+d+0MpTjuEcoQ56sSkWU7a6 4HCQ== 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=NTGK4hML4ErU1yKOstvLOpiuT4DQy76v/C1+bofd9Cw=; b=e+zcIJDVB5gKsjJR3zA7EYQoXYrT0Onlu6/9BEkj78CyhayDGIeAD/X/YDHbwQePp4 42TUJkIXDlptewtGAAs22Ez1Oo1g3ZN+Qmx3z2jU41ov5d/7qJ/CTjMLrg/RqtjGmE6c EYDE8UJz3R/Sh7H58eNAWagkn/BU4N/q0Ctg2iFpjPnS1MBpr/oTlB4UjqSzZKGQEcDl YGVkHFtchVkG2BN+jn7KuhOCAMbZCwShk9i4TtbdjGHIuG9A0DumMyyYa2OT/Etup080 raPRhMiqoA3OsfRyikjJzTttpSbpHw/8x+S/T5B8rtJYc5ZHTMK7oq7LGvpaw1EyomX/ RdMA== X-Gm-Message-State: APjAAAXENZ00eSX2YFVk1vN5GHrkC6fu5kGhB5HEVPfBBUezwYBkTD5j lgmLo4AIOfIH6aM3A/NeT8fmRFuDUqYV+PZxXwZX+g== X-Google-Smtp-Source: APXvYqyhEGmciM5Qsci/BRxLCe2CZGxby7wB0F2s67O2j0nanCSBoYG8VKU/rHobm0lJBKjWBGnRu61RnSLD1gIaItA= X-Received: by 2002:ab0:5981:: with SMTP id g1mr2987226uad.98.1571772374889; Tue, 22 Oct 2019 12:26:14 -0700 (PDT) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191018161033.261971-7-samitolvanen@google.com> <20191022162826.GC699@lakrids.cambridge.arm.com> In-Reply-To: <20191022162826.GC699@lakrids.cambridge.arm.com> From: Sami Tolvanen Date: Tue, 22 Oct 2019 12:26:02 -0700 Message-ID: Subject: Re: [PATCH 06/18] add support for Clang's Shadow Call Stack (SCS) To: Mark Rutland Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Nick Desaulniers , clang-built-linux , Kernel Hardening , linux-arm-kernel , LKML Content-Type: text/plain; charset="UTF-8" On Tue, Oct 22, 2019 at 9:28 AM Mark Rutland wrote: > I think it would be preferable to follow the example of CC_FLAGS_FTRACE > so that this can be filtered out, e.g. > > ifdef CONFIG_SHADOW_CALL_STACK > CFLAGS_SCS := -fsanitize=shadow-call-stack > KBUILD_CFLAGS += $(CFLAGS_SCS) > export CC_FLAGS_SCS > endif Sure, SGTM. > > +choice > > + prompt "Return-oriented programming (ROP) protection" > > + default ROP_PROTECTION_NONE > > + help > > + This option controls kernel protections against return-oriented > > + programming (ROP) attacks. > > Are we expecting more options here in future? Yes, I believe we'd be interested in seeing PAC support too once hardware is more readily available. > I think it would be better to ./make that depend on !SHADOW_CALL_STACK, as > it's plausible that we can add a different ROP protection mechanism that > is compatible with kretprobes. OK, I can change that and remove the choice. We can always add it back when other alternatives are added. > > +config SHADOW_CALL_STACK > > + bool "Clang Shadow Call Stack" > > + depends on ARCH_SUPPORTS_SHADOW_CALL_STACK > > + depends on CC_IS_CLANG && CLANG_VERSION >= 70000 > > Is there a reason for an explicit version check rather than a > CC_HAS_ check? e.g. was this available but broken in prior > versions of clang? No, this feature was added in Clang 7. However, -fsanitize=shadow-call-stack might require architecture-specific flags, so a simple $(cc-option, -fsanitize=shadow-call-stack) in arch/Kconfig is not going to work. I could add something like this to arch/arm64/Kconfig though: select ARCH_SUPPORTS_SHADOW_CALL_STACK if CC_HAVE_SHADOW_CALL_STACK ... config CC_HAVE_SHADOW_CALL_STACK def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18) And then drop CC_IS_CLANG and version check entirely. Thoughts? > > +#define SCS_GFP (GFP_KERNEL | __GFP_ZERO) > > Normally GFP_ is a prefix. For consistency, GFP_SCS would be preferable. Ack. > > +extern unsigned long init_shadow_call_stack[]; > > Do we need this exposed here? IIUC this is only assigned by assembly in > arch code. True, it's not needed. > [...] > > > +void scs_set_init_magic(struct task_struct *tsk) > > +{ > > + scs_save(tsk); > > + scs_set_magic(tsk); > > + scs_load(tsk); > > +} > > Can we initialize this at compile time instead? We can. I'll change this and drop the function. Sami