freebsd-dev/sys
Kirk McKusick 75e3597abb Continuing efforts to provide hardening of FFS, this change adds a
check hash to cylinder groups. If a check hash fails when a cylinder
group is read, no further allocations are attempted in that cylinder
group until it has been fixed by fsck. This avoids a class of
filesystem panics related to corrupted cylinder group maps. The
hash is done using crc32c.

Check hases are added only to UFS2 and not to UFS1 as UFS1 is primarily
used in embedded systems with small memories and low-powered processors
which need as light-weight a filesystem as possible.

Specifics of the changes:

sys/sys/buf.h:
    Add BX_FSPRIV to reserve a set of eight b_xflags that may be used
    by individual filesystems for their own purpose. Their specific
    definitions are found in the header files for each filesystem
    that uses them. Also add fields to struct buf as noted below.

sys/kern/vfs_bio.c:
    It is only necessary to compute a check hash for a cylinder
    group when it is actually read from disk. When calling bread,
    you do not know whether the buffer was found in the cache or
    read. So a new flag (GB_CKHASH) and a pointer to a function to
    perform the hash has been added to breadn_flags to say that the
    function should be called to calculate a hash if the data has
    been read. The check hash is placed in b_ckhash and the B_CKHASH
    flag is set to indicate that a read was done and a check hash
    calculated. Though a rather elaborate mechanism, it should
    also work for check hashing other metadata in the future. A
    kernel internal API change was to change breada into a static
    fucntion and add flags and a function pointer to a check-hash
    function.

sys/ufs/ffs/fs.h:
    Add flags for types of check hashes; stored in a new word in the
    superblock. Define corresponding BX_ flags for the different types
    of check hashes. Add a check hash word in the cylinder group.

sys/ufs/ffs/ffs_alloc.c:
    In ffs_getcg do the dance with breadn_flags to get a check hash and
    if one is provided, check it.

sys/ufs/ffs/ffs_vfsops.c:
    Copy across the BX_FFSTYPES flags in background writes.
    Update the check hash when writing out buffers that need them.

sys/ufs/ffs/ffs_snapshot.c:
    Recompute check hash when updating snapshot cylinder groups.

sys/libkern/crc32.c:
lib/libufs/Makefile:
lib/libufs/libufs.h:
lib/libufs/cgroup.c:
    Include libkern/crc32.c in libufs and use it to compute check
    hashes when updating cylinder groups.

Four utilities are affected:

sbin/newfs/mkfs.c:
    Add the check hashes when building the cylinder groups.

sbin/fsck_ffs/fsck.h:
sbin/fsck_ffs/fsutil.c:
    Verify and update check hashes when checking and writing cylinder groups.

sbin/fsck_ffs/pass5.c:
    Offer to add check hashes to existing filesystems.
    Precompute check hashes when rebuilding cylinder group
    (although this will be done when it is written in fsutil.c
    it is necessary to do it early before comparing with the old
    cylinder group)

sbin/dumpfs/dumpfs.c
    Print out the new check hash flag(s)

sbin/fsdb/Makefile:
    Needs to add libufs now used by pass5.c imported from fsck_ffs.

Reviewed by: kib
Tested by: Peter Holm (pho)
2017-09-22 12:45:15 +00:00
..
amd64 Do not do torn writes to active LDTs. 2017-09-19 17:57:04 +00:00
arm Define CPU_XSCALE_CORE3 when relevant. 2017-09-19 23:41:55 +00:00
arm64 Fix indentation for r323068 2017-09-19 20:40:05 +00:00
boot libefi: define EISA PNP constants 2017-09-22 07:44:36 +00:00
bsm Commit the 64-bit inode project. 2017-05-23 09:29:05 +00:00
cam cam iosched: Bettar account IOPS for smoother performance 2017-09-22 02:36:36 +00:00
cddl MFV r323917: 8648 Fix range locking in ZIL commit codepath 2017-09-22 08:27:27 +00:00
compat Add support for 32-bit compatibility IOCTLs in the LinuxKPI. 2017-09-22 08:12:08 +00:00
conf Miscellaneous fixes and improvements to MMCCAM stack 2017-09-15 19:47:44 +00:00
contrib Plug memory leak in case when nvlist allocation succeeds, but nvpair 2017-09-21 10:28:22 +00:00
crypto aesni(4): Fix another trivial typo (aensi -> aesni) 2017-09-20 18:31:36 +00:00
ddb Rename mkdumpheader() and group EKCD functions in kern_shutdown.c. 2017-08-18 04:04:09 +00:00
dev Clean up error messages related to device discovery 2017-09-22 12:07:03 +00:00
fs Only handle _PC_MAX_CANON, _PC_MAX_INPUT, and _PC_VDISABLE for TTY devices. 2017-09-21 23:05:32 +00:00
gdb
geom gmirror: treat ENXIO as disk disconnect, not media error 2017-09-15 13:57:08 +00:00
gnu Update DTS files from Linux 4.12 2017-07-09 13:53:32 +00:00
i386 Fix indentation for r323068 2017-09-19 20:40:05 +00:00
isa Use better hard-coded defaults for the cursor shape, and remove nearby 2017-08-19 19:33:16 +00:00
kern Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
kgssapi
libkern Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
mips Add MIPS32/64 Rev2 CP0 intctl register definitions. 2017-09-15 19:56:21 +00:00
modules Give icee(4) a detach() method so it can be used as a module. Add a 2017-09-17 22:58:13 +00:00
net bridge: Set module version 2017-09-21 14:14:01 +00:00
net80211 net80211: fix a typo (premable -> preamble). 2017-08-27 22:13:03 +00:00
netgraph Unprotected modification of ng_iface(4) private data leads to kernel panic. 2017-09-21 20:16:10 +00:00
netinet Add missing locking. Found by Coverity while scanning the usrsctp 2017-09-22 06:33:01 +00:00
netinet6 Fix a locking issue found by Coverity scanning the usrsctp library. 2017-09-09 20:51:54 +00:00
netipsec Fix possible double releasing for SA reference. 2017-09-01 11:51:07 +00:00
netpfil Use in_localip() function instead of unlocked access to addresses hash 2017-09-20 22:35:28 +00:00
netsmb
nfs Improve FHA locality control for NFS read/write requests. 2017-07-31 15:23:19 +00:00
nfsclient Add an NFSv4.1 mount option for "use one openowner". 2017-04-13 21:54:19 +00:00
nfsserver
nlm Commit the 64-bit inode project. 2017-05-23 09:29:05 +00:00
ofed Remove unsafe access to the LinuxKPI file structure from ibcore. 2017-09-09 06:34:20 +00:00
opencrypto Support AEAD requests with non-GCM algorithms. 2017-09-22 00:34:46 +00:00
powerpc Fix indentation for r323068 2017-09-19 20:40:05 +00:00
riscv Sync with amd64/arm/arm64/i386/mips pmap change r288256: 2017-09-20 04:19:49 +00:00
rpc Listening sockets improvements. 2017-06-08 21:30:34 +00:00
security Sprinkle __read_frequently on few obvious places. 2017-09-06 20:33:33 +00:00
sparc64 Fix indentation for r323068 2017-09-19 20:40:05 +00:00
sys Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
teken Fix syscons escape sequence for setting the local cursor type. This sequence 2017-08-18 15:40:40 +00:00
tests style(9): sort headers 2017-05-09 05:08:47 +00:00
tools make.conf: Add the possibility to use another DTC 2017-06-17 23:34:53 +00:00
ufs Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
vm For unlinked files, do not msync(2) or sync on the vnode deactivation. 2017-09-19 16:46:37 +00:00
x86 x86: Decode AMD "Extended Feature Extensions ID EBX" bits 2017-09-20 18:30:37 +00:00
xdr * limit size of buffers to RPC_MAXDATASIZE 2017-06-01 06:12:25 +00:00
xen
Makefile Remove glimpse make target added in r181432 2017-05-22 15:53:30 +00:00