Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp227674pxb; Wed, 3 Feb 2021 04:11:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQ141GaFduYIKe/scFOxitRQImPQDTsKjqclJMp/3/JemVNCPMY4UaLIXjaClNzTGww4b1 X-Received: by 2002:a17:906:17c3:: with SMTP id u3mr2823813eje.304.1612354295178; Wed, 03 Feb 2021 04:11:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612354295; cv=none; d=google.com; s=arc-20160816; b=Fz0b+Sp/5GnFcZbdlt/V6NorixD7NgWN4+j82WyNLS2tsGmI9PeTpzwZpSB8QzLEN1 20kBeO6jMCWmLwu+d9CdAnlwG37oCm5Ujcy2AXY4eG3VKUkr7ZSXs6aQ3+QRjMidvUJf /mlIHVNjAKu8dha5IVS4NEV4U2ZIxnKhrXas0Ejd5umPpp2BDZIv6YUOz+7Y/gaai6tO bQQb1bXz1j13VfH+ZcC0c1xcWUZ3G+OkWfYrHXuobFQ5zAtMgBoQQ3J7J7DithKLptEZ reQsjSSedLpz0Q5dzNq4JDEbs+2soqLpGfmQgoaG188UL6jjYlEKDdm32C3KWA3dFCm6 bAQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gKqIUoUlL8R76kxwkZS//+2tVOQRZKxuwAdDoVgDGVc=; b=ilMa/WvlEING5V3N9A7U76FXlSu+CqFcW4bhmVaDYfNMD69GK65pg7zG5dvryuSxE2 GDaMIWjyYBQNdt15Siz0ZXSG/HnnID0nP/E2WaaRRz0pJKL2wK0QPFBI2gODFmkb0Di1 yfSUOuL09+6p3Xl108TPtwGOlpGvZ/iZi05f3WqBPwAp3cb7LvR8ttALl7ja+x8ixt5G ybL6C1/3tKih3mkjawh0LaVOO7lCYa0zraxAyW6wLlS0ZSlFCOPp4k2FjbiAnv8VeVx3 WwB3aMUkkcX28jSndtk4fAn3L744ZWLcZPcOy+uNm2ZkHsFRq6eo/LE79A/FU0gaIOQ3 lefw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=mxvYYdsW; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id js10si1125383ejc.446.2021.02.03.04.11.10; Wed, 03 Feb 2021 04:11:35 -0800 (PST) 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=@suse.com header.s=susede1 header.b=mxvYYdsW; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234454AbhBCMKW (ORCPT + 99 others); Wed, 3 Feb 2021 07:10:22 -0500 Received: from mx2.suse.de ([195.135.220.15]:36988 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234141AbhBCMKT (ORCPT ); Wed, 3 Feb 2021 07:10:19 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612354172; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gKqIUoUlL8R76kxwkZS//+2tVOQRZKxuwAdDoVgDGVc=; b=mxvYYdsWkKnOLbAAY2Xq93W86QtxGZG9WZBc2Cc9sS5vqXt3wUWDhs4DwbnmfVD6tvAGG0 lS5OJmRviEMD44E4iBuZm462q2JlcFLn8YYCSpZ5+zJQC2fMRyJYklkp59wywSxIFouSEb IneXY25y0nuwemPLYik6lohSpv88DtM= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DB6EEAD26; Wed, 3 Feb 2021 12:09:31 +0000 (UTC) Date: Wed, 3 Feb 2021 13:09:30 +0100 From: Michal Hocko To: James Bottomley Cc: Mike Rapoport , David Hildenbrand , Andrew Morton , 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 , Mark Rutland , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , 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, Hagen Paul Pfeifer , Palmer Dabbelt Subject: Re: [PATCH v16 07/11] secretmem: use PMD-size pages to amortize direct map fragmentation Message-ID: References: <20210202124857.GN242749@kernel.org> <6653288a-dd02-f9de-ef6a-e8d567d71d53@redhat.com> <211f0214-1868-a5be-9428-7acfc3b73993@redhat.com> <95625b83-f7e2-b27a-2b99-d231338047fb@redhat.com> <20210202181546.GO242749@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 02-02-21 10:55:40, James Bottomley wrote: > On Tue, 2021-02-02 at 20:15 +0200, Mike Rapoport wrote: > > On Tue, Feb 02, 2021 at 03:34:29PM +0100, David Hildenbrand wrote: > > > On 02.02.21 15:32, Michal Hocko wrote: > > > > On Tue 02-02-21 15:26:20, David Hildenbrand wrote: > > > > > On 02.02.21 15:22, Michal Hocko wrote: > > > > > > On Tue 02-02-21 15:12:21, David Hildenbrand wrote: > > > > > > [...] > > > > > > > I think secretmem behaves much more like longterm GUP right > > > > > > > now > > > > > > > ("unmigratable", "lifetime controlled by user space", > > > > > > > "cannot go on > > > > > > > CMA/ZONE_MOVABLE"). I'd either want to reasonably well > > > > > > > control/limit it or > > > > > > > make it behave more like mlocked pages. > > > > > > > > > > > > I thought I have already asked but I must have forgotten. Is > > > > > > there any > > > > > > actual reason why the memory is not movable? Timing attacks? > > > > > > > > > > I think the reason is simple: no direct map, no copying of > > > > > memory. > > > > > > > > This is an implementation detail though and not something > > > > terribly hard > > > > to add on top later on. I was more worried there would be really > > > > fundamental reason why this is not possible. E.g. security > > > > implications. > > > > > > I don't remember all the details. Let's see what Mike thinks > > > regarding > > > migration (e.g., security concerns). > > > > Thanks for considering me a security expert :-) > > > > Yet, I cannot estimate how dangerous is the temporal exposure of > > this data to the kernel via the direct map in the simple > > map/copy/unmap > > sequence. > > Well the safest security statement is that we never expose the data to > the kernel because it's a very clean security statement and easy to > enforce. It's also the easiest threat model to analyse. Once we do > start exposing the secret to the kernel it alters the threat profile > and the analysis and obviously potentially provides the ROP gadget to > an attacker to do the same. Instinct tells me that the loss of > security doesn't really make up for the ability to swap or migrate but > if there were a case for doing the latter, it would have to be a > security policy of the user (i.e. a user should be able to decide their > data is too sensitive to expose to the kernel). The security/threat model should be documented in the changelog as well. I am not a security expert but I would tend to agree that not allowing even temporal mapping for data copying (in the kernel) is the most robust approach. Whether that is generally necessary for users I do not know. From the API POV I think it makes sense to have two modes. NEVER_MAP_IN_KERNEL which would imply no migrateability, no copy_{from,to}_user, no gup or any other way for the kernel to access content of the memory. Maybe even zero the content on the last unmap to never allow any data leak. ALLOW_TEMPORARY would unmap the page from the direct mapping but it would still allow temporary mappings for data copying inside the kernel (thus allow CoW, copy*user, migration). Which one should be default and which an opt-in I do not know. A less restrictive mode to be default and the more restrictive an opt-in via flags makes a lot of sense to me though. -- Michal Hocko SUSE Labs