Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3239659rdh; Mon, 27 Nov 2023 09:14:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOas4qYfF0XDUKHs+ShcrGUaQJiDWZScuTbHe3tAti8njatP1GHkhpV84xvtCQ2HlTsiGS X-Received: by 2002:a05:6a20:e113:b0:18c:55b4:df2a with SMTP id kr19-20020a056a20e11300b0018c55b4df2amr7725934pzb.2.1701105268955; Mon, 27 Nov 2023 09:14:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701105268; cv=none; d=google.com; s=arc-20160816; b=apTRtxRgp4Q/+qJdLfEWSJsfzowwRHRbsetGKtk+85HXkpHSYL3rrjF07EQK9MApKL ltMrN9e/UCt14rXMv4TloxyUWSJNTfwpt26lQXAZh3KUvYysd2BD+hdmwXrchH+CJ/eI wF5Jl7d0BaxdMe2acKs/UdTfGvhsfSLWsj9oB2bA7jI1jTH0pdZVVtW14BpwwoSbHEn3 XDF6fPv/MefDGQG0Pw0jg8sMKwuemMinMVAYP/AaPmgHS1t2c+4psnFI1C4fFNWpMR9V xIUYi0mfcGla7lzhlhgYAYR7k1lsi4Bswr0sZiReIkvWd7fi3j1fUGpSJ+7VokIg2YWx 8rzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=hQp9k1xmzkhJv53kIi+fGz0Bm7C0uUgSE5lwBZUzRAE=; fh=pLEsqeCK8oWkkRyOPkHTIick7rw319kfknAE23HRGkc=; b=bn7Ku4kDYJLlxcNV7H8HE5QMgkRj9xnWLFtmVkuF71h8vgwIfRrW+TKhICsAZLyAGp nzwb2AvcXuyvmnmMH8n3i+VLIcf+WQ/3TMhCGSnXywvSmuXZZDjz1R9lMjFXTQ9u8OBX XXblx/6JRsGX2aSxCMoCHFLSr9LZdw4hsgrZ/9FbVH75/8orh7B+/8AjsKNKQ++cYM1G Zp2cKrcyJkZmN3AqPPB6YsIZOBJRLAFrsG1scCVaWXku9bLFBM7G1Rlwr1N6FZorfhM7 /pQ1Y7tO9QyVu+bbahe3HRg0+nuPpCFY3P+EKLYuxQICexCbKYt/cnP5bePFw6VHA1m4 ntlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rJ8cBOmh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id be14-20020a656e4e000000b005be095b2545si11226186pgb.183.2023.11.27.09.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 09:14:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rJ8cBOmh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 754C8805A898; Mon, 27 Nov 2023 09:14:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbjK0RNp (ORCPT + 99 others); Mon, 27 Nov 2023 12:13:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343562AbjK0RNV (ORCPT ); Mon, 27 Nov 2023 12:13:21 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 933F52706; Mon, 27 Nov 2023 09:05:26 -0800 (PST) Received: from [192.168.4.26] (unknown [47.186.13.91]) by linux.microsoft.com (Postfix) with ESMTPSA id D60A120B74C0; Mon, 27 Nov 2023 09:05:23 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D60A120B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1701104726; bh=hQp9k1xmzkhJv53kIi+fGz0Bm7C0uUgSE5lwBZUzRAE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=rJ8cBOmhMjU1LJ0/8Jcu8Zs0D7K0IoJJgYpooleweR4JPTx8RVu3i076OKuSc40H8 vQyhttx9sRNbXZhKrbp4uy9amwle/wkhxSgx+XSVVJGrDjkKV6ziAkv22z1oJr2gBV BrN8A1ek3f3VLgDmEE47gJhsasnKPJeYvbYTTmRg= Message-ID: Date: Mon, 27 Nov 2023 11:05:23 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2 18/19] heki: x86: Protect guest kernel memory using the KVM hypervisor Content-Language: en-US To: Peter Zijlstra , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8?= =?UTF-8?Q?n?= Cc: 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 , =?UTF-8?Q?Mihai_Don=C8=9Bu?= , =?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 References: <20231113022326.24388-1-mic@digikod.net> <20231113022326.24388-19-mic@digikod.net> <20231113085403.GC16138@noisy.programming.kicks-ass.net> From: "Madhavan T. Venkataraman" In-Reply-To: <20231113085403.GC16138@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 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,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 27 Nov 2023 09:14:26 -0800 (PST) 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. The lockdown is just for the current Heki implementation. In the future, we plan to have a way of authenticating guest requests to change permissions on a text page. Once that is in place, permissions on text pages can be changed on the fly to support features that depend on text patching - FTrace, KProbes, etc. Madhavan