aboutsummaryrefslogtreecommitdiff
path: root/lib/libufs
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2018-12-11 22:14:37 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2018-12-11 22:14:37 +0000
commit8f829a5cf0fa341a95fd4bed7091d6c44129d68f (patch)
tree2cb40f5c8c0521451556577ffdfcd8b8aeb90861 /lib/libufs
parentd3cc40300eaa672ce8f7d1782454267d3ea15dfb (diff)
downloadsrc-8f829a5cf0fa341a95fd4bed7091d6c44129d68f.tar.gz
src-8f829a5cf0fa341a95fd4bed7091d6c44129d68f.zip
Continuing efforts to provide hardening of FFS. This change adds a
check hash to the filesystem inodes. Access attempts to files associated with an inode with an invalid check hash will fail with EINVAL (Invalid argument). Access is reestablished after an fsck is run to find and validate the inodes with invalid check-hashes. This check avoids a class of filesystem panics related to corrupted inodes. The hash is done using crc32c. Note this check-hash is for the inode itself and not any of its indirect blocks. Check-hash validation may be extended to also cover indirect block pointers, but that will be a separate (and more costly) feature. Check hashes 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. Reviewed by: kib Tested by: Peter Holm Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=341836
Diffstat (limited to 'lib/libufs')
-rw-r--r--lib/libufs/inode.c7
-rw-r--r--lib/libufs/libufs.h2
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/libufs/inode.c b/lib/libufs/inode.c
index 11e263f08ad5..497ff4c854f6 100644
--- a/lib/libufs/inode.c
+++ b/lib/libufs/inode.c
@@ -90,7 +90,10 @@ gotit: switch (disk->d_ufs) {
disk->d_dp.dp2 = &((struct ufs2_dinode *)inoblock)[inum - min];
if (dp != NULL)
*dp = disk->d_dp;
- return (0);
+ if (ffs_verify_dinode_ckhash(fs, disk->d_dp.dp2) == 0)
+ return (0);
+ ERROR(disk, "check-hash failed for inode read from disk");
+ return (-1);
default:
break;
}
@@ -108,6 +111,8 @@ putinode(struct uufsd *disk)
ERROR(disk, "No inode block allocated");
return (-1);
}
+ if (disk->d_ufs == 2)
+ ffs_update_dinode_ckhash(fs, disk->d_dp.dp2);
if (bwrite(disk, fsbtodb(fs, ino_to_fsba(&disk->d_fs, disk->d_inomin)),
disk->d_inoblock, disk->d_fs.fs_bsize) <= 0)
return (-1);
diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h
index 9d1e7355c2f7..44eaed83ccbd 100644
--- a/lib/libufs/libufs.h
+++ b/lib/libufs/libufs.h
@@ -116,6 +116,8 @@ int ffs_sbget(void *, struct fs **, off_t, char *,
int (*)(void *, off_t, void **, int));
int ffs_sbput(void *, struct fs *, off_t,
int (*)(void *, off_t, void *, int));
+void ffs_update_dinode_ckhash(struct fs *, struct ufs2_dinode *);
+int ffs_verify_dinode_ckhash(struct fs *, struct ufs2_dinode *);
/*
* Request standard superblock location in ffs_sbget