2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00
linux/lib/raid6
Chunyan Zhang bc75552b80
raid6: riscv: Fix NULL pointer dereference caused by a missing clobber
When running the raid6 user-space test program on RISC-V QEMU, there's a
segmentation fault which seems caused by accessing a NULL pointer,
which is the pointer variable p/q in raid6_rvv*_gen/xor_syndrome_real(),
p/q should have been equal to dptr[x], but when I use GDB command to
see its value, which was 0x10 like below:

"
Program received signal SIGSEGV, Segmentation fault.
0x0000000000011062 in raid6_rvv2_xor_syndrome_real (disks=<optimized out>, start=0, stop=<optimized out>, bytes=4096, ptrs=<optimized out>) at rvv.c:386
(gdb) p p
$1 = (u8 *) 0x10 <error: Cannot access memory at address 0x10>
"

The issue was found to be related with:
1) Compile optimization
   There's no segmentation fault if compiling the raid6test program with
   the optimization flag -O0.
2) The RISC-V vector command vsetvli
   If not used t0 as the first parameter in vsetvli, there's no
   segmentation fault either.

This patch selects the 2nd solution to fix the issue.

[Palmer: The actual issue here is a missing clobber in the vsetvli code.
It's a little tricky: we've already probed for VLENB so we don't need to
look at the output register, we just need to have an X register in the
instruction as that's the form required to actually set VL.  Thus we
clobber a register, and without describing that we end up breaking
compilers.]

Fixes: 6093faaf95 ("raid6: Add RISC-V SIMD syndrome and recovery calculations")
Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20250610101234.1100660-3-zhangchunyan@iscas.ac.cn
Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
2025-06-12 12:21:48 -07:00
..
test raid6: skip avx512 checks 2025-04-30 21:53:48 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
algos.c RISC-V Patches for the 6.16 Merge Window, Part 1 2025-06-06 18:05:18 -07:00
altivec.uc lib/raid6: Build proper raid6test files on powerpc 2018-03-20 16:47:52 +11:00
avx2.c lib/raid6: Use strict priority ranking for pq gen() benchmarking 2022-01-06 08:37:03 -08:00
avx512.c raid6: skip avx512 checks 2025-04-30 21:53:48 +02:00
int.uc lib/raid6: Drop IA64 support 2023-09-11 08:13:18 +00:00
loongarch_simd.c raid6: Add LoongArch SIMD syndrome calculation 2023-09-06 22:53:55 +08:00
loongarch.h raid6: Add LoongArch SIMD syndrome calculation 2023-09-06 22:53:55 +08:00
Makefile raid6: Add RISC-V SIMD syndrome and recovery calculations 2025-06-05 14:03:07 -07:00
mktables.c raid6: guard the tables.c include of <linux/export.h> with __KERNEL__ 2023-08-15 09:40:27 -07:00
mmx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 48 2019-05-24 17:27:13 +02:00
neon.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
neon.h raid6: neon: add missing prototypes 2023-06-13 15:13:20 -07:00
neon.uc raid6: neon: add missing prototypes 2023-06-13 15:13:20 -07:00
recov_avx2.c x86: update AS_* macros to binutils >=2.23, supporting ADX and AVX2 2020-04-09 00:12:48 +09:00
recov_avx512.c raid6: skip avx512 checks 2025-04-30 21:53:48 +02:00
recov_loongarch_simd.c raid6: Add LoongArch SIMD recovery implementation 2023-09-06 22:53:55 +08:00
recov_neon_inner.c raid6: neon: add missing prototypes 2023-06-13 15:13:20 -07:00
recov_neon.c raid6: neon: add missing prototypes 2023-06-13 15:13:20 -07:00
recov_rvv.c raid6: Add RISC-V SIMD syndrome and recovery calculations 2025-06-05 14:03:07 -07:00
recov_s390xc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
recov_ssse3.c x86: remove always-defined CONFIG_AS_SSSE3 2020-04-09 00:01:59 +09:00
recov.c raid6: remove the <linux/export.h> include from recov.c 2023-08-15 09:40:27 -07:00
rvv.c raid6: riscv: Fix NULL pointer dereference caused by a missing clobber 2025-06-12 12:21:48 -07:00
rvv.h raid6: Add RISC-V SIMD syndrome and recovery calculations 2025-06-05 14:03:07 -07:00
s390vx.uc s390/vx: Convert cpu_has_vx() to cpu feature function 2025-03-04 17:18:07 +01:00
sse1.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 48 2019-05-24 17:27:13 +02:00
sse2.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 48 2019-05-24 17:27:13 +02:00
unroll.awk lib: raid6: fix awk build warnings 2019-12-09 18:55:03 +01:00
vpermxor.uc lib/raid6: Include <asm/ppc-opcode.h> for VPERMXOR 2022-03-08 15:20:21 -08:00
x86.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 48 2019-05-24 17:27:13 +02:00