Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp554890pxb; Wed, 25 Aug 2021 09:19:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsyMpIR+eqdg0soaIhmLmKG0UF3uHZDdFcsLLBKLyU2mlvCejeYO757qqzTYixYtnkgXgC X-Received: by 2002:a17:906:318b:: with SMTP id 11mr46725111ejy.493.1629908384411; Wed, 25 Aug 2021 09:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629908384; cv=none; d=google.com; s=arc-20160816; b=nYooGSsMpxeEXAjWPmE/1Jnki1rJqFu+KVzVWBXzzpa251VOUt8puzLw/gJGne/gME nrfe/nQ69d4rUgWSGpKF8gL2SxZxkYlSip4NwZ/PWOJd6xXChVNiNdbaHSZWsbT03Moj SgAnIaGCfFm2qcTsvbf8P59GBIUJEeGsHN48g6I/4DPdMiiuYGQQ3U+5tRIf25U1w4LN TRnnVD2d3df8n8aOHwUJC8UdxeXiS29HrTTIkn0hvHOxUjQbPcAopQVvudq12gDGWBnW WiQgsG7OOeXTqB2l/38r8PUf367lWFQZPMZa5QqPdYLq6dOH1ORNtAqH4qs1sjfyXVQp /PGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=j7N1z6xBjv/bx/mcccTmiKuoQlJaxvENQ4HQCnJTN1w=; b=GvbnK2BjwVL5EruJP880Nac1HmD6Dh4b1E75CKCCNLxfpAuxkAlN+qKzOvbWOB2kIZ 4R+st+CQYJc9/dsBm6RKZI5Tt2uIOU/OvFpXM5y4gRIRas0KhoLbVsat5RRBwHCyWTYE +sHgJ7zen0gIbjzfRw6w+5whm7pMvbaZrkWDwrGPeFLcUTc1fSaH/Ju0OsGGIxrkEwy0 YeQnh9z1+LWIuGIpZCuxalsrAK3d6YcwDPzIg8mfjxSRYyboK2wFb5iyqqWSS3e6HUmW YEUr0lcKxG/SXvxGiOrOAL6+aGNojXMdwUjTZvuVF5g/8SWSztXhGgnlN/wC3kzFHSkA 8UXQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si236564ejx.469.2021.08.25.09.19.19; Wed, 25 Aug 2021 09:19:44 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240730AbhHYQSZ (ORCPT + 99 others); Wed, 25 Aug 2021 12:18:25 -0400 Received: from foss.arm.com ([217.140.110.172]:54692 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240593AbhHYQSK (ORCPT ); Wed, 25 Aug 2021 12:18:10 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0CEC8D6E; Wed, 25 Aug 2021 09:17:25 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B362E3F66F; Wed, 25 Aug 2021 09:17:23 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 08/39] KVM: arm64: Deny changes to locked memslots Date: Wed, 25 Aug 2021 17:17:44 +0100 Message-Id: <20210825161815.266051-9-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210825161815.266051-1-alexandru.elisei@arm.com> References: <20210825161815.266051-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Forbid userspace from making changes to a locked memslot. If userspace wants to modify a locked memslot, then they will need to unlock it. One special case is allowed: memslots locked for read, but not for write, can have dirty page logging turned on. Signed-off-by: Alexandru Elisei --- arch/arm64/kvm/mmu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 27b7befd4fa9..3ab8eba808ae 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1842,8 +1842,23 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, { hva_t hva = mem->userspace_addr; hva_t reg_end = hva + mem->memory_size; + struct kvm_memory_slot *old; int ret = 0; + /* + * Forbid all changes to locked memslots with the exception of turning + * on dirty page logging for memslots locked only for reads. + */ + old = id_to_memslot(kvm_memslots(kvm), memslot->id); + if (old && memslot_is_locked(old)) { + if (change == KVM_MR_FLAGS_ONLY && + memslot_is_logging(memslot) && + !(old->arch.flags & KVM_MEMSLOT_LOCK_WRITE)) + memcpy(&memslot->arch, &old->arch, sizeof(old->arch)); + else + return -EBUSY; + } + if (change != KVM_MR_CREATE && change != KVM_MR_MOVE && change != KVM_MR_FLAGS_ONLY) return 0; -- 2.33.0