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=-5.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 19130C2BA83 for ; Fri, 7 Feb 2020 17:38:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BFFB720838 for ; Fri, 7 Feb 2020 17:38:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="fGmS0yM0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BFFB720838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 664046B0003; Fri, 7 Feb 2020 12:38:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 614EC6B0006; Fri, 7 Feb 2020 12:38:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52A0E6B0007; Fri, 7 Feb 2020 12:38:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id 3AE826B0003 for ; Fri, 7 Feb 2020 12:38:56 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D0E50181AEF0B for ; Fri, 7 Feb 2020 17:38:55 +0000 (UTC) X-FDA: 76464041430.25.wool86_13ac5a75de229 X-HE-Tag: wool86_13ac5a75de229 X-Filterd-Recvd-Size: 7644 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Fri, 7 Feb 2020 17:38:55 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id q8so133895ljj.11 for ; Fri, 07 Feb 2020 09:38:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=i6vlODbgw3D1Fk+qVfHsvrKBbAKyG8Du6ntGjKOG5WE=; b=fGmS0yM0rW43Nhm2NeZIiSUkMxHTet4sgoGz2NmEFf2cNMVDXpS/LXg08rHGRpx0aD GFWda7zIaazKzKZZjDT1VNY0lQBsvOb3JsqN21iKXZYu0W5CRPNuNWpkQ8OgFuljbjV6 NsoGVuF0wFdFlrGtfNnRHueYl2Fr4oxZyWYQykkhAyGCbJjjgxl50I1WaDnDgRQrabQT YkJD5iL8UopB6PuD7IrT99naaHZCJPMxWaj0rNIf0vwbUWkw5+IrOCbg0qzrsltM4dtF bn7DZH1SxtV3pCLBVfQ0q2Pqr2ANYzEtAj6E0/v7gx2aKmXfiJUZ4AHgimMdnBcQEjVF CKxw== 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; bh=i6vlODbgw3D1Fk+qVfHsvrKBbAKyG8Du6ntGjKOG5WE=; b=gQVMAdXDQcyWOO89Q1YE770+TnmubJhsnlo2ydqm5FvB1JKU6mb0gumVkzPL3egelt 1XyS77b7KYvX/j2s6AuiRXov8hUeMMMaewfHiM1nRfyTlpwg3PyyfxAoIYoIWpX/JnBR /X7TAgkmPA88easnaBODE48svRton4qhRlbmPEcO0hALCaOu79dX1zf74xo0OG1sHbCe e3UnNWD2wYkpiOKGKWDlYJfKhSMSyJbLClUwC6Cg7ikv//AKy8EE+UISNE85ozDqei0Z PBi2IPEDle28/16S92vvecDeLaDVmeP183fxng5LW75roAnMPZOXbntgBQdt+IyXx6hD TU+A== X-Gm-Message-State: APjAAAWE56XXzTrZcvy3opDPCfRbzAfjjPRNjylsC+6X+am/6NJPMp+Z p6jXLZCxYgmfe4UOLw3K84qfu328wxM= X-Google-Smtp-Source: APXvYqwHbVAFfSgpkCVBjr3xu3e6C4YsOiOQMCDQZRETQira2/j0azactWI0OcpjKVh2FJ/Ubptvrg== X-Received: by 2002:a05:651c:32b:: with SMTP id b11mr192606ljp.203.1581097133166; Fri, 07 Feb 2020 09:38:53 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id z8sm1610118ljk.13.2020.02.07.09.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 09:38:52 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 0F632100B68; Fri, 7 Feb 2020 20:39:09 +0300 (+03) Date: Fri, 7 Feb 2020 20:39:09 +0300 From: "Kirill A. Shutemov" To: Mike Rapoport Cc: lsf-pc@lists.linux-foundation.org, linux-mm@kvack.org Subject: Re: [LSF/MM/BPF TOPIC] Restricted kernel address spaces Message-ID: <20200207173909.e5gtjys7q4ieh2fv@box> References: <20200206165900.GD17499@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200206165900.GD17499@linux.ibm.com> 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: On Thu, Feb 06, 2020 at 06:59:00PM +0200, Mike Rapoport wrote: > > Restricted mappings in the kernel mode may improve mitigation of hardware > speculation vulnerabilities and minimize the damage exploitable kernel bugs > can cause. > > There are several ongoing efforts to use restricted address spaces in > Linux kernel for various use cases: > * speculation vulnerabilities mitigation in KVM [1] > * support for memory areas visible only in a single owning context, or more > generically, a memory areas with more restrictive protection that the > defaults ("secret" memory) [2], [3], [4] > * hardening of the Linux containers [ no reference yet :) ] > > Last year we had vague ideas and possible directions, this year we have > several real challenges and design decisions we'd like to discuss: > > * "Secret" memory userspace APIs > > Should such API follow "native" MM interfaces like mmap(), mprotect(), > madvise() or it would be better to use a file descriptor , e.g. like > memfd-create does? I don't really see a point in such file-descriptor. It suppose to be very private secret data. What functionality that provide a file descriptor do you see valuable in this scenario? File descriptor makes it easier to spill the secrets to other process: over fork(), UNIX socket or via /proc/PID/fd/. > MM "native" APIs would require VM_something flag and probably a page flag > or page_ext. With file-descriptor VM_SPECIAL and custom implementation of > .mmap() and .fault() would suffice. On the other hand, mmap() and > mprotect() seem better fit semantically and they could be more easily > adopted by the userspace. You mix up implementation and interface. You can provide an interface which doesn't require a file descriptor, but still use a magic file internally to the VMA distinct. > * Direct/linear map fragmentation > > Whenever we want to drop some mappings from the direct map or even change > the protection bits for some memory area, the gigantic and huge pages > that comprise the direct map need to be broken and there's no THP for the > kernel page tables to collapse them back. Moreover, the existing API > defined in by several architectures do not really > presume it would be widely used. > > For the "secret" memory use-case the fragmentation can be minimized by > caching large pages, use them to satisfy smaller "secret" allocations and > than collapse them back once the "secret" memory is freed. Another > possibility is to pre-allocate physical memory at boot time. I would rather go with pre-allocation path. At least at first. We always can come up with more dynamic and complicated solution later if the interface would be wildly adopted. > Yet another idea is to make page allocator aware of the direct map layout. > > * Kernel page table management > > Currently we presume that only one kernel page table exists (well, > mostly) and the page table abstraction is required only for the user page > tables. As such, we presume that 'page table == struct mm_struct' and the > mm_struct is used all over by the operations that manage the page tables. > > The management of the restricted address space in the kernel requires > ability to create, update and remove kernel contexts the same way we do > for the userspace. > > One way is to overload the mm_struct, like EFI and text poking did. But > it is quite an overkill, because most of the mm_struct contains > information required to manage user mappings. In what way is it overkill? Just memory overhead? How many of such contexts do you expect to see in the system? > My suggestion is to introduce a first class abstraction for the page > table and then it could be used in the same way for user and kernel > context management. For now I have a very basic POC that slitted several > fields from the mm_struct into a new 'struct pg_table' [5]. This new > abstraction can be used e.g. by PTI implementation of the page table > cloning and the KVM ASI work. > > > [1] https://lore.kernel.org/lkml/1557758315-12667-1-git-send-email-alexandre.chartre@oracle.com/ > [2] https://lore.kernel.org/lkml/20190612170834.14855-1-mhillenb@amazon.de/ > [3] https://lore.kernel.org/lkml/1572171452-7958-1-git-send-email-rppt@kernel.org/ > [4] https://lore.kernel.org/lkml/20200130162340.GA14232@rapoport-lnx/ > [5] https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=pg_table/v0.0 > > -- > Sincerely yours, > Mike. > > -- Kirill A. Shutemov