From patchwork Fri Dec 7 16:23:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Abd El Mawgood X-Patchwork-Id: 10718511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2BF91731 for ; Fri, 7 Dec 2018 16:24:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2B5528C2F for ; Fri, 7 Dec 2018 16:24:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D665E2D83A; Fri, 7 Dec 2018 16:24:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 0B9D52DDAB for ; Fri, 7 Dec 2018 16:24:10 +0000 (UTC) Received: (qmail 31836 invoked by uid 550); 7 Dec 2018 16:24:09 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 31817 invoked from network); 7 Dec 2018 16:24:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mena-vt-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0ZLMRK1sa14ZeWEcMpGckEyj8BI4tsg92VSqXi44f2k=; b=z1TUJhC/ICXd7VUEA7Zc9hLkfQ9RfS+KHHrmxIjly7beF6KVxTS+6rzLEs2J2ur9MT coAAwfSGk1MfNZxQItV0Rs4baXK/aFwLaaSEyCCF6J7S15hMOLm+GOhMp+7apzqVxgwM bnJxdcRXzUNcbo9uCcR2I9VowdftyuzVRjmpU5hQCltb5ofH48xrbHUVDK4TDYl9Y0Cy uO3pQ7tR4tqtSSw3Sa+zF+Fg3YrvFFuTOlwhKh3xxlXBvBpF+PJ82xi5rjuKCf5eRrB9 N8aWEjzoqw7tLtcNW0f1yqj2FEHkAYuC7zvnjjvGsnxvpQYEUwaW5ULomgRSbLR8ZoMH /JoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0ZLMRK1sa14ZeWEcMpGckEyj8BI4tsg92VSqXi44f2k=; b=UE0HG0m+R3fa6/Pp7lMbCk05QhFHu2LMWpuVKlOp4Wrk1/bc0P2OXZeP+kJu9+h6Fs BcnPeFCHkJMNXDBO08ZsI+M23REQn1KfOo+0pZtPJADw7Y3PmAkUxYJwo4/nH4awM8i1 scTDJDWi8RlGCxa5OjMpOccqKyGQ2v0sKQoBGjCqtuiEWTQYGHUwJCKTIiDh3ylJsw52 varWq+QYQxTmOHs8T1y4/gO3xFk9kTfitdlNK5HJ48DvIwdwopw1Wu6/Es4FSIvuM5wO pAK900b6oALuoU2lCB/ycnvSpDhs/BCmJD6Cs3a4EVi/2ZR7BCOkAI2ePuI0B0Knx/W1 IfPQ== X-Gm-Message-State: AA+aEWaxm/ileCsV4ooje4u0ndm+EmiEv5egR8LZS99furKqkLsWbKct wH8e6tR64Fka2r3mQpWzx8TcoA== X-Google-Smtp-Source: AFSGD/UkT9Ta/PzidJmaQ+Am56ke5yurCQxQ2pToh570695xGXOPEh8uXHqsdnU0qD0vzyXjJMdsrA== X-Received: by 2002:adf:8228:: with SMTP id 37mr2289815wrb.160.1544199837389; Fri, 07 Dec 2018 08:23:57 -0800 (PST) From: Ahmed Abd El Mawgood To: Paolo Bonzini , rkrcmar@redhat.com, Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, ahmedsoliman0x666@gmail.com, ovich00@gmail.com, kernel-hardening@lists.openwall.com, nigel.edwards@hpe.com, Boris Lukashev , Igor Stoppa Cc: Ahmed Abd El Mawgood Subject: RESEND [PATCH 10/10] KVM: Log ROE violations in system log Date: Fri, 7 Dec 2018 18:23:15 +0200 Message-Id: <20181207162315.6004-1-ahmedsoliman@mena.vt.edu> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181207124803.10828-1-ahmedsoliman@mena.vt.edu> References: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP I am absolutely sorry, I had some modifications that I forgot to commit before I send. so please use this one patch 10/10 instead of the last one. Signed-off-by: Ahmed Abd El Mawgood --- virt/kvm/kvm_main.c | 3 ++- virt/kvm/roe.c | 26 ++++++++++++++++++++++++++ virt/kvm/roe_generic.h | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c3a21d3bc8..761cb7561a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1870,13 +1870,14 @@ static u64 roe_gfn_to_hva(struct kvm_memory_slot *slot, gfn_t gfn, int offset, addr = __gfn_to_hva_many(slot, gfn, NULL, false); return addr; } + static int __kvm_write_guest_page(struct kvm_memory_slot *memslot, gfn_t gfn, const void *data, int offset, int len) { int r; unsigned long addr; - addr = roe_gfn_to_hva(memslot, gfn, offset, len); + kvm_roe_check_and_log(memslot, gfn, data, offset, len); if (kvm_is_error_hva(addr)) return -EFAULT; r = __copy_to_user((void __user *)addr + offset, data, len); diff --git a/virt/kvm/roe.c b/virt/kvm/roe.c index 6555838f0c..01362f0fca 100644 --- a/virt/kvm/roe.c +++ b/virt/kvm/roe.c @@ -76,6 +76,32 @@ void kvm_roe_free(struct kvm_memory_slot *slot) kvfree(slot->prot_list); } +static void kvm_warning_roe_violation(u64 addr, const void *data, int len) +{ + int i; + const char *d = data; + char *buf = kvmalloc(len * 3 + 1, GFP_KERNEL); + + for (i = 0; i < len; i++) + sprintf(buf+3*i, " %02x", d[i]); + pr_warn("ROE violation:\n"); + pr_warn("\tAttempt to write %d bytes at address 0x%08llx\n", len, addr); + pr_warn("\tData: %s\n", buf); + kvfree(buf); +} + +void kvm_roe_check_and_log(struct kvm_memory_slot *memslot, gfn_t gfn, + const void *data, int offset, int len) +{ + if (!memslot) + return; + if (!gfn_is_full_roe(memslot, gfn)) + return; + if (!kvm_roe_check_range(memslot, gfn, offset, len)) + return; + kvm_warning_roe_violation((gfn << PAGE_SHIFT) + offset, data, len); +} + static void kvm_roe_protect_slot(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn, u64 npages, bool partial) { diff --git a/virt/kvm/roe_generic.h b/virt/kvm/roe_generic.h index f1ce4a8aec..6c5f0cf381 100644 --- a/virt/kvm/roe_generic.h +++ b/virt/kvm/roe_generic.h @@ -14,5 +14,6 @@ void kvm_roe_free(struct kvm_memory_slot *slot); int kvm_roe_init(struct kvm_memory_slot *slot); bool kvm_roe_check_range(struct kvm_memory_slot *slot, gfn_t gfn, int offset, int len); - +void kvm_roe_check_and_log(struct kvm_memory_slot *memslot, gfn_t gfn, + const void *data, int offset, int len); #endif