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=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 F3205C33CAC for ; Thu, 6 Feb 2020 16:59:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A7E9A20838 for ; Thu, 6 Feb 2020 16:59:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7E9A20838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 53CC16B0007; Thu, 6 Feb 2020 11:59:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C5DA6B0008; Thu, 6 Feb 2020 11:59:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38DC66B000A; Thu, 6 Feb 2020 11:59:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 1A9166B0007 for ; Thu, 6 Feb 2020 11:59:09 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C05C882499A8 for ; Thu, 6 Feb 2020 16:59:08 +0000 (UTC) X-FDA: 76460312376.08.key55_32afbddffa954 X-HE-Tag: key55_32afbddffa954 X-Filterd-Recvd-Size: 6590 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 16:59:08 +0000 (UTC) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 016GsCHI109018 for ; Thu, 6 Feb 2020 11:59:06 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2y0necb961-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 06 Feb 2020 11:59:06 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 6 Feb 2020 16:59:05 -0000 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 6 Feb 2020 16:59:03 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 016Gx2Oc15532464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Feb 2020 16:59:02 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFCDFA4053; Thu, 6 Feb 2020 16:59:02 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 67937A4040; Thu, 6 Feb 2020 16:59:02 +0000 (GMT) Received: from linux.ibm.com (unknown [9.148.206.192]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 6 Feb 2020 16:59:02 +0000 (GMT) Date: Thu, 6 Feb 2020 18:59:00 +0200 From: Mike Rapoport To: lsf-pc@lists.linux-foundation.org Cc: linux-mm@kvack.org Subject: [LSF/MM/BPF TOPIC] Restricted kernel address spaces MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-TM-AS-GCONF: 00 x-cbid: 20020616-0012-0000-0000-0000038458D2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20020616-0013-0000-0000-000021C0C78B Message-Id: <20200206165900.GD17499@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-06_01:2020-02-06,2020-02-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=63 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 mlxlogscore=920 mlxscore=0 bulkscore=63 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002060129 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: 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? 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. * 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. 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. 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.