Calculate updated superblock check-hash before writing it into the snapshot.

This corrects a bug that prevented snapshots from being mounted due to a
superblock check-hash failure.

Reported by:  Brennan Vincent <brennan@umanwizard.com>
Tested by:    Peter Holm (pho@)
Sponsored by: Netflix
This commit is contained in:
Kirk McKusick 2018-11-25 18:01:15 +00:00
parent 6e00f3a311
commit ade67b509c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=340924
3 changed files with 7 additions and 5 deletions

View File

@ -68,6 +68,7 @@ ufs2_daddr_t ffs_blkpref_ufs1(struct inode *, ufs_lbn_t, int, ufs1_daddr_t *);
ufs2_daddr_t ffs_blkpref_ufs2(struct inode *, ufs_lbn_t, int, ufs2_daddr_t *);
void ffs_blkrelease_finish(struct ufsmount *, u_long);
u_long ffs_blkrelease_start(struct ufsmount *, struct vnode *, ino_t);
uint32_t ffs_calc_sbhash(struct fs *);
int ffs_checkfreefile(struct fs *, struct vnode *, ino_t);
void ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
void ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);

View File

@ -795,6 +795,7 @@ out1:
brelse(nbp);
} else {
loc = blkoff(fs, fs->fs_sblockloc);
copy_fs->fs_ckhash = ffs_calc_sbhash(copy_fs);
bcopy((char *)copy_fs, &nbp->b_data[loc], (u_int)fs->fs_sbsize);
bawrite(nbp);
}

View File

@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include <ufs/ffs/fs.h>
uint32_t calculate_crc32c(uint32_t, const void *, size_t);
uint32_t ffs_calc_sbhash(struct fs *);
struct malloc_type;
#define UFS_MALLOC(size, type, flags) malloc(size)
#define UFS_FREE(ptr, type) free(ptr)
@ -147,7 +148,6 @@ ffs_load_inode(struct buf *bp, struct inode *ip, struct fs *fs, ino_t ino)
static off_t sblock_try[] = SBLOCKSEARCH;
static int readsuper(void *, struct fs **, off_t, int,
int (*)(void *, off_t, void **, int));
static uint32_t calc_sbhash(struct fs *);
/*
* Read a superblock from the devfd device.
@ -276,7 +276,7 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk,
fs->fs_bsize <= MAXBSIZE &&
fs->fs_bsize >= roundup(sizeof(struct fs), DEV_BSIZE) &&
fs->fs_sbsize <= SBLOCKSIZE) {
if (fs->fs_ckhash != (ckhash = calc_sbhash(fs))) {
if (fs->fs_ckhash != (ckhash = ffs_calc_sbhash(fs))) {
#ifdef _KERNEL
res = uprintf("Superblock check-hash failed: recorded "
"check-hash 0x%x != computed check-hash 0x%x\n",
@ -339,7 +339,7 @@ ffs_sbput(void *devfd, struct fs *fs, off_t loc,
}
fs->fs_fmod = 0;
fs->fs_time = UFS_TIME;
fs->fs_ckhash = calc_sbhash(fs);
fs->fs_ckhash = ffs_calc_sbhash(fs);
if ((error = (*writefunc)(devfd, loc, fs, fs->fs_sbsize)) != 0)
return (error);
return (0);
@ -348,8 +348,8 @@ ffs_sbput(void *devfd, struct fs *fs, off_t loc,
/*
* Calculate the check-hash for a superblock.
*/
static uint32_t
calc_sbhash(struct fs *fs)
uint32_t
ffs_calc_sbhash(struct fs *fs)
{
uint32_t ckhash, save_ckhash;