From patchwork Thu Jan 14 17:23:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Petrova X-Patchwork-Id: 12020397 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 A003BC433DB for ; Thu, 14 Jan 2021 17:26:45 +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 5604F23B31 for ; Thu, 14 Jan 2021 17:26:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5604F23B31 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=U9bMLUlNnahePG8ZjCTNZVRBFydhLhA0hcbh67Cqo+o=; b=U4TjwFNDhB3hsQDbgDka4Jpf+ XucxZ+7um8Nc+hjF45uCCzY+Vi8yPdYw3al7giUOyyZm/BH5qhm0nxRL8BjES3nFNfAwhjXYLA4RE 2Vx8J1keL8ERHrYN1sWjcubQ487JRrkIeYqI2siEY9b69K/YD7yK5cNMCELPyihoxwK3c9b3IOBRy eGXK0qSBaiWZkHvD1S+KChKSuwqFEvabIl3chTpogB9UOr6VrqXWOkalo72NI3tmFXrrO3WKvsBNf ooAOI9IfuJTQbmI9DCQmDMfQOL+1/hWkrd2cwOb6QwWoqwQZp76nFWfC151uRU3bu+OhwvRMEjGux b3wvi78qw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l06Mp-0000or-5T; Thu, 14 Jan 2021 17:25:03 +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 1l06Mf-0000lL-Md for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 17:24:54 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id t17so5114973qvv.17 for ; Thu, 14 Jan 2021 09:24:51 -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=g4KIFCTj4cFhEnW/O46us+TReSaxYy0f2hLe/I7ffcA=; b=Hhr7KAKs8kOi8WVwQmidsIWDfqEk25rtQyJk/MDOmviLPuxOOzJXYdh3f3lkDblIxi bkOl0KJfgrERFCfypVjkChfLf+YPjTJ2R6MoqdE8g3xwuh+pQXXK3sHhXvwsKekmTuQr QQZ4C8ABTaOUX/c4/fxJ2IPw96KQYShHaP4aBligI7fm0lZfPVmDgpSb+bb/A9vzI0uT 05p9H0NYCR5SOIC0wIYgnUW2Vp5y9e+ep8LU3dqPpAd0MTpr4eJacqrwxYq+CNdewQnp iAKYH+6BEWrpZfWVGQL8yXKYA9g/L++6zE4c2taW502LbXImxUOSySltAIpQbEX82Xxe KNrg== 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=g4KIFCTj4cFhEnW/O46us+TReSaxYy0f2hLe/I7ffcA=; b=h35oF2eZX92wjUyK1+Mqu6Yk46vK9Pn9jjK+mUl6nDOGkuIxZeuJhwRRBqmi3bFN27 zE5HXbw8IX9fpMC1qfvZYGZiY/RCJZbMuiTXyqFsBW3R9hdds4MxNZd+jAHt588PUOvP 7UMNBjd/HkjLCjoNkwMyJpcGJzS7zTtcNGA8LhfbamgUploEB6v564Z0dlH94LZGcJ+n QYahx3nlLjL6JHS2yHQZhktZBpUpKrPk1TNgWfrZ0EH5C/0/W0XyRS1QctMUMBaQeTAg JxV2tDXW6mqtfwQwyUMRWZaoktBJbAjR471pWTpw1WCvwNQUG/4quFupA3GCFUCR9v0k OLyg== X-Gm-Message-State: AOAM5324ZGXhQgF/Ly1KsWWy3oKNgNbm1KLgMIaoflPYHmJel1oquZTO L7EVT5ufLWgxmCdD3s77rnXe0eDjrhaw X-Google-Smtp-Source: ABdhPJygeOs4qkIrlkzeio5jc/x8qxwkfpCDIRzqWD6MrXutel9ZiEnpHM1XoAxYJ1uynxI++vLlmJLX5+SR X-Received: from beef.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1091]) (user=lenaptr job=sendgmr) by 2002:ad4:5188:: with SMTP id b8mr8125977qvp.55.1610645090361; Thu, 14 Jan 2021 09:24:50 -0800 (PST) Date: Thu, 14 Jan 2021 17:23:35 +0000 In-Reply-To: <20210114172338.2798389-1-lenaptr@google.com> Message-Id: <20210114172338.2798389-6-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 5/9] KVM: arm64: Enable shift out of bounds undefined behaviour check for 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_122453_758836_CC0FFEEF X-CRM114-Status: GOOD ( 14.01 ) 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 __ubsan_handle_shift_out_of_bounds data is passed to the buffer inside hyp/nVHE. This data is passed to the original handler from kernel. The 64bit values of the shift expression operands are stored as the lhs and rhs pointers, so there is no need to dereference them. Signed-off-by: George Popescu Signed-off-by: Elena Petrova --- arch/arm64/include/asm/kvm_ubsan.h | 5 ++++- arch/arm64/kvm/hyp/nvhe/ubsan.c | 14 +++++++++++++- arch/arm64/kvm/kvm_ubsan_buffer.c | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_ubsan.h b/arch/arm64/include/asm/kvm_ubsan.h index 70c6f2541d07..0eef0e11a93b 100644 --- a/arch/arm64/include/asm/kvm_ubsan.h +++ b/arch/arm64/include/asm/kvm_ubsan.h @@ -19,11 +19,13 @@ struct ubsan_values { struct kvm_ubsan_info { enum { UBSAN_OUT_OF_BOUNDS, - UBSAN_UNREACHABLE_DATA + UBSAN_UNREACHABLE_DATA, + UBSAN_SHIFT_OUT_OF_BOUNDS } type; union { struct out_of_bounds_data out_of_bounds_data; struct unreachable_data unreachable_data; + struct shift_out_of_bounds_data shift_out_of_bounds_data; }; union { struct ubsan_values u_val; @@ -32,3 +34,4 @@ struct kvm_ubsan_info { void __ubsan_handle_out_of_bounds(void *_data, void *index); void __ubsan_handle_builtin_unreachable(void *_data); +void __ubsan_handle_shift_out_of_bounds(void *_data, void *lhs, void *rhs); diff --git a/arch/arm64/kvm/hyp/nvhe/ubsan.c b/arch/arm64/kvm/hyp/nvhe/ubsan.c index 5e55897b2d72..1069ed5036d5 100644 --- a/arch/arm64/kvm/hyp/nvhe/ubsan.c +++ b/arch/arm64/kvm/hyp/nvhe/ubsan.c @@ -56,7 +56,19 @@ 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_shift_out_of_bounds(void *_data, void *lhs, void *rhs) +{ + struct kvm_ubsan_info *slot; + struct shift_out_of_bounds_data *data = _data; + + slot = kvm_ubsan_buffer_next_slot(); + if (slot) { + slot->type = UBSAN_SHIFT_OUT_OF_BOUNDS; + slot->shift_out_of_bounds_data = *data; + slot->u_val.lval = lhs; + slot->u_val.rval = rhs; + } +} void __ubsan_handle_builtin_unreachable(void *_data) { diff --git a/arch/arm64/kvm/kvm_ubsan_buffer.c b/arch/arm64/kvm/kvm_ubsan_buffer.c index e51949c275aa..b80045883047 100644 --- a/arch/arm64/kvm/kvm_ubsan_buffer.c +++ b/arch/arm64/kvm/kvm_ubsan_buffer.c @@ -27,6 +27,10 @@ void __kvm_check_ubsan_data(struct kvm_ubsan_info *slot) case UBSAN_UNREACHABLE_DATA: __ubsan_handle_builtin_unreachable(&slot->unreachable_data); break; + case UBSAN_SHIFT_OUT_OF_BOUNDS: + __ubsan_handle_shift_out_of_bounds(&slot->shift_out_of_bounds_data, + slot->u_val.lval, slot->u_val.rval); + break; } }