From 217fabc9d496dceef8914ed0a77ac70e4073a53c Mon Sep 17 00:00:00 2001 From: Tony Hutter Date: Sun, 12 Nov 2023 16:26:07 -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. Reviewed-by: Brian Behlendorf Tested-by: Thomas Lamprecht Co-authored-by: Thomas Lamprecht Signed-off-by: Tony Hutter Issue #15145 Closes #15510 --- include/os/linux/spl/sys/kmem_cache.h | 2 +- include/sys/vdev_raidz_impl.h | 4 ++-- module/icp/Makefile.in | 2 ++ module/zfs/Makefile.in | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/os/linux/spl/sys/kmem_cache.h b/include/os/linux/spl/sys/kmem_cache.h index 48006ec5d27e..c4aeebb81558 100644 --- a/include/os/linux/spl/sys/kmem_cache.h +++ b/include/os/linux/spl/sys/kmem_cache.h @@ -111,7 +111,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 908723da0c2a..b5c9a4f09ace 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/icp/Makefile.in b/module/icp/Makefile.in index ce84999ad1cf..0c5cb7c1fe12 100644 --- a/module/icp/Makefile.in +++ b/module/icp/Makefile.in @@ -69,6 +69,8 @@ OBJECT_FILES_NON_STANDARD_aesni-gcm-x86_64.o := y OBJECT_FILES_NON_STANDARD_sha256_impl.o := y OBJECT_FILES_NON_STANDARD_sha512_impl.o := y +UBSAN_SANITIZE_modhash.o := n + ICP_DIRS = \ api \ core \ diff --git a/module/zfs/Makefile.in b/module/zfs/Makefile.in index 0e04d7ef0cd2..d9b86890b5f5 100644 --- a/module/zfs/Makefile.in +++ b/module/zfs/Makefile.in @@ -159,4 +159,8 @@ CFLAGS_REMOVE_vdev_raidz_math_aarch64_neon.o += -mgeneral-regs-only CFLAGS_REMOVE_vdev_raidz_math_aarch64_neonx2.o += -mgeneral-regs-only endif +UBSAN_SANITIZE_zap_leaf.o := n +UBSAN_SANITIZE_zap_micro.o := n +UBSAN_SANITIZE_sa.o := n + include $(mfdir)/../os/linux/zfs/Makefile