HomeFreeBSD

zvols: prevent overflow of minor device numbers

Description

zvols: prevent overflow of minor device numbers

currently, the linux kernel allows 2^20 minor devices per major device
number. ZFS reserves blocks of 2^4 minors per zvol: 1 for the zvol
itself, the other 15 for the first partitions of that zvol. as a result,
only 2^16 such blocks are available for use.

there are no checks in place to avoid overflowing into the major device
number when more than 2^16 zvols are allocated (with volmode=dev or
default). instead of ignoring this limit, which comes with all sorts of
weird knock-on effects, detect this situation and simply fail allocating
the zvol block device early on.

without this safeguard, the kernel will reject the attempt to create an
already existing block device, but ZFS doesn't handle this error and
gets confused about which zvol occupies which minor slot, potentially
resulting in kernel NULL derefs and other issues later on.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Closes #16006

Details

Provenance
Fabian-Gruenbichler <f.gruenbichler@proxmox.com>Authored on Mar 29 2024, 9:37 PM
Tony Hutter <hutter2@llnl.gov>Committed on Apr 22 2024, 4:23 PM
Parents
rGbb9542a2a027: Linux 6.8 compat: META (#16099)
Branches
Unknown
Tags
Unknown

Event Timeline

Tony Hutter <hutter2@llnl.gov> committed rGfa2cbd40078f: zvols: prevent overflow of minor device numbers (authored by Fabian-Gruenbichler <f.gruenbichler@proxmox.com>).Apr 22 2024, 4:23 PM