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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 AB4AEC433DB for ; Mon, 18 Jan 2021 11:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B520222B3 for ; Mon, 18 Jan 2021 11:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389418AbhARLIP (ORCPT ); Mon, 18 Jan 2021 06:08:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389298AbhARLH0 (ORCPT ); Mon, 18 Jan 2021 06:07:26 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0145C061573 for ; Mon, 18 Jan 2021 03:06:44 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id q18so16052559wrn.1 for ; Mon, 18 Jan 2021 03:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NnBFT8EP9V7MmU84deKSaC5Ci7/3yuRujoqea2uYBqU=; b=S0v70/XeJSnyzyiifqGs12j42+wMyVfdZmFp9vAYkXCvNspcgkhHm/aAnQRXxVKwXn xMc//0tppKYCReKyia6kMXMXxqRWsrWfKSwZ+LPj8fybmUm1d6i1vYA87dayQ08MyOUc 0p6Akb3D1OU7oM6tdHFfjG3TkuwOE22g9Eqvgr8tCeZ9J9ESNatB5rJHEaL49J/XzUYf qe/5UI+KoiKw5ugbwxf6Dph+sNadI0zgVCRMqckEhTL5F2NEWen6hNvI4IiTIZ5yzVvT ko0skt3XiUtvAqGdh6+/oV51WMeZ7c1SEhK/K0YPo731oBI195bJhJXW106wUlun6yJy 2TKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NnBFT8EP9V7MmU84deKSaC5Ci7/3yuRujoqea2uYBqU=; b=gmJskgvS8F1NVBzF9Pwxq/GD1J3XueHvOgyrDwXAiuHWIafdtX5i4Dt9vGqTjeRk3r InW6uQko0nAQLhriu/NF2Dw4DLJXyy0trqsBifNmwn/VcQzEUnhMkiel5rT+A1ARaCDi 27pup06V4t/pVRQEL4WkjBSJGV5ULV+IPp8O69xJ5TaQ2PKxnnMWU3sXUbb+ysj5pTNX ENIsosESdmTWEST4P9NRJBTlp0n54ELuwdXwUm9gERDXDIiBIdbpUWxVOfpkiUcIs3hC Ij92/wRs9TwOttYOYOyMlHE/RlpGv8NwwKSY6jKTEl5Nu0To2KNZEySG2TtskNojl/rF godg== X-Gm-Message-State: AOAM530DGdMW9z3goZ+CvHRJ12zzfo1lv4f0+//S8SoeiGoVE62DQbCd 5M12/q0c/XwVnvgiLAeKqYNNYw== X-Google-Smtp-Source: ABdhPJwWGXCEWcvWmyWLYTOB7DQ3+9c+Y1HcC/heAJVGshcFFa64ZS5RxK5AbQjre5wgJBvYLRmsBQ== X-Received: by 2002:a5d:40ce:: with SMTP id b14mr24876133wrq.350.1610968003510; Mon, 18 Jan 2021 03:06:43 -0800 (PST) Received: from google.com ([2a01:4b00:8523:2d03:3d4d:985d:87b7:4d55]) by smtp.gmail.com with ESMTPSA id g1sm29961893wrq.30.2021.01.18.03.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 03:06:42 -0800 (PST) Date: Mon, 18 Jan 2021 11:06:41 +0000 From: David Brazdil To: Elena Petrova Cc: kvmarm@lists.cs.columbia.edu, George Popescu , Marc Zyngier , open list , linux-arm-kernel@lists.infradead.org, George Popescu Subject: Re: [PATCH v3 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE Message-ID: <20210118110641.ak4jlzu34lxzluzy@google.com> References: <20210115171830.3602110-1-lenaptr@google.com> <20210115171830.3602110-4-lenaptr@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210115171830.3602110-4-lenaptr@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 05:18:24PM +0000, Elena Petrova wrote: > 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; > + }; I don't see this second union having more members later in the series. Remove it? Even the 'struct ubsan_values' seems redundant and we could just have those three fields directly here. > }; > + > +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); Not sure why this is breaking out into another function. The code will not be shared with any other user. > slot[i].type = 0; This invalidation is redundant. The buffer's cursor will be reset on next hypercall, which will implicitly invalidate all entries. > } > } > -- > 2.30.0.296.g2bfb1c46d8-goog > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-13.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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 56909C433E0 for ; Mon, 18 Jan 2021 11:06:57 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id B0F4C221F8 for ; Mon, 18 Jan 2021 11:06:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0F4C221F8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4B0A54B26B; Mon, 18 Jan 2021 06:06:51 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GKFs-77rm9o6; Mon, 18 Jan 2021 06:06:47 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 562844B26D; Mon, 18 Jan 2021 06:06:47 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A4F874B269 for ; Mon, 18 Jan 2021 06:06:46 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GHkgmHlbF4PK for ; Mon, 18 Jan 2021 06:06:44 -0500 (EST) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id C17784B265 for ; Mon, 18 Jan 2021 06:06:44 -0500 (EST) Received: by mail-wr1-f46.google.com with SMTP id v15so12374385wrx.4 for ; Mon, 18 Jan 2021 03:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NnBFT8EP9V7MmU84deKSaC5Ci7/3yuRujoqea2uYBqU=; b=S0v70/XeJSnyzyiifqGs12j42+wMyVfdZmFp9vAYkXCvNspcgkhHm/aAnQRXxVKwXn xMc//0tppKYCReKyia6kMXMXxqRWsrWfKSwZ+LPj8fybmUm1d6i1vYA87dayQ08MyOUc 0p6Akb3D1OU7oM6tdHFfjG3TkuwOE22g9Eqvgr8tCeZ9J9ESNatB5rJHEaL49J/XzUYf qe/5UI+KoiKw5ugbwxf6Dph+sNadI0zgVCRMqckEhTL5F2NEWen6hNvI4IiTIZ5yzVvT ko0skt3XiUtvAqGdh6+/oV51WMeZ7c1SEhK/K0YPo731oBI195bJhJXW106wUlun6yJy 2TKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NnBFT8EP9V7MmU84deKSaC5Ci7/3yuRujoqea2uYBqU=; b=WTyM3mQzKm2VH6fRRHluMOGsL1x5fBbZdZKug6wedfnfwL+y156xFNIwzbPfFPy1KI xHsTaHXLcvTh5SVtuuiEbqGoxkJgQGg1wsxp7U5lFI1SMaq0lXJdRgftudxfNJIwUvPs jdzJ1o243oKhFy8tGeOvs7Bg1mvBaW5Jpjzt2IZMN8poowE4Gx1Ss3dr6LsOGID9NnPG nLxKM+9HNZg+F73amowc3NwlhBaL42/UzZUOcu0xdAWG1oXjG4avPrsvOLb8FKq+pwX2 u4H4YmBbWgE1NDRTtUdOjZd5PYRNjHPQalp/I09FKVbOZXOzeXQ7Mh6tCWHXJu1pLk+A Npnw== X-Gm-Message-State: AOAM531ayyZu6xs8BC7Z+051hGeuWaPsERuDW/PjbYCV7tkyT6e9p764 lBesvkHEN6i5bUyCU/SIQ6qUCg== X-Google-Smtp-Source: ABdhPJwWGXCEWcvWmyWLYTOB7DQ3+9c+Y1HcC/heAJVGshcFFa64ZS5RxK5AbQjre5wgJBvYLRmsBQ== X-Received: by 2002:a5d:40ce:: with SMTP id b14mr24876133wrq.350.1610968003510; Mon, 18 Jan 2021 03:06:43 -0800 (PST) Received: from google.com ([2a01:4b00:8523:2d03:3d4d:985d:87b7:4d55]) by smtp.gmail.com with ESMTPSA id g1sm29961893wrq.30.2021.01.18.03.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 03:06:42 -0800 (PST) Date: Mon, 18 Jan 2021 11:06:41 +0000 From: David Brazdil To: Elena Petrova Subject: Re: [PATCH v3 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE Message-ID: <20210118110641.ak4jlzu34lxzluzy@google.com> References: <20210115171830.3602110-1-lenaptr@google.com> <20210115171830.3602110-4-lenaptr@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210115171830.3602110-4-lenaptr@google.com> Cc: George Popescu , Marc Zyngier , open list , kvmarm@lists.cs.columbia.edu, George Popescu , linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Fri, Jan 15, 2021 at 05:18:24PM +0000, Elena Petrova wrote: > 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; > + }; I don't see this second union having more members later in the series. Remove it? Even the 'struct ubsan_values' seems redundant and we could just have those three fields directly here. > }; > + > +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); Not sure why this is breaking out into another function. The code will not be shared with any other user. > slot[i].type = 0; This invalidation is redundant. The buffer's cursor will be reset on next hypercall, which will implicitly invalidate all entries. > } > } > -- > 2.30.0.296.g2bfb1c46d8-goog > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-13.9 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 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 7A28CC433E0 for ; Mon, 18 Jan 2021 11:08:20 +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 1DF52221F8 for ; Mon, 18 Jan 2021 11:08:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DF52221F8 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YataFwq6gTYxL1h+HbCrhsNnQLPvQA4nhbw8iXLq8V0=; b=LI726X/bQeL8Ld0b9oXw7JbCZ h+X9DvCcmrWcvU6Dk9qAU614zQ7EMv+yu2puVcLOLrVDWfPCxZae9Da7SKKCcox2aV0RQBRN7U6E0 xbspYZfNntOgR2/+/T/eDVV+LWY/aNpQDqxHDEXt7YF/l5lB/Hw8lnCg3uhKTEKvdFIuwV5WCzz7z foawOYbxpUH6D6PPAlOs9oNv+fMRBtJX9AdMMQ7p8wmu6HWeLLihIPWjejD5D5FcWxPxwPHKE9Xll Bc5fDa0lEhoS6K6x0YkxkGRdu+7ZaQb2xKsCswkpXNTCS68tKt6xCyqcEhVSgccN8mA7jZCasNtsC GBjU+3vwg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1SMz-00034Y-5D; Mon, 18 Jan 2021 11:06:49 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1SMv-00033a-TQ for linux-arm-kernel@lists.infradead.org; Mon, 18 Jan 2021 11:06:47 +0000 Received: by mail-wr1-x430.google.com with SMTP id 6so8733906wri.3 for ; Mon, 18 Jan 2021 03:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NnBFT8EP9V7MmU84deKSaC5Ci7/3yuRujoqea2uYBqU=; b=S0v70/XeJSnyzyiifqGs12j42+wMyVfdZmFp9vAYkXCvNspcgkhHm/aAnQRXxVKwXn xMc//0tppKYCReKyia6kMXMXxqRWsrWfKSwZ+LPj8fybmUm1d6i1vYA87dayQ08MyOUc 0p6Akb3D1OU7oM6tdHFfjG3TkuwOE22g9Eqvgr8tCeZ9J9ESNatB5rJHEaL49J/XzUYf qe/5UI+KoiKw5ugbwxf6Dph+sNadI0zgVCRMqckEhTL5F2NEWen6hNvI4IiTIZ5yzVvT ko0skt3XiUtvAqGdh6+/oV51WMeZ7c1SEhK/K0YPo731oBI195bJhJXW106wUlun6yJy 2TKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NnBFT8EP9V7MmU84deKSaC5Ci7/3yuRujoqea2uYBqU=; b=MPOxsAIvV6U3HbH8F1f2Ze+9osPbDCjOCFTYVTn2+5oQXt9IiT0e+ags2V9XJJJsgB 5sai+GYaW5C0hMKGJA2DayXP/AK2G7iWyP+X4A3nleYVu1wqAOjOpgKCkqWnS9BVaSWF eDiRpg3NY49bDS9oF3DfV1unFbCLrI/GYceJkKSz1+Wy/40JBXxzFSmokajQYBFSVEza P3hgyw2Q0HYiBB0MHL2EH4z8zoqqxBD5RTwiiEIcO7tDw0W/zpimpbLwl5N/EC70eU1T vdse/IS1d4C3rjJhIYQr4WbUEt7iDk837VtIywPTKdRDlM/4FvDXPbU9k/mw0BZZCz2a uNGA== X-Gm-Message-State: AOAM532SvcRYp+7wC6Jyq1uMtSwSWjNVP7Hvi4E3dWkfqFWvJoG1Dz0N ixuAZii9LxyH+drCCR02Biu8pQ== X-Google-Smtp-Source: ABdhPJwWGXCEWcvWmyWLYTOB7DQ3+9c+Y1HcC/heAJVGshcFFa64ZS5RxK5AbQjre5wgJBvYLRmsBQ== X-Received: by 2002:a5d:40ce:: with SMTP id b14mr24876133wrq.350.1610968003510; Mon, 18 Jan 2021 03:06:43 -0800 (PST) Received: from google.com ([2a01:4b00:8523:2d03:3d4d:985d:87b7:4d55]) by smtp.gmail.com with ESMTPSA id g1sm29961893wrq.30.2021.01.18.03.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 03:06:42 -0800 (PST) Date: Mon, 18 Jan 2021 11:06:41 +0000 From: David Brazdil To: Elena Petrova Subject: Re: [PATCH v3 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE Message-ID: <20210118110641.ak4jlzu34lxzluzy@google.com> References: <20210115171830.3602110-1-lenaptr@google.com> <20210115171830.3602110-4-lenaptr@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210115171830.3602110-4-lenaptr@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210118_060645_985364_A80B92F5 X-CRM114-Status: GOOD ( 26.70 ) 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 , Marc Zyngier , open list , kvmarm@lists.cs.columbia.edu, George Popescu , linux-arm-kernel@lists.infradead.org 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 On Fri, Jan 15, 2021 at 05:18:24PM +0000, Elena Petrova wrote: > 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; > + }; I don't see this second union having more members later in the series. Remove it? Even the 'struct ubsan_values' seems redundant and we could just have those three fields directly here. > }; > + > +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); Not sure why this is breaking out into another function. The code will not be shared with any other user. > slot[i].type = 0; This invalidation is redundant. The buffer's cursor will be reset on next hypercall, which will implicitly invalidate all entries. > } > } > -- > 2.30.0.296.g2bfb1c46d8-goog > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel