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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 6F32AC433DB for ; Wed, 3 Feb 2021 12:09:37 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1FD8564F7E for ; Wed, 3 Feb 2021 12:09:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1FD8564F7E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AC9A3100EAB72; Wed, 3 Feb 2021 04:09:36 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=195.135.220.15; helo=mx2.suse.de; envelope-from=mhocko@suse.com; receiver= Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1E4DD100F2242 for ; Wed, 3 Feb 2021 04:09:33 -0800 (PST) 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 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-Disposition: inline In-Reply-To: Message-ID-Hash: 46LX6YOZUG5VESQ34QOWJGAD7OKMOPEU X-Message-ID-Hash: 46LX6YOZUG5VESQ34QOWJGAD7OKMOPEU X-MailFrom: mhocko@suse.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Mike Rapoport , David Hildenbrand , Andrew Morton , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , 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 Ander sen , 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 X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org 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=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 7E8F2C433E9 for ; Wed, 3 Feb 2021 12:10:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41F0864F9D for ; Wed, 3 Feb 2021 12:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234416AbhBCMK2 (ORCPT ); Wed, 3 Feb 2021 07:10:28 -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 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=-4.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 59349C433DB for ; Wed, 3 Feb 2021 12:09:51 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3FF464F7E for ; Wed, 3 Feb 2021 12:09:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3FF464F7E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DnhPLNCn/AaxBjvC7KizZFZxd5RGG5SRJsC0+TWetgI=; b=oXeZuC/CssPxuW1LjmWvJQZtE uf2453C+NtoYLyaR1S5Q2iDeUIvdaqYMDbowPC+c/a2Ry0kV7ET5AvAJnfCHQ1P/HmZ8d14CySlhE OtIAPcmkr7OU2ygvG/sJlcs1nia1UKcdwUhqwhxfVazVmZX46y3lV2WdR1zw1hSbZgyAXWPmwpsr4 KTOX08cmVnQgJ5YFfQg1rdggPHGBcw5lFoq4fgpEqR/G/v8Hg/1SVH/6csJEbWWrZNPehTj4mP1xP DZSqf5h3NcA5O46KnWNJl+RpXeS3R2ztJSPmrU2wFzkVjMtbXgQW3KoOhImFkNZGpXUlrv/M7ssnZ hATyWvz5A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7GyZ-00082V-FI; Wed, 03 Feb 2021 12:09:39 +0000 Received: from mx2.suse.de ([195.135.220.15]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7GyT-00080X-QP; Wed, 03 Feb 2021 12:09:35 +0000 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 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210203_070934_106204_D7C6BD85 X-CRM114-Status: GOOD ( 33.45 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , David Hildenbrand , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, "H. Peter Anvin" , Christopher Lameter , Shuah Khan , Thomas Gleixner , Elena Reshetova , linux-arch@vger.kernel.org, Tycho Andersen , linux-nvdimm@lists.01.org, Will Deacon , x86@kernel.org, Matthew Wilcox , Mike Rapoport , Ingo Molnar , Michael Kerrisk , Palmer Dabbelt , Arnd Bergmann , Hagen Paul Pfeifer , Borislav Petkov , Alexander Viro , Andy Lutomirski , Paul Walmsley , "Kirill A. Shutemov" , Dan Williams , linux-arm-kernel@lists.infradead.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , linux-fsdevel@vger.kernel.org, Shakeel Butt , Andrew Morton , Rick Edgecombe , Roman Gushchin , Mike Rapoport Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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=-4.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 D715DC433E0 for ; Wed, 3 Feb 2021 12:10:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79C2A64E93 for ; Wed, 3 Feb 2021 12:10:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79C2A64E93 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HZqMb9fFJ1U3jmZFcp9FKmlKvpvS2a0ck8UBIYQD/Z0=; b=1Vw5ceaPWyt9Wdo/2ATRK3WG0 JqtjBSc/lYyLiS0aau3+eGmdmBkxtt1sidZVJvTWWBK6QwiDAUhoDHvBvP/L8GtMymaLfS9QPUt78 Ym+pzY4g0gdyCrjuxqmb07ijksHY/oLsGz+eGSZ8engx5vMS/km3wySZhvfIO4p3sGWGw9ErdD7d0 hKhK4/Cb2Cs+7zrPooQrCU+BnRp+HsxY+kOWp/c0wPrxpwxwEOrX9wR/pUcysh0VSoUZ2079P/ekz Q48RpJmC7S+z+uRQQOrbMBvTmtSsdve3DC4+dw9/qq6xUrwCCMX72hmqyBUD5Wq97VBUdfEdBkrWI 773PcilIg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7GyX-00081z-1c; Wed, 03 Feb 2021 12:09:37 +0000 Received: from mx2.suse.de ([195.135.220.15]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7GyT-00080X-QP; Wed, 03 Feb 2021 12:09:35 +0000 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 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210203_070934_106204_D7C6BD85 X-CRM114-Status: GOOD ( 33.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , David Hildenbrand , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, "H. Peter Anvin" , Christopher Lameter , Shuah Khan , Thomas Gleixner , Elena Reshetova , linux-arch@vger.kernel.org, Tycho Andersen , linux-nvdimm@lists.01.org, Will Deacon , x86@kernel.org, Matthew Wilcox , Mike Rapoport , Ingo Molnar , Michael Kerrisk , Palmer Dabbelt , Arnd Bergmann , Hagen Paul Pfeifer , Borislav Petkov , Alexander Viro , Andy Lutomirski , Paul Walmsley , "Kirill A. Shutemov" , Dan Williams , linux-arm-kernel@lists.infradead.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , linux-fsdevel@vger.kernel.org, Shakeel Butt , Andrew Morton , Rick Edgecombe , Roman Gushchin , Mike Rapoport Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel