Received: by 10.213.65.68 with SMTP id h4csp1037677imn; Thu, 22 Mar 2018 13:58:10 -0700 (PDT) X-Google-Smtp-Source: AG47ELu14WuYNFUF+6xwvAAHsczO2HmtYwc81qW1tAv/mxJoUwsKQXhev17otlsISQ3qEENIitBo X-Received: by 2002:a17:902:6184:: with SMTP id u4-v6mr7066747plj.390.1521752290118; Thu, 22 Mar 2018 13:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521752290; cv=none; d=google.com; s=arc-20160816; b=MdtbI73hju3VG2DZzLsO+gMfUoXB0rsTwpquZ/gCIbP4rCH0YwK9Bh63kwYa6dDkY+ EqHoSR1n2dzdNrQiPxqm9p+kRNYBNQCs8FOuO/eT95RDq03a5vhPtoHpB3ZnOJ7hV0ik ckbTK25nUFu0Rnn8khYbT3tWGdemAy3XXzAVYyssPslkjPNjyoxJmrZJUjKeYwcytI6a ZXMlXJvajphiITfWDbb+h8l4G3jQT28LsLcqGz2zHiDbRfDpIbX3Nz3sMyUNANDpAx06 x8tw28Af3wE3NwF06PK1QoPkT0QmIbM/F46WRN1fPcxo6QxqOMqQIcB4rhWrswbX5D3x o1Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to :arc-authentication-results; bh=03GJZPxOwjQAOUQeGhUUuN1qEQPQ7syL1e0DJe8H9N0=; b=mCH8Dzc8XKaCGxGjxJn4uUKflApvVOQM7nf8Kevz+R/kqBpPurVH6wn8EtjHoi1iaE vRvw6atU36+/irc6gopRq+NOZw48HyW3zOvCN4GMkNVSL+a+8rQiNFtzoJj6Rnv0vyNq txynJJHm7gBFuKY9A7LApz8N9Byv8OQIVzUpG+o7B3oOlnFM4H8zyCt6niT0wTf/AObA Jbpfza6WX4w5M/MCu+cTTDyV+8vWhpbAjgm6G9r80EozooJsM+9REezD32JygWnZCP90 HuH3jYa/sihfhuKEcjFsHZ/d0OZanYJe/73i51LOrn7kKHR/HPqdco3SxZp7Qpe1oBk8 F6pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x15si1088691pgx.487.2018.03.22.13.57.55; Thu, 22 Mar 2018 13:58:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751694AbeCVU47 (ORCPT + 99 others); Thu, 22 Mar 2018 16:56:59 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:40113 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbeCVU46 (ORCPT ); Thu, 22 Mar 2018 16:56:58 -0400 Received: by mail-lf0-f68.google.com with SMTP id e5-v6so15238987lfb.7 for ; Thu, 22 Mar 2018 13:56:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=03GJZPxOwjQAOUQeGhUUuN1qEQPQ7syL1e0DJe8H9N0=; b=BmBou95Qe+JqxyPrAyFN+zbTsLqGKXqK7rV75qo/la3oHCsM/hsQnfeYXTybDdpSWH TSOPaadM5/dKEA40fnA641CsjH0UJOn0KlfSz3avJe9NIUfzblnfvrLlEffTQBX8ciRE YDnMkEln0YiZKtiRkh3ri9JidQagVLWyQ54V6A+MuUjCN6x5YmJxHjHz1p0E1MaATcjZ MVpL94eLB38d2AFJdptULbKpCsWSYFXoohk48Ek1xl1NLKx4gQE+KXiE6WBNPDwsS4jX 6SWZQ0LsY/m9AEnkhOQZuy21bQI64nxY61nJ7wPdmoX1/fxP8+a6gOyqN7LvgcLmkWCj s0Og== X-Gm-Message-State: AElRT7FRXJgAy1CSgM0NNaHn0IDrQNthMHTnBT7WH/IDOBEE6LhmNVY9 kdR/lZQgq2QuNkZXilrRgf0= X-Received: by 10.46.126.14 with SMTP id z14mr16911519ljc.103.1521752216647; Thu, 22 Mar 2018 13:56:56 -0700 (PDT) Received: from [192.168.1.147] ([176.15.214.2]) by smtp.gmail.com with ESMTPSA id y128-v6sm1796433lfc.64.2018.03.22.13.56.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 13:56:55 -0700 (PDT) Reply-To: alex.popov@linux.com Subject: Re: [PATCH RFC v9 2/7] x86/entry: Add STACKLEAK erasing the kernel stack at the end of syscalls To: Dave Hansen , Peter Zijlstra , Laura Abbott , Linus Torvalds , Kees Cook , Andy Lutomirski Cc: PaX Team , Brad Spengler , Ingo Molnar , Tycho Andersen , Mark Rutland , Ard Biesheuvel , Borislav Petkov , Richard Sandiford , Thomas Gleixner , "H . Peter Anvin" , "Dmitry V . Levin" , Emese Revfy , Jonathan Corbet , Andrey Ryabinin , "Kirill A . Shutemov" , Thomas Garnier , Andrew Morton , Alexei Starovoitov , Josef Bacik , Masami Hiramatsu , Nicholas Piggin , Al Viro , "David S . Miller" , Ding Tianhong , David Woodhouse , Josh Poimboeuf , Steven Rostedt , Dominik Brodowski , Juergen Gross , Greg Kroah-Hartman , Dan Williams , Mathias Krause , Vikas Shivappa , Kyle Huey , Dmitry Safonov , Will Deacon , Arnd Bergmann , x86@kernel.org, linux-kernel@vger.kernel.org, "kernel-hardening@lists.openwall.com" References: <1520107232-14111-1-git-send-email-alex.popov@linux.com> <1520107232-14111-3-git-send-email-alex.popov@linux.com> <94f268b2-31a4-620a-86ed-325d5bb33c57@redhat.com> <20180305202535.GX25201@hirez.programming.kicks-ass.net> <295a6830-fce9-ee00-f45d-7dafd74d11a1@linux.intel.com> From: Alexander Popov Message-ID: Date: Thu, 22 Mar 2018 23:56:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <295a6830-fce9-ee00-f45d-7dafd74d11a1@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21.03.2018 18:33, Dave Hansen wrote: > On 03/21/2018 04:04 AM, Alexander Popov wrote: >> The main obstacle: >> erase_kstack() must save and restore any modified registers, because it is >> called from the trampoline stack (introduced by Andy Lutomirski), when all >> registers except RDI are live. > > Wow, cool, thanks for doing this! > > PTI might also cause you some problems here because it probably won't > map your function. Did you have to put it in one of the sections that > gets mapped by the user page tables? No, I didn't have to do that: erase_kstack() works fine, it is called just before SWITCH_TO_USER_CR3_STACK. There is also a way not to offend KASAN. erase_kstack() C code can be put in a separate source file and compiled with "KASAN_SANITIZE_erase.o := n". So, as I wrote, the only critical drawback of the C implementation is that it needs no_caller_saved_registers attribute, which is provided by gcc since version 7. Can you recommend any solution? By the way, during my work on STACKLEAK, I've found one case when we get to the userspace directly from the thread stack. Please see sysret32_from_system_call in entry_64_compat.S. I checked that. IMO it seems odd, can the adversary use that to bypass PTI? Best regards, Alexander