freebsd-dev/sys/libkern
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
..
arm
arm64 arm64: add ".arch armv8-a+crc" to allow use of crc instructions 2017-06-08 20:06:09 +00:00
x86 x86/crc32_sse42.c: quiet unused function warning 2017-08-11 17:05:31 +00:00
arc4random.c Replace the RC4 algorithm for generating in-kernel secure random 2017-04-16 09:11:02 +00:00
ashldi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
ashrdi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
asprintf.c
bcd.c Use time_t for intermediate values to avoid overflow in clock_ts_to_ct 2017-01-24 18:05:29 +00:00
bcmp.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
bsearch.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
cmpdi2.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
crc32.c Continuing efforts to provide hardening of FFS, this change adds a 2017-09-22 12:45:15 +00:00
divdi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
explicit_bzero.c
ffs.c
ffsl.c
ffsll.c
fls.c
flsl.c
flsll.c
fnmatch.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
iconv_converter_if.m
iconv_ucs.c libkern: Remove obsolete 'register' keyword 2017-01-12 17:02:29 +00:00
iconv_xlat16.c sys: Replace zero with NULL for pointers. 2017-02-22 02:35:59 +00:00
iconv_xlat.c
iconv.c
inet_aton.c
inet_ntoa.c Remove inet_ntoa() from the kernel 2017-02-16 20:50:01 +00:00
inet_ntop.c
inet_pton.c
jenkins_hash.c
lshrdi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
mcount.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
memcchr.c
memchr.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
memcmp.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
memmem.c libkern: Remove obsolete 'register' keyword 2017-01-12 17:02:29 +00:00
memmove.c
memset.c
moddi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
murmur3_32.c
qdivrem.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
qsort_r.c
qsort.c Sync qsort.c with userland r318515. 2017-05-19 06:37:16 +00:00
quad.h Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
random.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
scanc.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strcasecmp.c
strcat.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strchr.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strcmp.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strcpy.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strcspn.c
strdup.c
strlcat.c
strlcpy.c
strlen.c
strncat.c
strncmp.c
strncpy.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strndup.c
strnlen.c
strrchr.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strsep.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strspn.c
strstr.c strstr.c was inadvertently blasted with a copy of isa_nmi.c. Revert 2017-03-01 02:07:51 +00:00
strtol.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strtoq.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strtoul.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strtouq.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
strvalid.c
timingsafe_bcmp.c
ucmpdi2.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
udivdi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
umoddi3.c Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
zlib.c Remove register keyword from sys/ and ANSIfy prototypes 2017-05-17 00:34:34 +00:00