From mboxrd@z Thu Jan 1 00:00:00 1970 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=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 3CD7BC43461 for ; Mon, 14 Sep 2020 17:31:24 +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 DDEE920E65 for ; Mon, 14 Sep 2020 17:31:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FN2D3F3V"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="tSsBMUWs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDEE920E65 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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PUq1+bDWGB/5c8jwxgbiAxrZStPipiM/rDLqVd1GGbg=; b=FN2D3F3VNsyMOJzvMMcnFS5RN lqfaICPhOlzCSjRq545zMU8CdR8ajtkUCbKLrTInVpnMhuRRZNqwWNTXwU33BHdBX835+q05yQIk9 brvEVSpg4Y7vAkOkFduC+GtKMTi2Ux6qik8/+P3SERJYaAW05zqA8ugHImeCBFtOZo6T45rAw/DlW EvbfMa/srWWhHbuWZYm+94d60nFSc0cWw0OTfATHf320S9rYrc+LK8lXhb3vi2bSJmup5OQWPWBnE +VHWHWfPeemBh1Fic3/uVzgO4kFS7AY/kzmXqBgjcJGgryR6f1jIbaF9IrN3gXHg+kMIQbUyvCvVy TvOfaMfgQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHsI6-00010n-Gc; Mon, 14 Sep 2020 17:29:22 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHsH3-0000bF-1B for linux-arm-kernel@lists.infradead.org; Mon, 14 Sep 2020 17:28:19 +0000 Received: by mail-wr1-x443.google.com with SMTP id z1so532382wrt.3 for ; Mon, 14 Sep 2020 10:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VE4tiaYIO2WH178ygWtKyTutOHC4+8KlDDbyhHM4F14=; b=tSsBMUWsMvg8+rPbGLC3iYKX0M9xTuJCgz8t9VzFY/lPy2b722XAFrOELq7cSNpIxk N9S5vrz2VcmU/j3WqAfHtIo7s+KuY8ak7B/tAU5NAvf54fH1rh0GHPJ6ElKhZGk3Mdw2 ZyUng2UvYJ18NYurvGMI2vrPFIihzVaGyJOS8jOH2ePwigt8T84XvtwVOp5ByrQLnaXd SxgwfYEnrlmxDAAm/fq1xJgaWOPKHUMNCKDRSG5G7oYbjiJGUMoAY65TE+vuPGm9bag9 Lh14EdLD9IpUB/n0nxNhI+Mj+Hx5DMLpZMQ3zlrmushDlXv2bFwUMuUlbzXDmKDYSRNl l23w== 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=VE4tiaYIO2WH178ygWtKyTutOHC4+8KlDDbyhHM4F14=; b=P7pw7rqLqR3cxZHFepxkW4tkPXVDY/oU+FqXSY9mnVB4EMjXQpWUvnaoPPL6IpBNqH rw/AZVfJWVv2apT9NXEYMKBwuRYwhs26N5lGn7zHh+699jNuuKPQ4TE/Zck4S8Tzx4eP CNreDmDmQFpnCVdLLXB7uJn6nto3bB9tYx4Fh0WIB5LLMs7n7EeQaRW5mZnUbaJWXteh iDAQC6JMuIWxQ75VT9Zdxms8qk/svp39H436kTfrSqfIydT2gh8TWwKbib7nKgGZRLs+ KfEqgzs44l4USXkW9TrnaMM68oszX1RieHejOgGYa4SA+2YiDquCTEtC5DDb5yUwxuww Ao7g== X-Gm-Message-State: AOAM533u3bcVD6a3B4JUFWxcYFBkgSqIuVMFOdiKi30ijwne0SgSyJ72 bi+yCb0iQNk/lbGhzqx1/suwlA== X-Google-Smtp-Source: ABdhPJwDp0qDmVhRrvPNjBrZkX56Whr339QzJq0eZ5FLOChOIB1ToFOdRxzoHsQ+yPW+W6ciFtGbiw== X-Received: by 2002:a5d:50c3:: with SMTP id f3mr16765517wrt.125.1600104495500; Mon, 14 Sep 2020 10:28:15 -0700 (PDT) Received: from localhost (49.222.77.34.bc.googleusercontent.com. [34.77.222.49]) by smtp.gmail.com with ESMTPSA id e1sm15404359wrp.49.2020.09.14.10.28.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Sep 2020 10:28:14 -0700 (PDT) From: George-Aurelian Popescu To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, masahiroy@kernel.org, michal.lkml@markovi.net Subject: [PATCH 07/14] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE Date: Mon, 14 Sep 2020 17:27:43 +0000 Message-Id: <20200914172750.852684-8-georgepope@google.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200914172750.852684-1-georgepope@google.com> References: <20200914172750.852684-1-georgepope@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200914_132817_751610_7D2EF864 X-CRM114-Status: GOOD ( 16.60 ) 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: arnd@arndb.de, elver@google.com, tglx@linutronix.de, keescook@chromium.org, maskray@google.com, linux-kbuild@vger.kernel.org, suzuki.poulose@arm.com, ndesaulniers@google.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, George Popescu , clang-built-linux@googlegroups.com, broonie@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, dvyukov@google.com, natechancellor@gmail.com, dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, ascull@google.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 happens in kvm_ubsan_buffer.c. The struct kvm_ubsan_info contains three main components: -enum type, which is used to identify which handler to call from the kernel. -struct ubsan_values, which stores the operands involved during the undefined behaviours, which can be one, two or zero, depending on what undefiend behaviour is reported. As an example for: out_of_bounds there is only one operand (the index). Accessing a slot with no type should do nothing. Each slot is marked with the UBSAN_NONE tag after it's first usage. Signed-off-by: George Popescu --- arch/arm64/include/asm/kvm_ubsan.h | 19 ++++++++++++++++++- arch/arm64/kvm/hyp/nvhe/ubsan.c | 13 ++++++++++++- arch/arm64/kvm/kvm_ubsan_buffer.c | 13 ++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_ubsan.h b/arch/arm64/include/asm/kvm_ubsan.h index af607a796376..575881e0bd5f 100644 --- a/arch/arm64/include/asm/kvm_ubsan.h +++ b/arch/arm64/include/asm/kvm_ubsan.h @@ -11,7 +11,24 @@ #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_NONE, + UBSAN_OUT_OF_BOUNDS + } type; + union { + struct out_of_bounds_data out_of_bounds_data; + }; + union { + struct ubsan_values u_val; + }; }; #endif + +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 a43c9646e1e8..b2d3404f6215 100644 --- a/arch/arm64/kvm/hyp/nvhe/ubsan.c +++ b/arch/arm64/kvm/hyp/nvhe/ubsan.c @@ -43,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 = NULL; + 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 28dcf19b5706..ce796bdd027e 100644 --- a/arch/arm64/kvm/kvm_ubsan_buffer.c +++ b/arch/arm64/kvm/kvm_ubsan_buffer.c @@ -16,6 +16,17 @@ DECLARE_KVM_DEBUG_BUFFER(struct kvm_ubsan_info, kvm_ubsan_buff, KVM_UBSAN_BUFFER_SIZE); +void __kvm_check_ubsan_data(struct kvm_ubsan_info *slot) +{ + switch (slot->type) { + case UBSAN_NONE: + break; + case UBSAN_OUT_OF_BOUNDS: + __ubsan_handle_out_of_bounds(&slot->out_of_bounds_data, + slot->u_val.lval); + break; + } +} void __kvm_check_ubsan_buffer(void) { @@ -25,7 +36,7 @@ void __kvm_check_ubsan_buffer(void) init_kvm_debug_buffer(kvm_ubsan_buff, struct kvm_ubsan_info, slot, write_ind); for_each_kvm_debug_buffer_slot(slot, write_ind, it) { - /* check ubsan data */ + __kvm_check_ubsan_data(slot); slot->type = 0; } } -- 2.28.0.618.gf4bc123cb7-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel