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=-7.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 2F9BFC47E49 for ; Tue, 29 Oct 2019 15:13:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9F4E214B2 for ; Tue, 29 Oct 2019 15:13:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=tycho-ws.20150623.gappssmtp.com header.i=@tycho-ws.20150623.gappssmtp.com header.b="eSOY5l0E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9F4E214B2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.ws Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8694E6B0005; Tue, 29 Oct 2019 11:13:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 819556B0006; Tue, 29 Oct 2019 11:13:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 708306B0007; Tue, 29 Oct 2019 11:13:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0057.hostedemail.com [216.40.44.57]) by kanga.kvack.org (Postfix) with ESMTP id 522926B0005 for ; Tue, 29 Oct 2019 11:13:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id F0265824999B for ; Tue, 29 Oct 2019 15:13:47 +0000 (UTC) X-FDA: 76097166894.13.glass67_40283fddf34f X-HE-Tag: glass67_40283fddf34f X-Filterd-Recvd-Size: 7014 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 15:13:47 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id 1so15172310iou.4 for ; Tue, 29 Oct 2019 08:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=11HABgG4cgofeXKrR7yB4qVxOwjvZW+qOCi2NPimHbk=; b=eSOY5l0EBsO+rrEeDHKewSn+1rtEbKi8WrMI2sePTVXC/Ok+C0a/fr77IQmSqDLll/ CYzbuzmDm2+OHZbCu51GGzTwtcJlmdGqZBoB3k2WEu3E7ZfLHWuUtCNJffCM3vd4kytD h75APcWTq5GfIYQdcBd+ORv7euX6JU53veJR73OudYgqb1zpmyY7HT+CEEa8lHvky3JK fJexNvnmunr/Z6HMFnmRDDOSv28P2Z2y2MpCADz3aefkrY8AfuK+Xs1BHEI32rrYY59w h8W0yxvIVrBz8iW81xL7o3SRufT6ZPfs4ucen2GYWR3JpJayBC5s5tF1Gtm9L0tqOZTk Q9kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=11HABgG4cgofeXKrR7yB4qVxOwjvZW+qOCi2NPimHbk=; b=O8wgzqSlpjz1vckyXMpHCROcqeqLVLXTLpqET1/tZhYhqb5kfC1ofe3a5MpMR8PXu8 Q93SLVhmLtYoAVQQCQN1kWulN9j1Bj/jQZkJfq8lpYlGRXxobokPjRqQ6GY4/oXp7hFs IcaRkAu1eslrQOTpdoT6zKO1NFF8gCvaU+gm9Db/xeT5BoSrCY3dKBlOauAuJodr2TK1 5VtML9O7PrvmkBanoYSraqyIq9ASq45cFq7ZsvoAa4T5N1dhf8pINYXEvPhNTX8J5wMd L8KsyPOSe3otIHd+7yXSr0IGsSLXLj5FXluhCD1qULA8kACq+aycKMIDGA7S33Kt/s7u zfdQ== X-Gm-Message-State: APjAAAUHJ/qwEWz8aVYEKWPloNMCdcKZVqBVvdKl99NS840NK2JnvOD8 8gwvQDh8SH9ZS5XfYZx9RkWqmg== X-Google-Smtp-Source: APXvYqxdgSH2LBsI1BNVKCGE4o19ADjNXKuKcQjC4hWiiauTRCCRnOEThsfn0v5Qac+1sVKsk2hU5Q== X-Received: by 2002:a5d:81c3:: with SMTP id t3mr4392281iol.300.1572362026220; Tue, 29 Oct 2019 08:13:46 -0700 (PDT) Received: from cisco ([2601:282:902:b340:7405:279a:1dff:4689]) by smtp.gmail.com with ESMTPSA id t16sm1473529iol.12.2019.10.29.08.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 08:13:45 -0700 (PDT) Date: Tue, 29 Oct 2019 09:13:43 -0600 From: Tycho Andersen To: "Reshetova, Elena" Cc: Mike Rapoport , "linux-kernel@vger.kernel.org" , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Dave Hansen , James Bottomley , Peter Zijlstra , Steven Rostedt , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "linux-api@vger.kernel.org" , "linux-mm@kvack.org" , "x86@kernel.org" , Mike Rapoport , Alan Cox Subject: Re: [PATCH RFC] mm: add MAP_EXCLUSIVE to create exclusive user mappings Message-ID: <20191029151343.GE32132@cisco> References: <1572171452-7958-1-git-send-email-rppt@kernel.org> <2236FBA76BA1254E88B949DDB74E612BA4EEC0CE@IRSMSX102.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2236FBA76BA1254E88B949DDB74E612BA4EEC0CE@IRSMSX102.ger.corp.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Elena, Mike, On Tue, Oct 29, 2019 at 11:25:12AM +0000, Reshetova, Elena wrote: > > The patch below aims to allow applications to create mappins that have > > pages visible only to the owning process. Such mappings could be used to > > store secrets so that these secrets are not visible neither to other > > processes nor to the kernel. > > Hi Mike, > > I have actually been looking into the closely related problem for the past > couple of weeks (on and off). What is common here is the need for userspace > to indicate to kernel that some pages contain secrets. And then there are > actually a number of things that kernel can do to try to protect these secrets > better. Unmap from direct map is one of them. Another thing is to map such > pages as non-cached, which can help us to prevent or considerably restrict > speculation on such pages. The initial proof of concept for marking pages as > "UNCACHED" that I got from Dave Hansen was actually based on mlock2() > and a new flag for it for this purpose. Since then I have been thinking on what > interface suits the use case better and actually selected going with new madvise() > flag instead because of all possible implications for fragmentation and performance. > My logic was that we better allocate the secret data explicitly (using mmap()) > to make sure that no other process data accidentally gets to suffer. > Imagine I would allocate a buffer to hold a secret key, signal with mlock > to protect it and suddenly my other high throughput non-secret buffer > (which happened to live on the same page by chance) became very slow > and I don't even have an easy way (apart from mmap()ing it!) to guarantee > that it won't be affected. > > So, I ended up towards smth like: > > secret_buffer = mmap(NULL, PAGE_SIZE, ...) > madvise(secret_buffer, size, MADV_SECRET) > > I have work in progress code here: > https://github.com/ereshetova/linux/commits/madvise > > I haven't sent it for review, because it is not ready yet and I am now working > on trying to add the page wiping functionality. Otherwise it would be useless > to protect the page during the time it is used in userspace, but then allow it > to get reused by a different process later after it has been released back and > userspace was stupid enough not to wipe the contents (or was crashed on > purpose before it was able to wipe anything out). I was looking at this and thinking that wiping during do_exit() might be a nice place, but I haven't tried anything yet. > We have also had some discussions with Tycho that XPFO can be also > applied selectively for such "SECRET" marked pages and I know that he has also > did some initial prototyping on this, so I think it would be great to decide > on userspace interface first and then see how we can assemble together all > these features. Yep! Here's my tree with the direct un-mapping bits ported from XPFO: https://github.com/tych0/linux/commits/madvise As noted in one of the commit messages I think the bit math for page prot flags needs a bit of work, but the test passes, so :) In any case, I'll try to look at Mike's patches later today. Cheers, Tycho