openzfs / zfs

OpenZFS on Linux and FreeBSD
https://openzfs.github.io/openzfs-docs
Other
10.68k stars 1.76k forks source link

Linux: Guard proc sentinel values using kernel version. #16805

Open IvanVolosyuk opened 10 hours ago

IvanVolosyuk commented 10 hours ago

Fixes openzfs kernel module loading on 6.11+ with CONFIG_RANDSTRUCT=y

Motivation and Context

This change fixes #16620 Linux kernel after 6.1-rc1 stopped using proc sentinel records and relies on ARRAY_SIZE. ZFS still uses the sentinel values, which causes crash:

sysctl table check failed: kernel/spl/(null) No proc_handler

I bisected the kernel commit where the issue starts to occur: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d7a76ec87195ced6910b0ca10ca133bb316c90f5

Description

The fix is to guard proc sentinel values using kernel version. Ideally it should be more targeted, but I don't know how to do that and if it even possible.

How Has This Been Tested?

Types of changes

Checklist:

amotin commented 8 hours ago

I bisected the kernel commit where the issue starts to occur:

This is the commit when it stopped allow the sentinels. Instead I think you could dig deeper to find when they become optional, since that is where the KPI has changed, and I wonder if it was more documented back then. The later was just a compatibility window.

snajpa commented 8 hours ago

Kernel versions aren't reliable, stuff can be backported to older kernels (RHEL kernels are known for that), testing a kernel version within OpenZFS code to make a decision of which code to use is thus not a good idea. It always needs a specific configure test, which affects zfs_config.h, which is what you can then use in the source to disambiguate between the different variants.

(I don't speak m4 either, I always just go looking for something in the config/ dir that is the closest to what I'm trying to do and then just copy and modify it)