Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp1603067lkv; Thu, 6 May 2021 09:47:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaetaj5kIAehP/K6+pXp/uo9pUJTM5cCk86dEVB3U8v5lFn+adLKvswGH5aFYr5ncrEA1+ X-Received: by 2002:a17:90a:9f02:: with SMTP id n2mr18727911pjp.190.1620319674610; Thu, 06 May 2021 09:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620319674; cv=none; d=google.com; s=arc-20160816; b=hv9bNKqxwXjBeIKDHkMIcjfZriL02VWh4VK5TQUZIegGm7q74O7IJmWfYxKq/mnguB sYQK9EjFQmFLnc163g0jummGylRBD+Gi1T8+5Nl6kP/une49tHXB5vDHRuOsELKBKcKh r6y8AKvMPFxr6PGwZWkK0uZ3q0wAl19l8na+9OYIehkkuJJajMcyuJVDiCq84PlE+g/e uoPacZRw9biYZgISKUDFACqH+x86oy9112Szk+5EX++OlZOGo9xJaM738RBH5VKgwcZ3 lJ2uVV8An15s3okGtTjG/jqpLF/t3zRiC7GOx6t3b/K8gy+glBczNDKm/TztIsmu+m5K E61w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject :organization:from:references:cc:to:dkim-signature; bh=0s/7VDcOT9Z56vBvGNlao04OZufq+cCm9HLSATOe2hs=; b=W3uK70n1LTlPWUYpf0UsXi0z4dV8SZOwUBPeFwGoAw+gYLCciHA7ZnRPevGutiLNGW X6Ixp8Fm/PBh6l4hZSjA3x950stPhszNi4v1phvRBejoDgWJKvq89MiwQpR6jRHFY7K0 WELvb/EAUN6W+Zw5bv6LQ+riDp8KfaFd1z08lCZCbw8V9VclgXsojkGJ3L2p/Uvs/pMd NGU0/bRNJe26Ag/r0YJ0SkC53TxydG1Z1OLeKJ7p8zuJRdrW6M2T3W6fvz3J8J/JX7Hb 2oWOyxI7rtqxU0V1BC62Mn826VwIo0NV4KedSsL6agB2LT1ncowEtkNK7vrO1qp//tVU RjGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YKgqzUJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si3909503pfa.306.2021.05.06.09.47.40; Thu, 06 May 2021 09:47:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YKgqzUJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235891AbhEFQqL (ORCPT + 99 others); Thu, 6 May 2021 12:46:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40182 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235933AbhEFQqK (ORCPT ); Thu, 6 May 2021 12:46:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620319511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0s/7VDcOT9Z56vBvGNlao04OZufq+cCm9HLSATOe2hs=; b=YKgqzUJ4GOTx6bmW4NSxv6DPiIY3WWTz3FO8rQ9MCvHhPyTMuh9yxAK3jWqjYG+oTtyTrK FmZ1McC87KPhPOaBsNJfacaqvRUgVuc4LR9lkAyuKIEyxOvZq1T4/SzaK6ibEd7/xIjK4X /bZeAWZxWEv9GLcVfWb2W6jkgzXXN4k= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-f8cQdCYTOp-rerV8u3SOuA-1; Thu, 06 May 2021 12:45:10 -0400 X-MC-Unique: f8cQdCYTOp-rerV8u3SOuA-1 Received: by mail-ej1-f70.google.com with SMTP id 16-20020a1709063010b029037417ca2d43so1945508ejz.5 for ; Thu, 06 May 2021 09:45:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=0s/7VDcOT9Z56vBvGNlao04OZufq+cCm9HLSATOe2hs=; b=CS44VYveaTbN98HNJbeijXzSxokfdjulO5Gusa1inkGpld7CqxOrjdn5Gyh6ChzndV MkA29dMIS+3wpqqprgJTpXDjzL4etVMowxDuvhOxBf7GTlYO6Qjz0BbWl/Kq5SxslM3b ZLYKX91Bi8KMs9OEN6YeNqbiXASbdV1YGvv0ThZPA/sfhkqA1fWNRREVm7fGtxC+ZiQw PF9c4BtMS7MyIoQJlzlls5ObRyi2Te8K5IVvFXsksIaxoLY/Onu2OBEQroYuW0UJl9rd iERp1ecAIPOIUeU9F2AGJX6kL+X/jTXcf1OAafObZ3wqvy0R4AkuQ8hllCtfdlI85f4E SFdg== X-Gm-Message-State: AOAM530HwZeM292saTivQChNj19wTll5XR8JlMegp49Mc33Xxb2KR3vP kOsSMlUv7fitpuUxlShxfyN0XJKRufI6pxpFijjUT6bC8eh6rT9tJQye5O4iwGyWohVD2Z+gNhs az4w6D4wVLQDaem+d4Hbb1sDU X-Received: by 2002:a17:907:1c98:: with SMTP id nb24mr5478119ejc.206.1620319508729; Thu, 06 May 2021 09:45:08 -0700 (PDT) X-Received: by 2002:a17:907:1c98:: with SMTP id nb24mr5478083ejc.206.1620319508409; Thu, 06 May 2021 09:45:08 -0700 (PDT) Received: from [192.168.3.132] (p5b0c64ae.dip0.t-ipconnect.de. [91.12.100.174]) by smtp.gmail.com with ESMTPSA id f19sm2095318edu.12.2021.05.06.09.45.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 May 2021 09:45:08 -0700 (PDT) To: jejb@linux.ibm.com, Andrew Morton , Mike Rapoport Cc: Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , Dan Williams , Dave Hansen , Elena Reshetova , "H. Peter Anvin" , Ingo Molnar , "Kirill A. Shutemov" , Matthew Wilcox , Matthew Garrett , Mark Rutland , Michal Hocko , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , "Rafael J. Wysocki" , Rick Edgecombe , Roman Gushchin , Shakeel Butt , Shuah Khan , Thomas Gleixner , Tycho Andersen , Will Deacon , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-riscv@lists.infradead.org, x86@kernel.org References: <20210303162209.8609-1-rppt@kernel.org> <20210505120806.abfd4ee657ccabf2f221a0eb@linux-foundation.org> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v18 0/9] mm: introduce memfd_secret system call to create "secret" memory areas Message-ID: <996dbc29-e79c-9c31-1e47-cbf20db2937d@redhat.com> Date: Thu, 6 May 2021 18:45:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06.05.21 17:26, James Bottomley wrote: > On Wed, 2021-05-05 at 12:08 -0700, Andrew Morton wrote: >> On Wed, 3 Mar 2021 18:22:00 +0200 Mike Rapoport >> wrote: >> >>> This is an implementation of "secret" mappings backed by a file >>> descriptor. >>> >>> The file descriptor backing secret memory mappings is created using >>> a dedicated memfd_secret system call The desired protection mode >>> for the memory is configured using flags parameter of the system >>> call. The mmap() of the file descriptor created with memfd_secret() >>> will create a "secret" memory mapping. The pages in that mapping >>> will be marked as not present in the direct map and will be present >>> only in the page table of the owning mm. >>> >>> Although normally Linux userspace mappings are protected from other >>> users, such secret mappings are useful for environments where a >>> hostile tenant is trying to trick the kernel into giving them >>> access to other tenants mappings. >> >> I continue to struggle with this and I don't recall seeing much >> enthusiasm from others. Perhaps we're all missing the value point >> and some additional selling is needed. >> >> Am I correct in understanding that the overall direction here is to >> protect keys (and perhaps other things) from kernel bugs? That if >> the kernel was bug-free then there would be no need for this >> feature? If so, that's a bit sad. But realistic I guess. > > Secret memory really serves several purposes. The "increase the level > of difficulty of secret exfiltration" you describe. And, as you say, > if the kernel were bug free this wouldn't be necessary. > > But also: > > 1. Memory safety for use space code. Once the secret memory is > allocated, the user can't accidentally pass it into the kernel to be > transmitted somewhere. That's an interesting point I didn't realize so far. > 2. It also serves as a basis for context protection of virtual > machines, but other groups are working on this aspect, and it is > broadly similar to the secret exfiltration from the kernel problem. > I was wondering if this also helps against CPU microcode issues like spectre and friends. >> >> Is this intended to protect keys/etc after the attacker has gained >> the ability to run arbitrary kernel-mode code? If so, that seems >> optimistic, doesn't it? > > Not exactly: there are many types of kernel attack, but mostly the > attacker either manages to effect a privilege escalation to root or > gets the ability to run a ROP gadget. The object of this code is to be > completely secure against root trying to extract the secret (some what > similar to the lockdown idea), thus defeating privilege escalation and > to provide "sufficient" protection against ROP gadget. What stops "root" from mapping /dev/mem and reading that memory? IOW, would we want to enforce "CONFIG_STRICT_DEVMEM" with CONFIG_SECRETMEM? Also, there is a way to still read that memory when root by 1. Having kdump active (which would often be the case, but maybe not to dump user pages ) 2. Triggering a kernel crash (easy via proc as root) 3. Waiting for the reboot after kump() created the dump and then reading the content from disk. Or, as an attacker, load a custom kexec() kernel and read memory from the new environment. Of course, the latter two are advanced mechanisms, but they are possible when root. We might be able to mitigate, for example, by zeroing out secretmem pages before booting into the kexec kernel, if we care :) -- Thanks, David / dhildenb