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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 721A9C78830 for ; Fri, 20 Sep 2024 12:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=x1dvcPtsLZR8K5qMQ5hQ3hsOFi1LD+/Tp2pAsvVsT7U=; b=dCT2UJxNiuy6LRPo8Ui9ejlLEn jmZBf9R2Tmex11uu4niZnO584ErZqVRuH8KJF2WuxrBcARUzjOFM3oqkv21SXmY5cna5sZ8hhWi/I Bx9o+aIt/rPiQagq/1AE11jMFafleWgFBgHgInEZLbY3RySt2igb6g+nYf6JWYiR5+7UZWIJKU6y3 EFdL8ZXmct87IrREOGvqg59gGS7EKBZOA96r2/B5zcXJdZRnYqVmOWBrlPHy8AXVNX1bMOhGkK44p o71NVJOyExBHTA+BAl+vqX0UIfk4WgZ3NCvdhlJDFgiO3Cm/OcGaZt0Ixa3B/bg00mnzYkjAB8sjX CLsC6hDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srcud-0000000CAoe-1hBF; Fri, 20 Sep 2024 12:39:03 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srctW-0000000CAkI-1BSI for linux-arm-kernel@lists.infradead.org; Fri, 20 Sep 2024 12:37:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 461C85C57AC; Fri, 20 Sep 2024 12:37:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EA7AC4CEC3; Fri, 20 Sep 2024 12:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726835872; bh=+xuRPrmR7i0CxITWrMzA6Rbir0u7SYmmYJphYrBfy3A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IAosnox004cPJJHW+Yce205KY2IrNZcl+CtEsZ66I+gYMKSE+fq8pE685GUG2D+EJ m1zHF9oNmFE5rcXk0uhVHyuVttL0SFDxoMmoHxvysv6F2CHInFj21hnvq8/iTgGvaI Q3F9Bzi0P6PuACKEq3bddrqjg6qomtCcOLXBXoXXTNzVyDGGdVqdOkG3hPCklQBNDX L21vx5LuGCCOeJwSeoogKTVj0e12k8ritzzV/uJzPJe1YtsMAZZCdiYNjwRjHJV5zI vWETvKPasLYzMiOdZPf2d7yNQ5bzAxvXcQ/uVvOECT/6dHsW12+8mHdktGo0VDm/eR yNTmeAkf5u+8w== Date: Fri, 20 Sep 2024 14:34:47 +0200 From: Mike Rapoport To: Fares Mehanna Cc: nh-open-source@amazon.com, Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Andrew Morton , Kemeng Shi , =?iso-8859-1?Q?Pierre-Cl=E9ment?= Tosi , Ard Biesheuvel , Mark Rutland , Javier Martinez Canillas , Arnd Bergmann , Fuad Tabba , Mark Brown , Joey Gouly , Kristina Martsenko , Randy Dunlap , Bjorn Helgaas , Jean-Philippe Brucker , David Hildenbrand , Roman Kagan , "moderated list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , open list , "open list:MEMORY MANAGEMENT" Subject: Re: [RFC PATCH 0/7] support for mm-local memory allocations and use it Message-ID: References: <20240911143421.85612-1-faresx@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240911143421.85612-1-faresx@amazon.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240920_053754_415943_04DECD6A X-CRM114-Status: GOOD ( 27.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On Wed, Sep 11, 2024 at 02:33:59PM +0000, Fares Mehanna wrote: > In a series posted a few years ago [1], a proposal was put forward to allow the > kernel to allocate memory local to a mm and thus push it out of reach for > current and future speculation-based cross-process attacks. We still believe > this is a nice thing to have. > > However, in the time passed since that post Linux mm has grown quite a few new > goodies, so we'd like to explore possibilities to implement this functionality > with less effort and churn leveraging the now available facilities. > > An RFC was posted few months back [2] to show the proof of concept and a simple > test driver. > > In this RFC, we're using the same approach of implementing mm-local allocations > piggy-backing on memfd_secret(), using regular user addresses but pinning the > pages and flipping the user/supervisor flag on the respective PTEs to make them > directly accessible from kernel. > In addition to that we are submitting 5 patches to use the secret memory to hide > the vCPU gp-regs and fp-regs on arm64 VHE systems. > > The generic drawbacks of using user virtual addresses mentioned in the previous > RFC [2] still hold, in addition to a more specific one: > > - While the user virtual addresses allocated for kernel secret memory are not > directly accessible by userspace as the PTEs restrict that, copy_from_user() > and copy_to_user() can operate on those ranges, so that e.g. the usermode can > guess the address and pass it as the target buffer for read(), making the > kernel overwrite it with the user-controlled content. Effectively making the > secret memory in the current implementation missing confidentiality and > integrity guarantees. Having a VMA in user mappings for kernel memory seems weird to say the least. Core MM does not expect to have VMAs for kernel memory. What will happen if userspace ftruncates that VMA? Or registers it with userfaultfd? > In the specific case of vCPU registers, this is fine because the owner process > can read and write to them using KVM IOCTLs anyway. But in the general case this > represents a security concern and needs to be addressed. > > A possible way forward for the arch-agnostic implementation is to limit the user > virtual addresses used for kernel to specific range that can be checked against > in copy_from_user() and copy_to_user(). > > For arch specific implementation, using separate PGD is the way to go. > > [1] https://lore.kernel.org/lkml/20190612170834.14855-1-mhillenb@amazon.de/ This approach seems much more reasonable and it's not that it was entirely arch-specific. There is some plumbing at arch level, but the allocator is anyway arch-independent. -- Sincerely yours, Mike.