From patchwork Thu Jan 14 17:23:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Petrova X-Patchwork-Id: 12020393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68B45C433DB for ; Thu, 14 Jan 2021 17:26:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B1C323A5E for ; Thu, 14 Jan 2021 17:26:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B1C323A5E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kGTexQRtDtRxBbDh2TY+O4Ybdr1VKscS7eiHmVINR70=; b=p6npp3qnZnZFIfV4ePKQ9x+iu Zl0y3pe7drhaojO9s/pSTmar8H8OWLifirtRimkEAzPlCGMuYIzl/IS8nFlDBzM3LOW2SZ9GlvO3P eI+h9EJvCnE/jThPot7ZBcZxBiGka8hN0m4MD5wzO3kZW51yohnFB/wm32jvVOYvDmJFBSitH/hk+ dc5i41pKzoD99WT7xiuDJTchAaIc6f8bQOSeKKKp9SGA1EWDSGiXrns2v8pH58yy4exA4QLlcMAvw eTLlxWYQ5UnL3YQi5/eDYTnFfkweXUZxnVXdb5XwgdJOPP2s+aL5TPHZCTETfS986WGy+tXV7Bopd nPEoQZEtw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l06Mc-0000lD-WB; Thu, 14 Jan 2021 17:24:51 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l06MZ-0000jW-2G for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 17:24:48 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id eb4so5114786qvb.21 for ; Thu, 14 Jan 2021 09:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=xV+/a2Rp5lRcHlFRCafjdMqZdknib/NjGfl4/F+eUSQ=; b=RHWeCTmFFlh0JG7mSrwt1xtK3BPDcF/hNwHiBSWk2tm3duHiYAEvtevj2/GAO5f869 2m3HICWqldEJ2EfhWZYJCnQAAWHfwp4TUOTERQqiZTnMzKq4FXSuSlHKsQCkxaLo5kyJ JZVSqwaPfHYu/kDGisDgA7beJwN0XcGGRgTpC4koHF1IBZ6E1aV1zcU2X2ozQZL+hprg GrABIORMdgZx5+EJ9vs7hqClA49Ey+lSP3BmQz4bubQJKTHQ36oAAVVxJ3tegF17coOb T9ZgM+wBKsYD90vhlOkPfEgk6gcyTQJ+48x4N36NaoN+BBBZ8562dlxSZD1b5nMk/z5w cP2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xV+/a2Rp5lRcHlFRCafjdMqZdknib/NjGfl4/F+eUSQ=; b=PmxHffCWU01u5MDRcHeE+lsBH+o9KD0d1e+Bkl5u3PGNyNJnHdCEGDSRrL/dP05Slm NR2L60lnvi3CvWwISjz++HekwWCQSWVlGMNNvxjL0GBmFnijisZsiMKd6/abNnTmrASR 1JaTKrBoNht98JqZ2MqBbVUIhEldfdnbajx3skp2WejxOlfrBxuu/ng7wDl+IVJz3Df/ taPMjj4WuLfH1BuI9m0YlwWJLzgQuKjCagBgZKshAmnrmkQ9IDePwaAPE82FZSGgBBcf X4gyoMURGOd+FmL9qnClw8Sogp18bDMr0Zc9TvwV164xRSE9z59KRj2thvAqxC+D22by vGBQ== X-Gm-Message-State: AOAM5321HlSs4uuw5itplMrZprPXOgzjxVFfGx984m40J06ow0To2q+1 3U806nVkbRfgpuXE9Zpy5oJ08MWp87NU X-Google-Smtp-Source: ABdhPJxYOrg0jToecCcCtBlCANab6SAeOu4IUUuOLW8kdj70MALJwg3ucMAxQNeuFfe9E7QdMPkIvkLD8o+D X-Received: from beef.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1091]) (user=lenaptr job=sendgmr) by 2002:a0c:a789:: with SMTP id v9mr7957944qva.41.1610645082204; Thu, 14 Jan 2021 09:24:42 -0800 (PST) Date: Thu, 14 Jan 2021 17:23:33 +0000 In-Reply-To: <20210114172338.2798389-1-lenaptr@google.com> Message-Id: <20210114172338.2798389-4-lenaptr@google.com> Mime-Version: 1.0 References: <20210114172338.2798389-1-lenaptr@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE From: Elena Petrova To: kvmarm@lists.cs.columbia.edu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210114_122447_186606_5BF39443 X-CRM114-Status: GOOD ( 14.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: George Popescu , Elena Petrova , Suzuki K Poulose , Marc Zyngier , open list , James Morse , linux-arm-kernel@lists.infradead.org, George Popescu , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: George Popescu If an out of bounds happens inside the hyp/nVHE code, the ubsan_out_of_bounds handler stores the logging data inside the kvm_ubsan_buffer. The one responsible for printing is the kernel ubsan_out_of_bounds handler. The process of decapsulating the data from the buffer is straightforward. Signed-off-by: George Popescu Signed-off-by: Elena Petrova --- arch/arm64/include/asm/kvm_ubsan.h | 19 ++++++++++++++++++- arch/arm64/kvm/hyp/nvhe/ubsan.c | 14 ++++++++++++-- arch/arm64/kvm/kvm_ubsan_buffer.c | 10 ++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_ubsan.h b/arch/arm64/include/asm/kvm_ubsan.h index fb32c7fd65d4..4f471acb88b0 100644 --- a/arch/arm64/include/asm/kvm_ubsan.h +++ b/arch/arm64/include/asm/kvm_ubsan.h @@ -9,6 +9,23 @@ #define UBSAN_MAX_TYPE 6 #define KVM_UBSAN_BUFFER_SIZE 1000 + +struct ubsan_values { + void *lval; + void *rval; + char op; +}; + struct kvm_ubsan_info { - int type; + enum { + UBSAN_OUT_OF_BOUNDS, + } type; + union { + struct out_of_bounds_data out_of_bounds_data; + }; + union { + struct ubsan_values u_val; + }; }; + +void __ubsan_handle_out_of_bounds(void *_data, void *index); diff --git a/arch/arm64/kvm/hyp/nvhe/ubsan.c b/arch/arm64/kvm/hyp/nvhe/ubsan.c index 8a194fb1f6cf..55a8f6db8555 100644 --- a/arch/arm64/kvm/hyp/nvhe/ubsan.c +++ b/arch/arm64/kvm/hyp/nvhe/ubsan.c @@ -13,7 +13,6 @@ #include #include #include -#include DEFINE_KVM_DEBUG_BUFFER(struct kvm_ubsan_info, kvm_ubsan_buffer, kvm_ubsan_buff_wr_ind, KVM_UBSAN_BUFFER_SIZE); @@ -44,7 +43,18 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, void *ptr) {} void __ubsan_handle_type_mismatch_v1(void *_data, void *ptr) {} -void __ubsan_handle_out_of_bounds(void *_data, void *index) {} +void __ubsan_handle_out_of_bounds(void *_data, void *index) +{ + struct kvm_ubsan_info *slot; + struct out_of_bounds_data *data = _data; + + slot = kvm_ubsan_buffer_next_slot(); + if (slot) { + slot->type = UBSAN_OUT_OF_BOUNDS; + slot->out_of_bounds_data = *data; + slot->u_val.lval = index; + } +} void __ubsan_handle_shift_out_of_bounds(void *_data, void *lhs, void *rhs) {} diff --git a/arch/arm64/kvm/kvm_ubsan_buffer.c b/arch/arm64/kvm/kvm_ubsan_buffer.c index 4a1959ba9f68..a1523f86be3c 100644 --- a/arch/arm64/kvm/kvm_ubsan_buffer.c +++ b/arch/arm64/kvm/kvm_ubsan_buffer.c @@ -17,6 +17,15 @@ DECLARE_KVM_DEBUG_BUFFER(struct kvm_ubsan_info, kvm_ubsan_buffer, kvm_ubsan_buff_wr_ind, KVM_UBSAN_BUFFER_SIZE); +void __kvm_check_ubsan_data(struct kvm_ubsan_info *slot) +{ + switch (slot->type) { + case UBSAN_OUT_OF_BOUNDS: + __ubsan_handle_out_of_bounds(&slot->out_of_bounds_data, + slot->u_val.lval); + break; + } +} void iterate_kvm_ubsan_buffer(unsigned long left, unsigned long right) { @@ -26,6 +35,7 @@ void iterate_kvm_ubsan_buffer(unsigned long left, unsigned long right) slot = (struct kvm_ubsan_info *) this_cpu_ptr_nvhe_sym(kvm_ubsan_buffer); for (i = left; i < right; ++i) { /* check ubsan data */ + __kvm_check_ubsan_data(slot + i); slot[i].type = 0; } }