From: Elena Petrova <hidden> Date: 2021-01-15 17:19:42
Respin of George's patch series enabling UBSAN for hyp/nVHE code.
Updates in v3:
* rebased onto v5.11-rc3
* added base commit info
Updates in v2:
* CONFIG_KVM_ARM_DEBUG_BUFFER removed; __kvm_check_ubsan_buffer is
called directly instead of via __kvm_arm_check_debug_buffer.
* Bugfixing commits removed as these are already upstream.
* Some code brought up to date, i.e. moved from entry.S to host.S.
* Merged "Add support for creating and checking a buffer" and
"Add a buffer that can pass UBSan data from hyp/nVHE" into
one commit as these changes don't work without each other.
George Popescu (9):
KVM: arm64: Enable UBSan instrumentation in nVHE hyp code
KVM: arm64: Add a buffer that can pass UBSan data from hyp/nVHE to
kernel
KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE
KVM: arm64: Enable UBsan check for unreachable code inside hyp/nVHE
code
KVM: arm64: Enable shift out of bounds undefined behaviour check for
hyp/nVHE
KVM: arm64: __ubsan_handle_load_invalid_value EL2 implementation.
KVM: arm64: Detect type mismatch undefined behaviour from hyp/nVHE
code
KVM: arm64: Detect arithmetic overflow is inside hyp/nVHE.
KVM: arm64: Add UBSan tests for PKVM.
arch/arm64/include/asm/assembler.h | 10 ++
arch/arm64/include/asm/kvm_debug_buffer.h | 34 ++++
arch/arm64/include/asm/kvm_host.h | 8 +-
arch/arm64/include/asm/kvm_ubsan.h | 50 ++++++
arch/arm64/kvm/Makefile | 2 +
arch/arm64/kvm/arm.c | 9 ++
arch/arm64/kvm/hyp/include/hyp/test_ubsan.h | 112 +++++++++++++
arch/arm64/kvm/hyp/nvhe/Makefile | 3 +-
arch/arm64/kvm/hyp/nvhe/host.S | 4 +
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 3 +
arch/arm64/kvm/hyp/nvhe/ubsan.c | 164 ++++++++++++++++++++
arch/arm64/kvm/kvm_ubsan_buffer.c | 81 ++++++++++
12 files changed, 478 insertions(+), 2 deletions(-)
create mode 100644 arch/arm64/include/asm/kvm_debug_buffer.h
create mode 100644 arch/arm64/include/asm/kvm_ubsan.h
create mode 100644 arch/arm64/kvm/hyp/include/hyp/test_ubsan.h
create mode 100644 arch/arm64/kvm/hyp/nvhe/ubsan.c
create mode 100644 arch/arm64/kvm/kvm_ubsan_buffer.c
base-commit: 5ee88057889bbca5f5bb96031b62b3756b33e164
--
2.30.0.296.g2bfb1c46d8-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Elena Petrova <hidden> Date: 2021-01-15 17:19:42
From: George-Aurelian Popescu <redacted>
Implement UBSan handlers inside nVHe hyp code, as empty functions for the
moment, so the undefined behaviours, that are triggered there, will be
linked to them, not to the ones defined in kernel-proper lib/ubsan.c.
In this way, enabling UBSAN_MISC won't cause a link error.
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++-
arch/arm64/kvm/hyp/nvhe/ubsan.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/kvm/hyp/nvhe/ubsan.c
@@ -61,7 +63,6 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAG# cause crashes. Just disable it.GCOV_PROFILE:=nKASAN_SANITIZE:=n-UBSAN_SANITIZE:=nKCOV_INSTRUMENT:=n# Skip objtool checking for this directory because nVHE code is compiled with
From: Elena Petrova <hidden> Date: 2021-01-15 17:19:42
From: George Popescu <redacted>
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 <redacted>
Signed-off-by: Elena Petrova <redacted>
---
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(-)
@@ -26,6 +35,7 @@ void iterate_kvm_ubsan_buffer(unsigned long left, unsigned long right)slot=(structkvm_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);slot[i].type=0;}}
--
2.30.0.296.g2bfb1c46d8-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Elena Petrova <hidden> Date: 2021-01-15 17:19:42
From: George Popescu <redacted>
Share a buffer between the kernel and the hyp/nVHE code by using the
macros from kvm_debug_buffer.h.
The hyp/nVHE code requires a write index which counts how many elements
have been writtens inside the buffer and the kernel requires a read
index which counts how many elements have been read from the buffer.
The write index and the buffer are shared with the kernel in read-only.
The kvm_debug_buffer_ind returns the reading and writing points of the
circular buffer and updates the reading index.
Data collected from UBSan handlers inside hyp/nVHE is stored in the
kvm_ubsan_buffer.
This buffer stores only UBSan data because it should not be preoccupied
by other mechanisms data structures and functionalities.
Also, for the moment the buffer is mapped inside .bss, where both the kernel
and the hyp/nVHE code have Read/Write rights, but in the future this will change
and the kernel will not be able to acess hyp/nVHE's .bss. At that point the buffer
will only need to be mapped in order for this patch to work.
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/assembler.h | 11 +++++++
arch/arm64/include/asm/kvm_debug_buffer.h | 36 ++++++++++++++++++++
arch/arm64/include/asm/kvm_host.h | 8 ++++-
arch/arm64/include/asm/kvm_ubsan.h | 14 ++++++++
arch/arm64/kvm/Makefile | 2 ++
arch/arm64/kvm/arm.c | 9 +++++
arch/arm64/kvm/hyp/nvhe/host.S | 4 +++
arch/arm64/kvm/hyp/nvhe/ubsan.c | 23 +++++++++++++
arch/arm64/kvm/kvm_ubsan_buffer.c | 40 +++++++++++++++++++++++
9 files changed, 146 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/include/asm/kvm_debug_buffer.h
create mode 100644 arch/arm64/include/asm/kvm_ubsan.h
create mode 100644 arch/arm64/kvm/kvm_ubsan_buffer.c
@@ -1784,6 +1784,15 @@ static int init_hyp_mode(void)gotoout_err;}}+#ifdef CONFIG_UBSAN+/* required by ubsan to access the handlers structures fields */+err=create_hyp_mappings(kvm_ksym_ref(_data),+kvm_ksym_ref(__end_once),PAGE_HYP_RO);+if(err){+kvm_err("Cannot map data section\n");+gotoout_err;+}+#endif/**MapHyppercpupages
From: Elena Petrova <hidden> Date: 2021-01-15 17:20:04
From: George Popescu <redacted>
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 <redacted>
Signed-off-by: Elena Petrova <redacted>
---
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(-)
From: Elena Petrova <hidden> Date: 2021-01-15 17:20:24
From: George Popescu <redacted>
__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 <redacted>
Signed-off-by: Elena Petrova <redacted>
---
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(-)
From: Elena Petrova <hidden> Date: 2021-01-15 17:20:24
From: George Popescu <redacted>
The handler for the load invalid value undefined behaviour is
implemented at EL2. The EL2 handler's parameters are stored inside the buffer.
They are used by the symetric handler from EL1.
Signed-off-by: George Popescu <redacted>
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/kvm_ubsan.h | 5 ++++-
arch/arm64/kvm/hyp/nvhe/ubsan.c | 14 +++++++++++++-
arch/arm64/kvm/kvm_ubsan_buffer.c | 6 +++++-
3 files changed, 22 insertions(+), 3 deletions(-)
From: Elena Petrova <hidden> Date: 2021-01-15 17:20:24
From: George Popescu <redacted>
Whenever an arithmetic overflow: addition, substraction, multiplication,
division or negating happens inside the hyp/nVHE code,
an __ubsan_handle_*_overflow is called.
All the overflow handlers are sharing the same structure called
overflow_data.
Signed-off-by: George Popescu <redacted>
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/kvm_ubsan.h | 10 ++++++--
arch/arm64/kvm/hyp/nvhe/ubsan.c | 40 ++++++++++++++++++++++++++----
arch/arm64/kvm/kvm_ubsan_buffer.c | 20 ++++++++++++++-
3 files changed, 62 insertions(+), 8 deletions(-)
From: Elena Petrova <hidden> Date: 2021-01-15 17:20:25
From: George Popescu <redacted>
Type mismatch undefiend behaviour handler provides two handlers with two
data structures type_mismatch_data and type_mismatch_data_v1. Both can be
stored inside a common data structure: type_mismatch_data_common, which
differs of type_mismatch_data only by keeping a pointer to a
struct source_location.
In this way, the buffer keeps the data encapsulated inside of a struct
type_mismatch_data, because pointers from nVHE can not be passed to the
kernel.
Inside the kernel call the __ubsan_handle_type_mismatch_data with the
data from the buffer.
Signed-off-by: George Popescu <redacted>
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/kvm_ubsan.h | 6 ++++-
arch/arm64/kvm/hyp/nvhe/ubsan.c | 41 ++++++++++++++++++++++++++++--
arch/arm64/kvm/kvm_ubsan_buffer.c | 5 +++-
3 files changed, 48 insertions(+), 4 deletions(-)
From: Elena Petrova <hidden> Date: 2021-01-15 17:20:25
From: George-Aurelian Popescu <redacted>
Test the UBsan functionality inside hyp/nVHE.
Because modules are not supported inside of hyp/nVHE code, the default
testing module for UBSan can not be used.
New functions have to be defined inside of hyp/nVHE.
They are called in kvm_get_mdcr_el2, to test UBSAN whenever a VM starts.
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/assembler.h | 17 ++-
arch/arm64/include/asm/kvm_debug_buffer.h | 10 +-
arch/arm64/include/asm/kvm_ubsan.h | 2 +-
arch/arm64/kvm/hyp/include/hyp/test_ubsan.h | 112 ++++++++++++++++++++
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 3 +
arch/arm64/kvm/kvm_ubsan_buffer.c | 1 -
6 files changed, 128 insertions(+), 17 deletions(-)
create mode 100644 arch/arm64/kvm/hyp/include/hyp/test_ubsan.h
@@ -0,0 +1,112 @@+/* SPDX-License-Identifier: GPL-2.0-only */++#include<linux/ctype.h>++typedefvoid(*test_ubsan_fp)(void);++staticvoidtest_ubsan_add_overflow(void)+{+volatileintval=INT_MAX;++val+=2;+}++staticvoidtest_ubsan_sub_overflow(void)+{+volatileintval=INT_MIN;+volatileintval2=2;++val-=val2;+}++staticvoidtest_ubsan_mul_overflow(void)+{+volatileintval=INT_MAX/2;++val*=3;+}++staticvoidtest_ubsan_negate_overflow(void)+{+volatileintval=INT_MIN;++val=-val;+}++staticvoidtest_ubsan_divrem_overflow(void)+{+volatileintval=16;+volatileintval2=0;++val/=val2;+}++staticvoidtest_ubsan_shift_out_of_bounds(void)+{+volatileintval=-1;+intval2=10;++val2<<=val;+}++staticvoidtest_ubsan_out_of_bounds(void)+{+volatileinti=4,j=5;+volatileintarr[4];++arr[j]=i;+}++staticvoidtest_ubsan_load_invalid_value(void)+{+volatilechar*dst,*src;+boolval,val2,*ptr;+charc=4;++dst=(char*)&val;+src=&c;+*dst=*src;++ptr=&val2;+val2=val;+}++staticvoidtest_ubsan_misaligned_access(void)+{+volatilechararr[5]__aligned(4)={1,2,3,4,5};+volatileint*ptr,val=6;++ptr=(int*)(arr+1);+*ptr=val;+}++staticvoidtest_ubsan_object_size_mismatch(void)+{+/* "((aligned(8)))" helps this not into be misaligned for ptr-access. */+volatileintval__aligned(8)=4;+volatilelonglong*ptr,val2;++ptr=(longlong*)&val;+val2=*ptr;+}++staticconsttest_ubsan_fptest_ubsan_array[]={+test_ubsan_out_of_bounds,+test_ubsan_add_overflow,+test_ubsan_sub_overflow,+test_ubsan_mul_overflow,+test_ubsan_negate_overflow,+test_ubsan_divrem_overflow,+test_ubsan_shift_out_of_bounds,+test_ubsan_load_invalid_value,+test_ubsan_misaligned_access,+test_ubsan_object_size_mismatch,+};++staticvoidtest_ubsan(void)+{+unsignedinti;++for(i=0;i<ARRAY_SIZE(test_ubsan_array);i++)+test_ubsan_array[i]();+}
From: David Brazdil <hidden> Date: 2021-01-18 10:18:44
On Fri, Jan 15, 2021 at 05:18:22PM +0000, Elena Petrova wrote:
From: George-Aurelian Popescu <redacted>
Implement UBSan handlers inside nVHe hyp code, as empty functions for the
moment, so the undefined behaviours, that are triggered there, will be
linked to them, not to the ones defined in kernel-proper lib/ubsan.c.
In this way, enabling UBSAN_MISC won't cause a link error.
The commit message needs to be updated - UBSAN_MISC does not exist any longer.
Also "nVHe" is a typo.
Other than that:
Acked-by: David Brazdil <redacted>
@@ -61,7 +63,6 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAG# cause crashes. Just disable it.GCOV_PROFILE:=nKASAN_SANITIZE:=n-UBSAN_SANITIZE:=nKCOV_INSTRUMENT:=n# Skip objtool checking for this directory because nVHE code is compiled with
From: David Brazdil <hidden> Date: 2021-01-18 11:08:33
On Fri, Jan 15, 2021 at 05:18:24PM +0000, Elena Petrova wrote:
quoted hunk
From: George Popescu <redacted>
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 <redacted>
Signed-off-by: Elena Petrova <redacted>
---
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(-)
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.
@@ -26,6 +35,7 @@ void iterate_kvm_ubsan_buffer(unsigned long left, unsigned long right)slot=(structkvm_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.
From: David Brazdil <hidden> Date: 2021-01-18 20:08:39
On Fri, Jan 15, 2021 at 05:18:30PM +0000, Elena Petrova wrote:
quoted hunk
From: George-Aurelian Popescu <redacted>
Test the UBsan functionality inside hyp/nVHE.
Because modules are not supported inside of hyp/nVHE code, the default
testing module for UBSan can not be used.
New functions have to be defined inside of hyp/nVHE.
They are called in kvm_get_mdcr_el2, to test UBSAN whenever a VM starts.
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/assembler.h | 17 ++-
arch/arm64/include/asm/kvm_debug_buffer.h | 10 +-
arch/arm64/include/asm/kvm_ubsan.h | 2 +-
arch/arm64/kvm/hyp/include/hyp/test_ubsan.h | 112 ++++++++++++++++++++
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 3 +
arch/arm64/kvm/kvm_ubsan_buffer.c | 1 -
6 files changed, 128 insertions(+), 17 deletions(-)
create mode 100644 arch/arm64/kvm/hyp/include/hyp/test_ubsan.h
This also looks like it should have been in a previous patch. The code assumes
that 'type == 0' means 'empty slot'. So presumably this is fixing a bug?
@@ -0,0 +1,112 @@+/* SPDX-License-Identifier: GPL-2.0-only */++#include<linux/ctype.h>++typedefvoid(*test_ubsan_fp)(void);++staticvoidtest_ubsan_add_overflow(void)+{+volatileintval=INT_MAX;++val+=2;+}++staticvoidtest_ubsan_sub_overflow(void)+{+volatileintval=INT_MIN;+volatileintval2=2;++val-=val2;+}++staticvoidtest_ubsan_mul_overflow(void)+{+volatileintval=INT_MAX/2;++val*=3;+}++staticvoidtest_ubsan_negate_overflow(void)+{+volatileintval=INT_MIN;++val=-val;+}++staticvoidtest_ubsan_divrem_overflow(void)+{+volatileintval=16;+volatileintval2=0;++val/=val2;+}++staticvoidtest_ubsan_shift_out_of_bounds(void)+{+volatileintval=-1;+intval2=10;++val2<<=val;+}++staticvoidtest_ubsan_out_of_bounds(void)+{+volatileinti=4,j=5;+volatileintarr[4];++arr[j]=i;+}++staticvoidtest_ubsan_load_invalid_value(void)+{+volatilechar*dst,*src;+boolval,val2,*ptr;+charc=4;++dst=(char*)&val;+src=&c;+*dst=*src;++ptr=&val2;+val2=val;+}++staticvoidtest_ubsan_misaligned_access(void)+{+volatilechararr[5]__aligned(4)={1,2,3,4,5};+volatileint*ptr,val=6;++ptr=(int*)(arr+1);+*ptr=val;+}++staticvoidtest_ubsan_object_size_mismatch(void)+{+/* "((aligned(8)))" helps this not into be misaligned for ptr-access. */+volatileintval__aligned(8)=4;+volatilelonglong*ptr,val2;++ptr=(longlong*)&val;+val2=*ptr;+}++staticconsttest_ubsan_fptest_ubsan_array[]={+test_ubsan_out_of_bounds,+test_ubsan_add_overflow,+test_ubsan_sub_overflow,+test_ubsan_mul_overflow,+test_ubsan_negate_overflow,+test_ubsan_divrem_overflow,+test_ubsan_shift_out_of_bounds,+test_ubsan_load_invalid_value,+test_ubsan_misaligned_access,+test_ubsan_object_size_mismatch,+};++staticvoidtest_ubsan(void)+{+unsignedinti;++for(i=0;i<ARRAY_SIZE(test_ubsan_array);i++)+test_ubsan_array[i]();+}
We cannot keep this in here. It's useful to exercise your code in development
but not something you should upstream. I would either remove this completely or
implement it as a separate hypercall.
From: David Brazdil <hidden> Date: 2021-01-18 20:32:21
On Fri, Jan 15, 2021 at 05:18:23PM +0000, Elena Petrova wrote:
quoted hunk
From: George Popescu <redacted>
Share a buffer between the kernel and the hyp/nVHE code by using the
macros from kvm_debug_buffer.h.
The hyp/nVHE code requires a write index which counts how many elements
have been writtens inside the buffer and the kernel requires a read
index which counts how many elements have been read from the buffer.
The write index and the buffer are shared with the kernel in read-only.
The kvm_debug_buffer_ind returns the reading and writing points of the
circular buffer and updates the reading index.
Data collected from UBSan handlers inside hyp/nVHE is stored in the
kvm_ubsan_buffer.
This buffer stores only UBSan data because it should not be preoccupied
by other mechanisms data structures and functionalities.
Also, for the moment the buffer is mapped inside .bss, where both the kernel
and the hyp/nVHE code have Read/Write rights, but in the future this will change
and the kernel will not be able to acess hyp/nVHE's .bss. At that point the buffer
will only need to be mapped in order for this patch to work.
Signed-off-by: Elena Petrova <redacted>
---
arch/arm64/include/asm/assembler.h | 11 +++++++
arch/arm64/include/asm/kvm_debug_buffer.h | 36 ++++++++++++++++++++
arch/arm64/include/asm/kvm_host.h | 8 ++++-
arch/arm64/include/asm/kvm_ubsan.h | 14 ++++++++
arch/arm64/kvm/Makefile | 2 ++
arch/arm64/kvm/arm.c | 9 +++++
arch/arm64/kvm/hyp/nvhe/host.S | 4 +++
arch/arm64/kvm/hyp/nvhe/ubsan.c | 23 +++++++++++++
arch/arm64/kvm/kvm_ubsan_buffer.c | 40 +++++++++++++++++++++++
9 files changed, 146 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/include/asm/kvm_debug_buffer.h
create mode 100644 arch/arm64/include/asm/kvm_ubsan.h
create mode 100644 arch/arm64/kvm/kvm_ubsan_buffer.c
This is subjective but I would:
* stop calling the second variable a "write index" and instead call it
"cursor" - I think this is a leftover from George's early two-cursor
implementation
* wrap these two variables in a struct; that is a bit tricky given that each
instantiation defines its own size (the macros would have to generate that
struct), so bar that I would at least generate the name of the cursor
variable as buffer_name##suffix.
I find this macro odd. Everything else in this file is about a generic buffer
data structure, yet this macro enumerates all instantiations of it (currently
just one). Please keep this generic and pass the name of the buffer cursor
as a parameter.
@@ -1784,6 +1784,15 @@ static int init_hyp_mode(void)gotoout_err;}}+#ifdef CONFIG_UBSAN+/* required by ubsan to access the handlers structures fields */
nit: capital R, grammar "handlers structures fields"
The hypervisor currently doesn't use the .data section, so this approach works
fine at the moment. But this will stop working as soon as somebody starts using
.data for other purposes. It would be nice to do this properly now rather than
fix it later as part of some unrelated series. What you'd need to do:
* add .data to arch/arm64/kvm/hyp/nvhe/hyp.lds.S; that will rename
hypervisor's .data to .hyp.data
* add .hyp.data to arch/arm64/kernel/vmlinux.lds.S
* add new entries to arch/arm64/include/asm/sections.h
* map .hyp.data here
Related, this currently relies on the fact that all pointers in .data are the
kernel VAs. That means later in this series it is safe to just copy the event
description to the buffer without any conversion. my series "Relocate absolute
hyp VAs" will convert all pointers in .hyp.* sections to the hypervisor VAs.
So once we do introduce .hyp.data, the hypervisor's ubsan.c will also have to
convert all pointers.
+ for (i = left; i < right; ++i) {
+ /* check ubsan data */
+ slot[i].type = 0;
+ }
+}
+
+void __kvm_check_ubsan_buffer(void)
+{
+ unsigned long *write_ind;
+
+ write_ind = (unsigned long *) this_cpu_ptr_nvhe_sym(kvm_ubsan_buff_wr_ind);
+ iterate_kvm_ubsan_buffer(0, *write_ind);
I think this is another remnant of George's previous implementation. The first
argument will always be zero, so I don't see the point in splitting this into
two functions any more.