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,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 5EEC5CA9EA9 for ; Fri, 18 Oct 2019 17:42:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 358FB222BD for ; Fri, 18 Oct 2019 17:42:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Im9v9Mzy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2634345AbfJRRmf (ORCPT ); Fri, 18 Oct 2019 13:42:35 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:46233 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405272AbfJRRme (ORCPT ); Fri, 18 Oct 2019 13:42:34 -0400 Received: by mail-oi1-f194.google.com with SMTP id k25so5871822oiw.13 for ; Fri, 18 Oct 2019 10:42:34 -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=dgmibiKo/0d1me29Z9Dof5MRYzr1N/NxNY1XetBfk8Q=; b=Im9v9MzyOaL8U2ABodimQMiMTAEx/ALWm+2aNR5YZ26YuKvMczxnA8y18urxRuG5/+ XnQcLW/emDRhYE9NXkabF0vkvtB7/B1OFfA8yc2+J/8ojxg76NYqn5XEF+6dxQ3j2h+N W8t6SnO3PNtg31COYmZhMXfuGKIHm2m38ocLOoiR9IX5P9GsCHQlOalXy865b6wos+FW B0+x6QnnBH3aiaVPuVUZ0KG2tSujXnqZN+BcWBmEFAt50N0+lqqz81wqX9FfykNabdgv GbBqtF/9x13uD9f2ebYbNP8caXnjBcYIO58ADq19axMfogTi2lrhNIWRqNxK+9X+cD04 +xjA== 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=dgmibiKo/0d1me29Z9Dof5MRYzr1N/NxNY1XetBfk8Q=; b=GHpE54ZOqlQWbg9I2YKzB85wPF73vDO4jmSpMoBFADj7lLkFJn4AcbZbhZNHfTwRAv 62dYNTQPhZVW3uO8CnjMUyqrSq/2nhG/cdr0NMMTSObfXueNKobxkzccmDXixxaRvucN NQxcPgVG6pAVYKpKf8IHCGNocnebKdD/0uoMISTiJl/XJFumsTJFTp7Qb7Bad6aGJ58m NegVTgeINb7h4kFaL3Y/8AqiE/oTOyjkzJfAR9Fg0dklKihmvYny7jPWlKH8xm982Rhl j4cZ9N8bpTk0HdMN9GO0O8topFcuM68Hh55WO77ArSTunP56hz9qKIo1GiM2TSItEMZJ yD/A== X-Gm-Message-State: APjAAAUVvhBpftP5SZljJyYxjlyM5CHFa0YLr0rgJTjklR/6OEsLJwaW n2Xw65HjjWRPVp3Vh6A9fFB02+pQVtTpzOjv0irvWA== X-Google-Smtp-Source: APXvYqwal8PqTswvVVivN8N3jgNtD8TTtzaGZToccBg4XVuLF0lDOlAL78wRlCO4ZNDrki8LF+IX3VdRa5kC4ELpgWY= X-Received: by 2002:aca:cd4d:: with SMTP id d74mr9183592oig.157.1571420553320; Fri, 18 Oct 2019 10:42:33 -0700 (PDT) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191018161033.261971-7-samitolvanen@google.com> In-Reply-To: <20191018161033.261971-7-samitolvanen@google.com> From: Jann Horn Date: Fri, 18 Oct 2019 19:42:06 +0200 Message-ID: Subject: Re: [PATCH 06/18] add support for Clang's Shadow Call Stack (SCS) To: Sami Tolvanen Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , Nick Desaulniers , clang-built-linux , Kernel Hardening , linux-arm-kernel@lists.infradead.org, kernel list 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 Fri, Oct 18, 2019 at 6:14 PM Sami Tolvanen wrote: > This change adds generic support for Clang's Shadow Call Stack, which > uses a shadow stack to protect return addresses from being overwritten > by an attacker. Details are available here: > > https://clang.llvm.org/docs/ShadowCallStack.html (As I mentioned in the other thread, the security documentation there doesn't fit the kernel usecase.) [...] > +config SHADOW_CALL_STACK_VMAP > + def_bool n > + depends on SHADOW_CALL_STACK > + help > + Use virtually mapped shadow call stacks. Selecting this option > + provides better stack exhaustion protection, but increases per-thread > + memory consumption as a full page is allocated for each shadow stack. Without CONFIG_SHADOW_CALL_STACK_VMAP, after 128 small stack frames, you overflow into random physmap memory even if the main stack is vmapped... I guess you can't get around that without making the SCS instrumentation more verbose. :/ Could you maybe change things so that independent of whether you have vmapped SCS or slab-allocated SCS, the scs_corrupted() check looks at offset 1024-8 (where it currently is for the slab-allocated case)? That way, code won't suddenly stop working when you disable CONFIG_SHADOW_CALL_STACK_VMAP; and especially if you use CONFIG_SHADOW_CALL_STACK_VMAP for development and testing but disable it in production, that would be annoying. 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,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 1D3B3CA9EA9 for ; Fri, 18 Oct 2019 17:42:43 +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 E7E91222BD for ; Fri, 18 Oct 2019 17:42:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NGqgQ5cm"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Im9v9Mzy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7E91222BD 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=nopyneM2JPUkA2AmhuBPN7h3sl+cwVSDKD0UV32pO8w=; b=NGqgQ5cm5X1MDb eJElAvu68g1kDBwwjxqMYk+eiINwFlVPZbH/v4w/Y1y/ORnaR0KmCjjl/7zGknOWSQlHWp3MsgQrH yVCbpp04DiXgRHXdp6S8TU6/vB/FYvMturfxc2pwh01IMF1B/TFMgzQsOeTSMGbEeQGS4i0JHSG8b vKtT+HHmPaZh2/h8Op9bAL+93u+34mFcymkWopTCqPbcAZu0vPxbk77G5oiQyfJkQzQkZyaVA7jUo D3STDVoq0bwCqgexO3wAFNpMCK+fnbmTDdNenBIPlP/rZdiRYjbMS5gY9+azRAwMoDOSq4yoogNc4 dGc9G+0tcOLszd7F+yGQ==; 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 1iLWGs-0006YP-7E; Fri, 18 Oct 2019 17:42:38 +0000 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iLWGo-0006Xo-IY for linux-arm-kernel@lists.infradead.org; Fri, 18 Oct 2019 17:42:36 +0000 Received: by mail-oi1-x244.google.com with SMTP id t84so5872746oih.10 for ; Fri, 18 Oct 2019 10:42:34 -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=dgmibiKo/0d1me29Z9Dof5MRYzr1N/NxNY1XetBfk8Q=; b=Im9v9MzyOaL8U2ABodimQMiMTAEx/ALWm+2aNR5YZ26YuKvMczxnA8y18urxRuG5/+ XnQcLW/emDRhYE9NXkabF0vkvtB7/B1OFfA8yc2+J/8ojxg76NYqn5XEF+6dxQ3j2h+N W8t6SnO3PNtg31COYmZhMXfuGKIHm2m38ocLOoiR9IX5P9GsCHQlOalXy865b6wos+FW B0+x6QnnBH3aiaVPuVUZ0KG2tSujXnqZN+BcWBmEFAt50N0+lqqz81wqX9FfykNabdgv GbBqtF/9x13uD9f2ebYbNP8caXnjBcYIO58ADq19axMfogTi2lrhNIWRqNxK+9X+cD04 +xjA== 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=dgmibiKo/0d1me29Z9Dof5MRYzr1N/NxNY1XetBfk8Q=; b=jMATUt5knyDSVHgfoPEJICeNLpZ0KP8TFmvZqnEmiop2V8Ad1raFyjpSZykpD6dvcj ZD9KftbWXFbBSoTGJgjd/ZN9On/iOJYlF23L697ccJ/Rfs0nLbShKHbdSKTD+JROM7gZ bit+z+mB190dbm9RPC2ccYuwDMSfurN1r/sg4lQKS1t1W1XiVsCkH3+8rbVIEcmgHgox 1FRHz6TRBpyScsMO3BgFX8ZNPdUlUQMY8AVPeAVQygIi2WKw/hGYD2BFN7zmaZ+J6k4f rubTFR9G6Lm0mErBVVjAyaAltN4TuZ/N7hzyjDbqCO/P7kwts2y1hKei+QvXlxI2jZ5e 4MoA== X-Gm-Message-State: APjAAAVLt50sU5dzI7qBTjNXBTR5ypjCa+OciswTVud06mTcakUCIrED M5dUB7QHVwKY3hG7WR+fMcNwuMG/KBpmgO0Stl6BlA== X-Google-Smtp-Source: APXvYqwal8PqTswvVVivN8N3jgNtD8TTtzaGZToccBg4XVuLF0lDOlAL78wRlCO4ZNDrki8LF+IX3VdRa5kC4ELpgWY= X-Received: by 2002:aca:cd4d:: with SMTP id d74mr9183592oig.157.1571420553320; Fri, 18 Oct 2019 10:42:33 -0700 (PDT) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191018161033.261971-7-samitolvanen@google.com> In-Reply-To: <20191018161033.261971-7-samitolvanen@google.com> From: Jann Horn Date: Fri, 18 Oct 2019 19:42:06 +0200 Message-ID: Subject: Re: [PATCH 06/18] add support for Clang's Shadow Call Stack (SCS) To: Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191018_104234_633301_3BAC83F7 X-CRM114-Status: GOOD ( 12.02 ) 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: Mark Rutland , Kees Cook , Ard Biesheuvel , Catalin Marinas , Kernel Hardening , Nick Desaulniers , kernel list , Steven Rostedt , clang-built-linux , Laura Abbott , Will Deacon , Dave Martin , linux-arm-kernel@lists.infradead.org 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 Fri, Oct 18, 2019 at 6:14 PM Sami Tolvanen wrote: > This change adds generic support for Clang's Shadow Call Stack, which > uses a shadow stack to protect return addresses from being overwritten > by an attacker. Details are available here: > > https://clang.llvm.org/docs/ShadowCallStack.html (As I mentioned in the other thread, the security documentation there doesn't fit the kernel usecase.) [...] > +config SHADOW_CALL_STACK_VMAP > + def_bool n > + depends on SHADOW_CALL_STACK > + help > + Use virtually mapped shadow call stacks. Selecting this option > + provides better stack exhaustion protection, but increases per-thread > + memory consumption as a full page is allocated for each shadow stack. Without CONFIG_SHADOW_CALL_STACK_VMAP, after 128 small stack frames, you overflow into random physmap memory even if the main stack is vmapped... I guess you can't get around that without making the SCS instrumentation more verbose. :/ Could you maybe change things so that independent of whether you have vmapped SCS or slab-allocated SCS, the scs_corrupted() check looks at offset 1024-8 (where it currently is for the slab-allocated case)? That way, code won't suddenly stop working when you disable CONFIG_SHADOW_CALL_STACK_VMAP; and especially if you use CONFIG_SHADOW_CALL_STACK_VMAP for development and testing but disable it in production, that would be annoying. _______________________________________________ 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,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 011EECA9EA9 for ; Fri, 18 Oct 2019 17:42:53 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 4E2B2222C3 for ; Fri, 18 Oct 2019 17:42:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Im9v9Mzy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E2B2222C3 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-17046-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 3437 invoked by uid 550); 18 Oct 2019 17:42:46 -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 3416 invoked from network); 18 Oct 2019 17:42:45 -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=dgmibiKo/0d1me29Z9Dof5MRYzr1N/NxNY1XetBfk8Q=; b=Im9v9MzyOaL8U2ABodimQMiMTAEx/ALWm+2aNR5YZ26YuKvMczxnA8y18urxRuG5/+ XnQcLW/emDRhYE9NXkabF0vkvtB7/B1OFfA8yc2+J/8ojxg76NYqn5XEF+6dxQ3j2h+N W8t6SnO3PNtg31COYmZhMXfuGKIHm2m38ocLOoiR9IX5P9GsCHQlOalXy865b6wos+FW B0+x6QnnBH3aiaVPuVUZ0KG2tSujXnqZN+BcWBmEFAt50N0+lqqz81wqX9FfykNabdgv GbBqtF/9x13uD9f2ebYbNP8caXnjBcYIO58ADq19axMfogTi2lrhNIWRqNxK+9X+cD04 +xjA== 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=dgmibiKo/0d1me29Z9Dof5MRYzr1N/NxNY1XetBfk8Q=; b=f9UBBdRnAhtoRJlFJmiSuM2q8MOP0uT45Z23vxx1AdBNllhDGOQJH2FBr0D9ZKMlBD j8+XRXikSWFhpSQ1zzjacIWgWzQ9VlGB8ezXzXxZL9/ShDjfQfFaQz90uSz5MRhs7uXj OzcjZkN0qZhyB0M2S/DI3Rykc3okV4jVDD02XLiqDaUDGr9mwlncEI+kz6J1/uyLqpUK UDVTjPr0xFzcXUwvqdT30rmy18ZoQsao66EqMVNyU7XyyQGLAGVBunlxuOyku6nlt0l6 isxUESGsZ9taG8EK7sg4NFXIJG8gnpPZI7z6kvio62UwoVLvfTBW3iDo6JGTdS+SN5VL eQbA== X-Gm-Message-State: APjAAAWAfYqoUo2GxC443KPEJRrZxfAOnGmlySHezgiufKlaGGqXiGTQ 4ZtKJhEMOTMSk6KJYx7yuCB4tzX3zcEhL68d3T8Qmg== X-Google-Smtp-Source: APXvYqwal8PqTswvVVivN8N3jgNtD8TTtzaGZToccBg4XVuLF0lDOlAL78wRlCO4ZNDrki8LF+IX3VdRa5kC4ELpgWY= X-Received: by 2002:aca:cd4d:: with SMTP id d74mr9183592oig.157.1571420553320; Fri, 18 Oct 2019 10:42:33 -0700 (PDT) MIME-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191018161033.261971-7-samitolvanen@google.com> In-Reply-To: <20191018161033.261971-7-samitolvanen@google.com> From: Jann Horn Date: Fri, 18 Oct 2019 19:42:06 +0200 Message-ID: Subject: Re: [PATCH 06/18] add support for Clang's Shadow Call Stack (SCS) To: Sami Tolvanen Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , Nick Desaulniers , clang-built-linux , Kernel Hardening , linux-arm-kernel@lists.infradead.org, kernel list Content-Type: text/plain; charset="UTF-8" On Fri, Oct 18, 2019 at 6:14 PM Sami Tolvanen wrote: > This change adds generic support for Clang's Shadow Call Stack, which > uses a shadow stack to protect return addresses from being overwritten > by an attacker. Details are available here: > > https://clang.llvm.org/docs/ShadowCallStack.html (As I mentioned in the other thread, the security documentation there doesn't fit the kernel usecase.) [...] > +config SHADOW_CALL_STACK_VMAP > + def_bool n > + depends on SHADOW_CALL_STACK > + help > + Use virtually mapped shadow call stacks. Selecting this option > + provides better stack exhaustion protection, but increases per-thread > + memory consumption as a full page is allocated for each shadow stack. Without CONFIG_SHADOW_CALL_STACK_VMAP, after 128 small stack frames, you overflow into random physmap memory even if the main stack is vmapped... I guess you can't get around that without making the SCS instrumentation more verbose. :/ Could you maybe change things so that independent of whether you have vmapped SCS or slab-allocated SCS, the scs_corrupted() check looks at offset 1024-8 (where it currently is for the slab-allocated case)? That way, code won't suddenly stop working when you disable CONFIG_SHADOW_CALL_STACK_VMAP; and especially if you use CONFIG_SHADOW_CALL_STACK_VMAP for development and testing but disable it in production, that would be annoying.