From patchwork Sun Jan 20 23:39:39 2019 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: 10772549 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 93FCD17E9 for ; Sun, 20 Jan 2019 23:43:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F07A29CB1 for ; Sun, 20 Jan 2019 23:43:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C55A29CC0; Sun, 20 Jan 2019 23:43:01 +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 9321529CB1 for ; Sun, 20 Jan 2019 23:43:00 +0000 (UTC) Received: (qmail 32107 invoked by uid 550); 20 Jan 2019 23:41:53 -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 32046 invoked from network); 20 Jan 2019 23:41:52 -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=IhG1ga+e4jMCr/1icaT0qzsbDovza4q20X40VnRy5Mw=; b=vPY8CKyF4BZgHUvB9f+hTiC4cuY5UAnYYG9Lexcqx7DTbCm925fQ9AMbHHWoxa/BPW OpAktjU2Y9R7ncJshPKtn6/mWocevKPSQqT2VND91cqmRabjphUqCDeF0eKTHRrgo54E ia1NVcOtQxFjM907lZSXRSHtSy86MjLjmZueYrWCOsXvynd8UnmC4LeCytW2BvPbyCVI xSIiAavK5pn4MgtrZdPKEKnfXTxvInD7mwV8hjFLxns9e1SLnfJU1G0rWTrY5MhDVW8b cwUIEqse0kiTlNHvk8yi0Ky3IV0u9yYkxzw6wLrUzIixsD4rzup9+nBdpUkuqhHJuelH nEFw== 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=IhG1ga+e4jMCr/1icaT0qzsbDovza4q20X40VnRy5Mw=; b=juqA6ReHVwNvcFMeu7Wbv3Xr92arP7n46xuBXXJTxvfQ/BVACsyode9qlUpKZAoGDc S90AkoRU2UXBaaI0xkBY6kv9kKzbC+9cNCONYpFBI1hUeC5H+x6fYXOfiYNbbT8s+SN0 ZdX8gG5/o/CpVjb3y0SMsUJsWpTDskotDKxoPlz+ch1X+W9iEjiLVjZ7Ryna8ErAIBXN 2xV93SHjPIEoKGs3JgAXD0bxkJ7Yq6Skwzf+PbQlIHZX2vWkJ1VZ62Mupyu7u7fcM/Qu PYm+CcACP0F4WyhWyRqfGhAj4etT5z57vMnomX1PEwA/U22OqxR0qKgW98ql4Sth5ieo FCmQ== X-Gm-Message-State: AJcUukcSNS9n5yfgHbKPZUcy6qfQU53mLEFJruKbjXz1c97rUiVqz8LP BhoZWeccIuLxPg+kcdkY9m22hQ== X-Google-Smtp-Source: ALg8bN4Y+xaNp3oVkt+57vV4ZLidw9dYYAcjBRI3aruZ8x1uvjg7qcZTEuQvUQ7ijUbKgU31CHGC4g== X-Received: by 2002:a5d:60cc:: with SMTP id x12mr24587573wrt.193.1548027701035; Sun, 20 Jan 2019 15:41:41 -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 V8 10/11] KVM: Log ROE violations in system log Date: Mon, 21 Jan 2019 01:39:39 +0200 Message-Id: <20190120233940.15282-11-ahmedsoliman@mena.vt.edu> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190120233940.15282-1-ahmedsoliman@mena.vt.edu> References: <20190120233940.15282-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 | 3 ++- virt/kvm/roe.c | 25 +++++++++++++++++++++++++ virt/kvm/roe_generic.h | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d92d300539..b3dc7255b0 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1945,13 +1945,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 9540473f89..e424b45e1c 100644 --- a/virt/kvm/roe.c +++ b/virt/kvm/roe.c @@ -76,6 +76,31 @@ 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) && + !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