From patchwork Fri Dec 7 12:48:03 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: 10718109 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 7D71E1750 for ; Fri, 7 Dec 2018 12:58:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CC822DB3B for ; Fri, 7 Dec 2018 12:58:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 605452DC57; Fri, 7 Dec 2018 12:58:48 +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 8CB912DB3B for ; Fri, 7 Dec 2018 12:58:47 +0000 (UTC) Received: (qmail 15680 invoked by uid 550); 7 Dec 2018 12:56:27 -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 Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 3295 invoked from network); 7 Dec 2018 12:49:46 -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=8WR3nfZ+UXawr7R//GnRUy/7E5Oz6Kr5I5N3ItmtOwA=; b=XgJFjDXXpxuO5DPzmfvD7ouX2XxqdC6F4pcGXKK0R2tvBXJyw+Nw5D38eOQKsUv1yJ w/DIegcnPPPWksE8FPD5ium12Lvwj6kPzCoek9IsWuK7gwEDoMt7dR9zTdkS+T9s9bvq ZLAsnkr91HoIltBgUbHteWWnl1Hh3XhHRQDYlhY+rzJLRRT/L9mYY5J5R4Iy5LXlvi9j z7ch89Mf2xau8p8XP7PJzWvQ6/wUrjKuz3VZPvW+Zo28sQNrFswQiwGz4XzlxcPy2dlz oSY3/koIjjyHIri9oT4KDnieBCua/yB8JxnS69UUKcxzElquzW2ljPTlPoFBqAKpXBJu 7aYA== 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=8WR3nfZ+UXawr7R//GnRUy/7E5Oz6Kr5I5N3ItmtOwA=; b=epp1o4WKltKXUbxv/5Ub+ABlX+WEJktPNPRIr2yYq5z5L0Jo4ReMh7fXbFjQzC4CSL hK/K9OATpZ3gDzJncWxwBR5yISQGC2/JTe5m1+PpUPcQ8lNuQeKWBidEAHRFaXIWIqqm x/BSRAaJDVYpgLvyWAT6nhYgl34BVXFaAkUzm+cCqkzfXwc/0MWuuMstDXFsBHj7W45P WJlGOf/vjGUh4w+uuhQeKdgRKxx/cSMD4EFdhwKQo3Q4HgGk5x5yM031o4XhvsPMoCMr ROYv5YTEb+bPr6CbQsvU1uYKLGKx4B6pxAvUj+48KIV/53LOVcgFxOSbuOP4T/jNLtSH F+pA== X-Gm-Message-State: AA+aEWa3ZiCOl39TyRzEt5+Y67KD/BQTqsnUmbNiQ694m+hRVu6ufLHR 7zWaDURX5fIK+529eAzB1jqiZA== X-Google-Smtp-Source: AFSGD/Uvbb9zxQ6Le59/z2g9FbUPsfQ3vtkpDzJJRcigKi93yPTIA3dAjUHEfENdbeVJt5hQt2tGqA== X-Received: by 2002:adf:e707:: with SMTP id c7mr1616063wrm.196.1544186975504; Fri, 07 Dec 2018 04:49:35 -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: [PATCH 10/10] KVM: Log ROE violations in system log Date: Fri, 7 Dec 2018 14:48:03 +0200 Message-Id: <20181207124803.10828-11-ahmedsoliman@mena.vt.edu> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181207124803.10828-1-ahmedsoliman@mena.vt.edu> References: <20181207124803.10828-1-ahmedsoliman@mena.vt.edu> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Ahmed Abd El Mawgood --- virt/kvm/kvm_main.c | 5 +++++ virt/kvm/roe.c | 14 ++++++++++++++ virt/kvm/roe_generic.h | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c3a21d3bc8..661933053f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1870,6 +1870,7 @@ 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) { @@ -1877,6 +1878,10 @@ static int __kvm_write_guest_page(struct kvm_memory_slot *memslot, gfn_t gfn, unsigned long addr; addr = roe_gfn_to_hva(memslot, gfn, offset, len); + if (gfn_is_full_roe(memslot, gfn) || + kvm_roe_check_range(memslot, gfn, offset, len)) + kvm_warning_roe_violation((gfn << PAGE_SHIFT) + offset, data, + 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..36b85fb303 100644 --- a/virt/kvm/roe.c +++ b/virt/kvm/roe.c @@ -76,6 +76,20 @@ void kvm_roe_free(struct kvm_memory_slot *slot) kvfree(slot->prot_list); } +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); +} + 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..8c191362cd 100644 --- a/virt/kvm/roe_generic.h +++ b/virt/kvm/roe_generic.h @@ -14,5 +14,5 @@ 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_warning_roe_violation(u64 addr, const void *data, int len); #endif