Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3356324rdh; Mon, 27 Nov 2023 12:04:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+kRG9/AkwkdEmU/iYdmDGDL3GdFtAj0vnik1D1HVftKLRyVMUza+wfVaMocNyqs7ISB7K X-Received: by 2002:a05:6a00:f8a:b0:690:d620:7801 with SMTP id ct10-20020a056a000f8a00b00690d6207801mr12244078pfb.11.1701115495411; Mon, 27 Nov 2023 12:04:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701115495; cv=none; d=google.com; s=arc-20160816; b=beAuX5W3jUfIDwaXkSQckjeN1Cx06UrWYqrbjfuTHao/R40T9kRZdj+vXsfOkzqLZO 09HvS/xAOtZiGAfNskS7nnZYoaesX8XAjofF2wTU8mskhqrIrdosoIspUQfNlxJu2xX0 d9PRU3z8mb+ojSg3Qx49Wht6rX2c1e2nYTMD8W0NZrpWX72FPNkYahyXHTL8uTDCY5HK GywN3AEtDzV/QlBYn3irTq9iayqjC6jtQmydyyeqffamJ4FI3qqAIIvqofKRq4X/GPt7 X0y0g5bIIBJcOm7U8b2kAXEsF6LWJwTKUPGeogth5Tn/AosCYjKPIBLJe/nGT8Blq1PZ HXmw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HKdTKht77swWp6IqbMhOYILRR0g0Evek+a+XDBEGFI4=; fh=3kfo7Wu3hVD31NLakUKcX3QFJbnxT7NDSOGAOu/oyBo=; b=Pgz4AhB/QujVHvf8DHIgRt0p+qab/o3f0KeV/8lN02RVhOxHmrQGjTC9w964Knq3VH P/KWkkL7R/I5Fna3ommci+LTjEl9nZTDEVZudzz4pT9y6KNh8Y94gg9I36U2MD5K7BEw vm1HNYWNC/9oyys4b2gcrnBX7pZ+FrRKjEXLcl/jN78dZtUROL1eWNgCLDecyNE2X2cL raH4OM8vY+2enp/thKyqZ7H/6VZPjUdWFDGEYbUsmyhALP1gYP9aCExFZyCDdLrXlYvW 0QjHXOcD8tdYg9Sgrzk6jFNlrDsFqDJKXTh7yVCryP6WHV30A6PxvdQXGiRb3h2GQ+77 oXiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VlhbNNJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x16-20020a62fb10000000b006cc01aa0480si6251212pfm.370.2023.11.27.12.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 12:04:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VlhbNNJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 9166C80DA8D9; Mon, 27 Nov 2023 12:04:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232986AbjK0UEc (ORCPT + 99 others); Mon, 27 Nov 2023 15:04:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjK0UEa (ORCPT ); Mon, 27 Nov 2023 15:04:30 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43520C2; Mon, 27 Nov 2023 12:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=HKdTKht77swWp6IqbMhOYILRR0g0Evek+a+XDBEGFI4=; b=VlhbNNJtOQjRl9xNXhif3pyBI3 Yp697PDT+1EY5w8uqPMVRgSViNRDlwsEBioaXw3hqY3eTB8lhCbqt0zd3cnGZiqHwqP840guPwjV2 oriE6LXZ82ilVLw6slHwTwphcRMD/0Nd1NsiEuOe9r4lBzOcT6SSF2nX3osd+EUhPcnLH6Ranfo9H Bv1hzhp/gFFn6ry0jRZXH/H0Gc8LitSNJ60ue7C967EBwiz7XA/OdUI9oaNSFUlcKQNcT7WMTubkf R85oEhWPha2wXYJ4yiCw7hSoq1yPIGJKgfABhWmW6p9IKG8obBpzJRziZFbyBKuL64aiz/cSiRsQN YX0jqE5A==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1r7hp0-00BhJQ-Ds; Mon, 27 Nov 2023 20:03:10 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id B60BD3002F1; Mon, 27 Nov 2023 21:03:08 +0100 (CET) Date: Mon, 27 Nov 2023 21:03:08 +0100 From: Peter Zijlstra To: "Madhavan T. Venkataraman" Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , Kees Cook , Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Alexander Graf , Chao Peng , "Edgecombe, Rick P" , Forrest Yuan Yu , James Gowans , James Morris , John Andersen , Marian Rotariu , Mihai =?utf-8?B?RG9uyJt1?= , =?utf-8?B?TmljdciZb3IgQ8OuyJt1?= , Thara Gopinath , Trilok Soni , Wei Liu , Will Deacon , Yu Zhang , Zahra Tarkhani , =?utf-8?Q?=C8=98tefan_=C8=98icleru?= , dev@lists.cloudhypervisor.org, kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, x86@kernel.org, xen-devel@lists.xenproject.org Subject: Re: [RFC PATCH v2 18/19] heki: x86: Protect guest kernel memory using the KVM hypervisor Message-ID: <20231127200308.GY3818@noisy.programming.kicks-ass.net> References: <20231113022326.24388-1-mic@digikod.net> <20231113022326.24388-19-mic@digikod.net> <20231113085403.GC16138@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 12:04:46 -0800 (PST) On Mon, Nov 27, 2023 at 11:05:23AM -0600, Madhavan T. Venkataraman wrote: > Apologies for the late reply. I was on vacation. Please see my response below: > > On 11/13/23 02:54, Peter Zijlstra wrote: > > On Sun, Nov 12, 2023 at 09:23:25PM -0500, Micka?l Sala?n wrote: > >> From: Madhavan T. Venkataraman > >> > >> Implement a hypervisor function, kvm_protect_memory() that calls the > >> KVM_HC_PROTECT_MEMORY hypercall to request the KVM hypervisor to > >> set specified permissions on a list of guest pages. > >> > >> Using the protect_memory() function, set proper EPT permissions for all > >> guest pages. > >> > >> Use the MEM_ATTR_IMMUTABLE property to protect the kernel static > >> sections and the boot-time read-only sections. This enables to make sure > >> a compromised guest will not be able to change its main physical memory > >> page permissions. However, this also disable any feature that may change > >> the kernel's text section (e.g., ftrace, Kprobes), but they can still be > >> used on kernel modules. > >> > >> Module loading/unloading, and eBPF JIT is allowed without restrictions > >> for now, but we'll need a way to authenticate these code changes to > >> really improve the guests' security. We plan to use module signatures, > >> but there is no solution yet to authenticate eBPF programs. > >> > >> Being able to use ftrace and Kprobes in a secure way is a challenge not > >> solved yet. We're looking for ideas to make this work. > >> > >> Likewise, the JUMP_LABEL feature cannot work because the kernel's text > >> section is read-only. > > > > What is the actual problem? As is the kernel text map is already RO and > > never changed. > > For the JUMP_LABEL optimization, the text needs to be patched at some point. > That patching requires a writable mapping of the text page at the time of > patching. > > In this Heki feature, we currently lock down the kernel text at the end of > kernel boot just before kicking off the init process. The lockdown is > implemented by setting the permissions of a text page to R_X in the extended > page table and not allowing write permissions in the EPT after that. So, jump label > patching during kernel boot is not a problem. But doing it after kernel > boot is a problem. But you see, that's exactly what the kernel already does with the normal permissions. They get set to RX after init and are never changed. See the previous patch, we establish a read-write alias and write there. You seem to lack basic understanding of how the kernel works in this regard, which makes me very nervous about you touching any of this. I must also say I really dislike your extra/random permssion calls all over the place. They don't really get us anything afaict. Why can't you plumb into the existing set_memory_*() family?