Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp142268pxb; Fri, 15 Jan 2021 09:21:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxT7EeWa8JFqk7JkZJqKaLH3Jhps31+WDzQT15N7kb/ekBPknOolmJBF8SOjYmn5rlTgUYY X-Received: by 2002:a17:906:e212:: with SMTP id gf18mr9784040ejb.551.1610731273885; Fri, 15 Jan 2021 09:21:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610731273; cv=none; d=google.com; s=arc-20160816; b=jfU94UHf0trhkTWTKhx9QbHJCaaFhrM3aQcFFghwRCwHomVwY505VEA1ukzpRq6ws8 pAbWxH4SYuGeWfcdVJv3ue9bUy9gIqx8C5q0NQEqv7AzxXwMWVxLSBAgmQNkEGEVLShs oIcwuNQX0PnCUvCN/d8dMZ+LGcHtwxOsRCvvJU140mzAcKo7B7wAIzF2hteF4eEI14UW ef/Gs5BGRc3h3hWS6lY/7DHSHzak6gHwtnDeb/JcNfLMiRJezuVQRTwqHwfdxa9bcmcf gYyTtkxGcJKjDTUi8y6TlwzIicuMD2sK5hWEmX43ukP8KcD6mi9yjKrc06OVOzI8Vj3T Qhpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=VLLmnZ0Ac3m76z32lc7f4mhhOZikEiI3As160KoTLrU=; b=n0iH6NDKxZB1o9/mII15rXdV9nrznJ9e4/yi1XBj+zy7ZS2m1yiBQM2T5A0ffKfuTK wCHB5nKTR0auyex2MHo4QvptLdsDGJq/r6WX7nVOa4dJrynvpRqoKushqx0axtQW6AJB OFJ/nE9iMS76FOYxvSWJ5HvHUGS9aamaPl435WdGSeiVx6I7lbwLIxVHRmC+z8RVp/hX 9yXDQmQ2EdhxmNPaBwKUd/YTvnDNXLpRC8cq80IYeIKaQpwjbEBP6wUoeQhZ3qemimNt qh3QtDMry2ZXMcLSjRCq6ycJ4Evq3hJbVJkUGtSjD0QNdM8ikrt09FoHslv7Me9kNObg mUYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="egSS6f+/"; 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 p17si1791875ejy.489.2021.01.15.09.20.49; Fri, 15 Jan 2021 09:21:13 -0800 (PST) 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="egSS6f+/"; 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 S1732099AbhAORTl (ORCPT + 99 others); Fri, 15 Jan 2021 12:19:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbhAORTl (ORCPT ); Fri, 15 Jan 2021 12:19:41 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B82ADC061794 for ; Fri, 15 Jan 2021 09:19:00 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id c83so8627169qkg.15 for ; Fri, 15 Jan 2021 09:19:00 -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=VLLmnZ0Ac3m76z32lc7f4mhhOZikEiI3As160KoTLrU=; b=egSS6f+/ZiSYDrYEqcmLy80yB2G8pLh4/46w4bOcE9bAiACETRhrIOb9DHjpvEIVRC /PgKrFttwj0MMDdD5zOroWcM10AEnpHSh4bCQdjiPpZNljcUGkNfLJRvgUCW/z/yGQfN LnctQtGQmXmFh4qFP8c74u0vAbaWhzKuG3qTIL0jDn8XsP/f1xVmGf2wfipFy0xdD1a5 6PsIwBV/6iCT6SuAY28J4lBPpO182IzI3Mhs0PwRRVnv53i45BbGMWwOVIb6W+dV/wtZ ZRYUwJGEFaLcB/qIU7O2/lXdYU4SRAXB0q5fCJNRSpnp5nw0eVPUwCE/IrGeHwWLtMxi PtdQ== 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=VLLmnZ0Ac3m76z32lc7f4mhhOZikEiI3As160KoTLrU=; b=DjI4nl40Z6LVhOop5wAisaxXN9+kyE7MLuZ4+UMnF35AoPJrEQQl5cODsZK8a9QfuZ A3/CHGTwcPJM/tPAdGRvo6mj9Cxyac112cXlledSj38U6ihBWtWkqwOTySLCP7t5FM24 ydE9V8mmrk6VcpHa2jcokPtafFYcDpdzKrG/GXYBPedsvr2Q+ZED8f0uGa6en9SFBHlX QzYWmAIvNaQddscguZ5lX1NE+HogPu+Y4izULBHbnm0IupI/ZRWAKgaV+sNxRZAF7jKL 2lgNSf3tQocOddIJ65BTDviLnAA0LHM+QAQzQ0X/JU3HRckkdCXY1tQQ3QlsSgYy8ZMn Bv6A== X-Gm-Message-State: AOAM532FOTYKrkrdL6l3Y8jU37//kJatq5w2OhT3SGrS7PBBk1nlLsZg hN5nNWYmnJchzH9fGQ9HJjS6JqO2Re0v Sender: "lenaptr via sendgmr" X-Received: from beef.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1091]) (user=lenaptr job=sendgmr) by 2002:a05:6214:a94:: with SMTP id ev20mr13079298qvb.56.1610731139913; Fri, 15 Jan 2021 09:18:59 -0800 (PST) Date: Fri, 15 Jan 2021 17:18:25 +0000 In-Reply-To: <20210115171830.3602110-1-lenaptr@google.com> Message-Id: <20210115171830.3602110-5-lenaptr@google.com> Mime-Version: 1.0 References: <20210115171830.3602110-1-lenaptr@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH v3 4/9] KVM: arm64: Enable UBsan check for unreachable code inside hyp/nVHE code From: Elena Petrova To: kvmarm@lists.cs.columbia.edu Cc: Elena Petrova , linux-arm-kernel@lists.infradead.org, open list , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , George Popescu , George Popescu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: George Popescu The data from __ubsan_handle_builtin_unreachable is passed to the buffer and printed inside the kernel by its simetric handler. Signed-off-by: George Popescu Signed-off-by: Elena Petrova --- arch/arm64/include/asm/kvm_ubsan.h | 3 +++ arch/arm64/kvm/hyp/nvhe/ubsan.c | 12 +++++++++++- arch/arm64/kvm/kvm_ubsan_buffer.c | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_ubsan.h b/arch/arm64/include/asm/kvm_ubsan.h index 4f471acb88b0..70c6f2541d07 100644 --- a/arch/arm64/include/asm/kvm_ubsan.h +++ b/arch/arm64/include/asm/kvm_ubsan.h @@ -19,9 +19,11 @@ struct ubsan_values { struct kvm_ubsan_info { enum { UBSAN_OUT_OF_BOUNDS, + UBSAN_UNREACHABLE_DATA } type; union { struct out_of_bounds_data out_of_bounds_data; + struct unreachable_data unreachable_data; }; union { struct ubsan_values u_val; @@ -29,3 +31,4 @@ struct kvm_ubsan_info { }; void __ubsan_handle_out_of_bounds(void *_data, void *index); +void __ubsan_handle_builtin_unreachable(void *_data); diff --git a/arch/arm64/kvm/hyp/nvhe/ubsan.c b/arch/arm64/kvm/hyp/nvhe/ubsan.c index 55a8f6db8555..5e55897b2d72 100644 --- a/arch/arm64/kvm/hyp/nvhe/ubsan.c +++ b/arch/arm64/kvm/hyp/nvhe/ubsan.c @@ -58,6 +58,16 @@ void __ubsan_handle_out_of_bounds(void *_data, void *index) void __ubsan_handle_shift_out_of_bounds(void *_data, void *lhs, void *rhs) {} -void __ubsan_handle_builtin_unreachable(void *_data) {} +void __ubsan_handle_builtin_unreachable(void *_data) +{ + struct kvm_ubsan_info *slot; + struct unreachable_data *data = _data; + + slot = kvm_ubsan_buffer_next_slot(); + if (slot) { + slot->type = UBSAN_UNREACHABLE_DATA; + slot->unreachable_data = *data; + } +} void __ubsan_handle_load_invalid_value(void *_data, void *val) {} diff --git a/arch/arm64/kvm/kvm_ubsan_buffer.c b/arch/arm64/kvm/kvm_ubsan_buffer.c index a1523f86be3c..e51949c275aa 100644 --- a/arch/arm64/kvm/kvm_ubsan_buffer.c +++ b/arch/arm64/kvm/kvm_ubsan_buffer.c @@ -24,6 +24,9 @@ void __kvm_check_ubsan_data(struct kvm_ubsan_info *slot) __ubsan_handle_out_of_bounds(&slot->out_of_bounds_data, slot->u_val.lval); break; + case UBSAN_UNREACHABLE_DATA: + __ubsan_handle_builtin_unreachable(&slot->unreachable_data); + break; } } -- 2.30.0.296.g2bfb1c46d8-goog