Do comprehensive UFS/FFS superblock integrity checks when reading a superblock.
Historically only minimal checks were made of a superblock when it
was read in as it was assumed that fsck would have been run to
correct any errors before attempting to use the filesystem. Recently
several bug reports have been submitted reporting kernel panics
that can be triggered by deliberately corrupting filesystem superblocks,
see Bug 263979 - [meta] UFS / FFS / GEOM crash (panic) tracking
which is tracking the reported corruption bugs.
This change upgrades the checks that are performed. These additional
checks should prevent panics from a corrupted superblock. Although
it appears in only one place, the new code will apply to the kernel
modules and (through libufs) user applications that read in superblocks.
Reported by: Robert Morris and Neeraj
Reviewed by: kib
Tested by: Peter Holm
PR: 263979
Differential Revision: https://reviews.freebsd.org/D35219
(cherry picked from commit 076002f24d35962f0d21f44bfddd34ee4d7f015d)
(cherry picked from commit bc218d89200faa021def77732f3d9fde4f4dee13)
(cherry picked from commit 800a53b445e7eb113ba193b1ac98631299178529)
(cherry picked from commit 50dc4c7df4156863148e6a9609c03e852e2aeb35)
(cherry picked from commit f3f5368dfbef4514686ba2d67f01f314b275227e)
(cherry picked from commit 9e1f44d044a58fcd2caaca3f57e69cf6180db3dc)
(cherry picked from commit 5bc926af9fd1c47f74356734f731c68145e31c6f)
(cherry picked from commit 904347a00c1f9a29f3b17e6e676805036d2494f1)
(cherry picked from commit 36e08b0127f97928a2f2c062feed8df9087b2b35)
(cherry picked from commit 548045bf57c46cb2f4d43d3d7fa5d8ad37ec7f9a)
(cherry picked from commit 3e40d2cc61a00a7d69e99b0fda4040cd1df04c57)
(cherry picked from commit 184e3118c1057a97e16230baf0f0433adeeed723)
(cherry picked from commit f0be378a66a75ebf335e9388ef0d319a70064d94)
(cherry picked from commit 9dee5da7450e8530c9fec51c9a16ecd42da78e55)
(cherry picked from commit 82ee4e1c42d70345cbaa1f6dd1874ae98a004910)
(cherry picked from commit dcdba3460dd779a0180ec7769ab8cd47c932799e)
(cherry picked from commit 017367c1146a69baca6a1a0bea10b0cb02c72d85)
(cherry picked from commit 8435a9b20684ba8bcda3df31d06b4d5eac9431a7)