From patchwork Sun Nov 4 17:11:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Soliman X-Patchwork-Id: 10666963 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 B2D6F13A4 for ; Sun, 4 Nov 2018 17:13:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 965A928C82 for ; Sun, 4 Nov 2018 17:13:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86CA1290B8; Sun, 4 Nov 2018 17:13:57 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 B145C28C82 for ; Sun, 4 Nov 2018 17:13:56 +0000 (UTC) Received: (qmail 32545 invoked by uid 550); 4 Nov 2018 17:12:47 -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 32478 invoked from network); 4 Nov 2018 17:12:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=TGhpIguxZKqGE+GdUaatDC/UNPrNnEL4NBgLd2GI3no=; b=t/EGvrw1MpSeR5jsmJkKVZg/m5oUFjSYOS8yLE8qz4cIL3Gcbn6/iPRjhO5O+lnmSU nyZzJwr3j5F7HdkUS6YNQf1+53OZg5+8kIC+4SL8JQzJZDitH1DCBzYlDFMQbnfFDUNc UP9aMK5MBCWXWGBkPIToeWyYPU2b58sCramhc7ZshzaAVB3gW5qS75TqutCV0qVJwjxr m8FqotY01NXAfi4AFJHJVrZ7YOawRuIEdVDNfuRpyI1evVjJqVxYoxaUkmF5nT6SDB+o dFc7PskmcOKqsW1RHd3pQL2cdhDUSEqwVyFUPKsl8g3oGQGC1x99w7QWqO4Ye0zsKEk+ zqdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=TGhpIguxZKqGE+GdUaatDC/UNPrNnEL4NBgLd2GI3no=; b=ikhFszKI08WQMEasEDycRFKdbJlGVcT7Ddr6DmEgiCqSyIzuOpWx/APr/ovBQ4O4bK SJ1JlWRbQsh5YskgjY+m52dZTUBmaNmsNHst8y8p1ySrIfkKKgmP2IoS7xjyt4SDRMdI KNk7VKAmBnaFiGyIF5jEn7OTbBPjouvsbWZHwF1k9NMN78ylk/D3ZvdMi8PMWowdZT9T qXKsjTc0oGooaf0n9uwo/rbzMyz1H7OR8CJ8rH6BhgW4yGlfhKplCWVKr0OTTpsESX5O QvrnmieJmrfJb5ctEZoR9dZNqNjy+0n2uo6HVCJfbr2AcA/55CfSkLhDdHXH2C8n82cB 0xOQ== X-Gm-Message-State: AGRZ1gL9d4oE6AxixsjKimK4j40Rm3/X/LT3NijdYa0Ckxs74OgHflLG 6V/losbjsE5ZP0Tx3rDE+Rk= X-Google-Smtp-Source: AJdET5ejay/sWk71bozJheRrobQzLIg9jrGDQJAiR0ikmiurOlkCuZvlKrsGOAnug1qWJDWykMx8gA== X-Received: by 2002:a1c:578c:: with SMTP id l134-v6mr3895086wmb.135.1541351555736; Sun, 04 Nov 2018 09:12: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 , Hossam Hassan <7ossam9063@gmail.com>, "Ahmed Lotfy igor . stoppa @ gmail . com" Subject: [PATCH V6 8/8] KVM: Log ROE violations in system log Date: Sun, 4 Nov 2018 19:11:24 +0200 Message-Id: <20181104171124.5717-9-ahmedsoliman0x666@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181104171124.5717-1-ahmedsoliman0x666@gmail.com> References: <20181104171124.5717-1-ahmedsoliman0x666@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Ahmed Abd El Mawgood --- virt/kvm/kvm_main.c | 7 +++++++ virt/kvm/roe.c | 14 ++++++++++++++ virt/kvm/roe_generic.h | 2 ++ 3 files changed, 23 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 48c5d9d9474e..d625db7f5350 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -63,6 +63,8 @@ #include "vfio.h" #include "roe_generic.h" +#include + #define CREATE_TRACE_POINTS #include @@ -1867,6 +1869,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) { @@ -1874,6 +1877,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 e94314fed3a3..c30c6b028638 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 006fc7b52bba..bce426441468 100644 --- a/virt/kvm/roe_generic.h +++ b/virt/kvm/roe_generic.h @@ -11,6 +11,7 @@ */ #ifdef CONFIG_KVM_ROE +void kvm_warning_roe_violation(u64 addr, const void *data, int len); 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, @@ -39,6 +40,7 @@ static bool kvm_roe_check_range(struct kvm_memory_slot *slot, gfn_t gfn, { return false; } +static void kvm_warning_roe_violation(u64 addr, const void *data, int len) {} #endif #endif