From 310afb0d199ccf0be946d47f0a8ae6694f60e590 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Sun, 12 Nov 2023 11:30:28 +0100 Subject: [PATCH] backport work-around for UBSAN-errors with variable arrays Link: https://github.com/openzfs/zfs/pull/15510 Signed-off-by: Thomas Lamprecht --- ...und-UBSAN-errors-for-variable-arrays.patch | 75 +++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 76 insertions(+) create mode 100644 debian/patches/0013-Workaround-UBSAN-errors-for-variable-arrays.patch diff --git a/debian/patches/0013-Workaround-UBSAN-errors-for-variable-arrays.patch b/debian/patches/0013-Workaround-UBSAN-errors-for-variable-arrays.patch new file mode 100644 index 0000000..0281531 --- /dev/null +++ b/debian/patches/0013-Workaround-UBSAN-errors-for-variable-arrays.patch @@ -0,0 +1,75 @@ +From 28be24aefc13b11e4c96e172cf2685994e03150d Mon Sep 17 00:00:00 2001 +From: Tony Hutter +Date: Thu, 9 Nov 2023 16:43:35 -0800 +Subject: [PATCH] Workaround UBSAN errors for variable arrays + +This gets around UBSAN errors when using arrays at the end of +structs. It converts some zero-length arrays to variable length +arrays and disables UBSAN checking on certain modules. + +It is based off of the patch from #15460. + +Addresses: #15145 +Signed-off-by: Tony Hutter +Co-authored-by: Tony Hutter +Co-authored-by: Thomas Lamprecht +Signed-off-by: Thomas Lamprecht +--- + include/os/linux/spl/sys/kmem_cache.h | 2 +- + include/sys/vdev_raidz_impl.h | 4 ++-- + module/Kbuild.in | 4 ++++ + 3 files changed, 7 insertions(+), 3 deletions(-) + +diff --git a/include/os/linux/spl/sys/kmem_cache.h b/include/os/linux/spl/sys/kmem_cache.h +index 20eeadc46..82d50b603 100644 +--- a/include/os/linux/spl/sys/kmem_cache.h ++++ b/include/os/linux/spl/sys/kmem_cache.h +@@ -108,7 +108,7 @@ typedef struct spl_kmem_magazine { + uint32_t skm_refill; /* Batch refill size */ + struct spl_kmem_cache *skm_cache; /* Owned by cache */ + unsigned int skm_cpu; /* Owned by cpu */ +- void *skm_objs[0]; /* Object pointers */ ++ void *skm_objs[]; /* Object pointers */ + } spl_kmem_magazine_t; + + typedef struct spl_kmem_obj { +diff --git a/include/sys/vdev_raidz_impl.h b/include/sys/vdev_raidz_impl.h +index c1037fa12..73c26dff1 100644 +--- a/include/sys/vdev_raidz_impl.h ++++ b/include/sys/vdev_raidz_impl.h +@@ -130,7 +130,7 @@ typedef struct raidz_row { + uint64_t rr_offset; /* Logical offset for *_io_verify() */ + uint64_t rr_size; /* Physical size for *_io_verify() */ + #endif +- raidz_col_t rr_col[0]; /* Flexible array of I/O columns */ ++ raidz_col_t rr_col[]; /* Flexible array of I/O columns */ + } raidz_row_t; + + typedef struct raidz_map { +@@ -139,7 +139,7 @@ typedef struct raidz_map { + int rm_nskip; /* RAIDZ sectors skipped for padding */ + int rm_skipstart; /* Column index of padding start */ + const raidz_impl_ops_t *rm_ops; /* RAIDZ math operations */ +- raidz_row_t *rm_row[0]; /* flexible array of rows */ ++ raidz_row_t *rm_row[]; /* flexible array of rows */ + } raidz_map_t; + + +diff --git a/module/Kbuild.in b/module/Kbuild.in +index c13217159..b9c284a24 100644 +--- a/module/Kbuild.in ++++ b/module/Kbuild.in +@@ -488,6 +488,10 @@ zfs-$(CONFIG_ARM64) += $(addprefix zfs/,$(ZFS_OBJS_ARM64)) + zfs-$(CONFIG_PPC) += $(addprefix zfs/,$(ZFS_OBJS_PPC_PPC64)) + zfs-$(CONFIG_PPC64) += $(addprefix zfs/,$(ZFS_OBJS_PPC_PPC64)) + ++UBSAN_SANITIZE_zap_leaf.o := n ++UBSAN_SANITIZE_zap_micro.o := n ++UBSAN_SANITIZE_sa.o := n ++ + # Suppress incorrect warnings from versions of objtool which are not + # aware of x86 EVEX prefix instructions used for AVX512. + OBJECT_FILES_NON_STANDARD_vdev_raidz_math_avx512bw.o := y +-- +2.39.2 + diff --git a/debian/patches/series b/debian/patches/series index 6a5ab10..eba3f86 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -10,3 +10,4 @@ 0010-zvol-Remove-broken-blk-mq-optimization.patch 0011-Revert-zvol-Temporally-disable-blk-mq.patch 0012-Fix-nfs_truncate_shares-without-etc-exports.d.patch +0013-Workaround-UBSAN-errors-for-variable-arrays.patch