Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2338045pxk; Mon, 14 Sep 2020 10:35:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUlD66S7PY8H07dB1G1K7n2wm9R8THP+8Ze1S7QBDxrTR1K/5Qd81jnX1nfsNBL37KZbVW X-Received: by 2002:a17:906:1b11:: with SMTP id o17mr16764049ejg.67.1600104916237; Mon, 14 Sep 2020 10:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600104916; cv=none; d=google.com; s=arc-20160816; b=z5cmMmIL7j4U+cvK8DCc9NAAcSplLCYvLwlPh4ZB1Pmz4ifwzcQCo/X76hy6YlxExq juaDAZiHYJfh4HgZOcb5O7HmMGd3m72QS2H6H2isQrmFcJ3kdA3l6GG/VIcV+aacL1fh R4q9oRt8cDS5qN+nU01TsFOHzm/CsCRGASX63fgI6js0tfBWwdTL9Z2OEOEqVW8UBuD0 sM6I0D7yE/yZc9m7eDhiwkeDa54l968TInASXfRfdeV9IjKs7h3ORZpGvjnN9FoqBYiI 1Vxbk2CdKCsaJSHT6SbAB2ZiYLzJ4/2FNDUt2xd/D/ouxyqDexKo5QUSf6eljmt6k6CI Mp6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VE4tiaYIO2WH178ygWtKyTutOHC4+8KlDDbyhHM4F14=; b=vLDcXFELFVs9vC5n5TYIv0sy8wldoGJ3Tte1NCx0w09eZtdR135tjzDhASGMQncWVx XYhR5RSCdcF2aZpqSzw43vTqYbbkeNK5YUfcnLZnypTbewsewAiP1AOoCGxYWM3IuPKm 90aLWI8vomBhJWNeP3fUALd9B/lkYRwnHLlqeoGURdZ1vuyOwsVhtxLioizoifsq5P2h fFzBJETciKUVGAbhUrGIpxgA9NN92QOjEMXYOWcGAWnPqU8lyTIfpcKYHNWnhTG2NiPH CGLOylMKcvZihI7flbNdVljVOVkJcawiQzZjsqEM5pA0z2HAw/a5aFjMhnbJEydhPHBL lJoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tSsBMUWs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jr1si7790146ejb.164.2020.09.14.10.34.53; Mon, 14 Sep 2020 10:35:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tSsBMUWs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726200AbgINReD (ORCPT + 99 others); Mon, 14 Sep 2020 13:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgINR2Z (ORCPT ); Mon, 14 Sep 2020 13:28:25 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE0F9C061788 for ; Mon, 14 Sep 2020 10:28:16 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id g4so515886wrs.5 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=HI5hIlJ0oUGMcVgjRYrBjeGnxcAVlzSMUz8FfURVzB908rAFebbGKYDKjXUwx/4JDd 1QnNmgoQ9ZyKhdi9NBGxupUnDNBu0W189bqx8kzXY1w+qd/agvadWbtQJMuVNJ3lk31X 30Jjf9RcBsdoVU+NttatwyYNuEINlj+ZYbeiwOk0IDReoXGMPS/eX1ck+BKodiSQzd8j 6bSdkVnSpuMxtgHsd1odg9fPmO0kJzs0vGrp19YlHHwnSy0ZxQq/iNM7eQblxxw2sZSJ CbL1RQYRcPr7CoQ00Dp9ImUhwYQ7MjddsKsxcUnZn/xGR2anVBZnaL9/d0j73qHxRX0z reYg== X-Gm-Message-State: AOAM533jRnXG7rP20xUB7y9RRyz4JDkRlw4Fh1a3TqEq8RUODNxdGFdL /OwJd1QcOG1XOSlVNCcRoqi83Q== 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 Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, natechancellor@gmail.com, ndesaulniers@google.com, dbrazdil@google.com, broonie@kernel.org, maskray@google.com, ascull@google.com, keescook@chromium.org, akpm@linux-foundation.org, dvyukov@google.com, elver@google.com, tglx@linutronix.de, arnd@arndb.de, George Popescu 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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