The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Brazdil <dbrazdil@google.com>
To: Elena Petrova <lenaptr@google.com>
Cc: kvmarm@lists.cs.columbia.edu,
	George Popescu <georgepope@google.com>,
	Marc Zyngier <maz@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	George Popescu <george.apopescu97@gmail.com>
Subject: Re: [PATCH v3 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE
Date: Mon, 18 Jan 2021 11:06:41 +0000	[thread overview]
Message-ID: <20210118110641.ak4jlzu34lxzluzy@google.com> (raw)
In-Reply-To: <20210115171830.3602110-4-lenaptr@google.com>

On Fri, Jan 15, 2021 at 05:18:24PM +0000, Elena Petrova wrote:
> From: George Popescu <georgepope@google.com>
> 
> 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 <georgepope@google.com>
> Signed-off-by: Elena Petrova <lenaptr@google.com>
> ---
>  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 <asm/kvm_ubsan.h>
>  #include <asm/kvm_debug_buffer.h>
>  #include <kvm/arm_pmu.h>
> -#include <ubsan.h>
>  
>  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

  reply	other threads:[~2021-01-18 11:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 17:18 [PATCH v3 0/9] UBSan Enablement for hyp/nVHE code Elena Petrova
2021-01-15 17:18 ` [PATCH v3 1/9] KVM: arm64: Enable UBSan instrumentation in nVHE hyp code Elena Petrova
2021-01-18  9:53   ` David Brazdil
2021-01-15 17:18 ` [PATCH v3 2/9] KVM: arm64: Add a buffer that can pass UBSan data from hyp/nVHE to kernel Elena Petrova
2021-01-18 10:37   ` David Brazdil
2021-01-15 17:18 ` [PATCH v3 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE Elena Petrova
2021-01-18 11:06   ` David Brazdil [this message]
2021-01-15 17:18 ` [PATCH v3 4/9] KVM: arm64: Enable UBsan check for unreachable code inside hyp/nVHE code Elena Petrova
2021-01-15 17:18 ` [PATCH v3 5/9] KVM: arm64: Enable shift out of bounds undefined behaviour check for hyp/nVHE Elena Petrova
2021-01-15 17:18 ` [PATCH v3 6/9] KVM: arm64: __ubsan_handle_load_invalid_value EL2 implementation Elena Petrova
2021-01-15 17:18 ` [PATCH v3 7/9] KVM: arm64: Detect type mismatch undefined behaviour from hyp/nVHE code Elena Petrova
2021-01-15 17:18 ` [PATCH v3 8/9] KVM: arm64: Detect arithmetic overflow is inside hyp/nVHE Elena Petrova
2021-01-15 17:18 ` [PATCH v3 9/9] KVM: arm64: Add UBSan tests for PKVM Elena Petrova
2021-01-18 10:44   ` David Brazdil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210118110641.ak4jlzu34lxzluzy@google.com \
    --to=dbrazdil@google.com \
    --cc=george.apopescu97@gmail.com \
    --cc=georgepope@google.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=lenaptr@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox