From nobody Mon Aug 01 03:29:24 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Lx3Wm6mZfz4WpM8; Mon, 1 Aug 2022 03:29:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Lx3Wm6KmCz4Cls; Mon, 1 Aug 2022 03:29:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659324564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SvPlBjCiV3vP6ei5MYI6yx6gpocmrOKH9o4UaJpJjfU=; b=cqerJnGSk+9zl3LmYMO54gZoLJjBrlp2MzLsxuyfCm65qyoSfGXwnI34Sqd6GlOuBqOxx1 3t4I8oWbxkW9TnSLh5s8NxLt8PUr93NPxail1nxI1IJVJoelf5AScl/v6pJKcSVZ1xcnjD l20CfLnvxRPfztpUgj7uUAQ1il0aeSJ8WUFnDlk3nMlGfMvkdwKzlwJ93SPTwtyZiVV3zQ 09+DudRUR8I34RXmi5wIvyD0jiDRHv46gW5B2qLRUE72QuOQsFjIrQi4D0/yeNcBqu3L84 hQny8m0EwZag2/0MDcVhUQEMAH1luPruEwHB/11C4kufgbwNvA6f+an0UZf0/w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Lx3Wm5P7vzJ8x; Mon, 1 Aug 2022 03:29:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2713TOmf044852; Mon, 1 Aug 2022 03:29:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2713TOwU044851; Mon, 1 Aug 2022 03:29:24 GMT (envelope-from git) Date: Mon, 1 Aug 2022 03:29:24 GMT Message-Id: <202208010329.2713TOwU044851@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: 184e3118c105 - main - Updates to UFS/FFS superblock integrity checks when reading a superblock. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 184e3118c1057a97e16230baf0f0433adeeed723 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659324564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SvPlBjCiV3vP6ei5MYI6yx6gpocmrOKH9o4UaJpJjfU=; b=e959cp+gNzyyzQv8UwhFL7g7ZGM8r8F22Vj4jW+zF9WuPy5Fg6UhA9qDb2Lg6KlKdEctWX w6mRaXn6hsL9ZrDn11qcrstbyO4MVHQD1T0VgzhKfvPU6sSjTHwkh0G8Rn3jwZ5CyWpQCS ADoNqn92+lhV+/7oLXcv8M4DzmCuU20p7l2I4rI9zVdglY+bsKk9bM1ePrWyIFmdlZOMCj klLUnhWj92qZz4Sc56AEtHW9PU3n9pYFQyJT8zX+t+MyyLB8ePYQKO4nsoQQlM4ui96h09 ZnSt+M0XtiCSZHvxmLs2phlGIW07sfV7iBLp1B7SsMLXCJpKNANvn2fGVMBdKw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659324564; a=rsa-sha256; cv=none; b=hWaDXKI+fWmc8qEXXEooejGA+YiEsBnYQSapgViweeTa9grS+P8QXDLiIlY+OZrMeC75E6 XrL/yfdZe5/MmfZgzlsv6O71KL6cr65juYfAYQ6grhrl7GoPUG5MUVgcEUtGq5okfJWkKY ysT1uJfx7vyDMVGZU9BI1Ty7dvdXu37krXloKC50GWnjW6AZORxrphMMDGUUXd2bc+5Sly ntFYpA8bEnvfjHTv2Vn1s/Yz7lcwp57wB5ToybaHQCsdqkb+2eKeDRBre8U3FBah9n0rqr lcIhqybUlHYfj+ogLiCVvCKC4dFAD3I3mVAGfsGHlEk/sh2F6awpgCfJ//vd8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=184e3118c1057a97e16230baf0f0433adeeed723 commit 184e3118c1057a97e16230baf0f0433adeeed723 Author: Kirk McKusick AuthorDate: 2022-08-01 03:28:04 +0000 Commit: Kirk McKusick CommitDate: 2022-08-01 03:29:08 +0000 Updates to UFS/FFS superblock integrity checks when reading a superblock. Further updates based on analysis of the way the fields are used in the various filesystem macros defined in fs.h. Eliminate several checks for non-negative values where the fields are checked for specific values. Since these specific values are non-negative, if the value is a verified positive value then it cannot be negative and such a check is redundant and unnecessary. No legitimate superblocks should fail as a result of these changes. --- sys/ufs/ffs/ffs_subr.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c index 90e7034e65a5..0bcc43fae4d4 100644 --- a/sys/ufs/ffs/ffs_subr.c +++ b/sys/ufs/ffs/ffs_subr.c @@ -355,33 +355,28 @@ validate_sblock(struct fs *fs, int flags) sectorsize = dbtob(1); prtmsg = ((flags & UFS_NOMSG) == 0); if (fs->fs_magic == FS_UFS2_MAGIC) { - if ((flags & UFS_ALTSBLK) == 0) { - CHK(fs->fs_sblockloc, !=, SBLOCK_UFS2, %#jx); + if ((flags & UFS_ALTSBLK) == 0) CHK2(fs->fs_sblockactualloc, !=, SBLOCK_UFS2, fs->fs_sblockactualloc, !=, 0, %jd); - } + CHK(fs->fs_sblockloc, !=, SBLOCK_UFS2, %#jx); CHK(fs->fs_maxsymlinklen, !=, ((UFS_NDADDR + UFS_NIADDR) * sizeof(ufs2_daddr_t)), %jd); CHK(fs->fs_nindir, !=, fs->fs_bsize / sizeof(ufs2_daddr_t), %jd); - CHK(fs->fs_inopb, <, 1, %jd); - CHK(fs->fs_inopb, !=, fs->fs_bsize / sizeof(struct ufs2_dinode), - %jd); + CHK(fs->fs_inopb, !=, + fs->fs_bsize / sizeof(struct ufs2_dinode), %jd); } else if (fs->fs_magic == FS_UFS1_MAGIC) { - if ((flags & UFS_ALTSBLK) == 0) { - CHK(fs->fs_sblockloc, >, SBLOCK_UFS1, %jd); + if ((flags & UFS_ALTSBLK) == 0) CHK(fs->fs_sblockactualloc, >, SBLOCK_UFS1, %jd); - } + CHK(fs->fs_sblockloc, <, 0, %jd); + CHK(fs->fs_sblockloc, >, SBLOCK_UFS1, %jd); CHK(fs->fs_nindir, !=, fs->fs_bsize / sizeof(ufs1_daddr_t), %jd); - CHK(fs->fs_inopb, <, 1, %jd); - CHK(fs->fs_inopb, !=, fs->fs_bsize / sizeof(struct ufs1_dinode), - %jd); + CHK(fs->fs_inopb, !=, + fs->fs_bsize / sizeof(struct ufs1_dinode), %jd); CHK(fs->fs_maxsymlinklen, !=, ((UFS_NDADDR + UFS_NIADDR) * sizeof(ufs1_daddr_t)), %jd); CHK(fs->fs_old_inodefmt, !=, FS_44INODEFMT, %jd); - CHK(fs->fs_old_cgoffset, !=, 0, %jd); - CHK(fs->fs_old_cgmask, !=, 0xffffffff, %#jx); CHK(fs->fs_old_rotdelay, !=, 0, %jd); CHK(fs->fs_old_rps, !=, 60, %jd); CHK(fs->fs_old_nspf, !=, fs->fs_fsize / sectorsize, %jd); @@ -414,8 +409,6 @@ validate_sblock(struct fs *fs, int flags) CHK(fs->fs_ipg, <, 1, %jd); CHK(fs->fs_ipg * fs->fs_ncg, >, (((int64_t)(1)) << 32) - INOPB(fs), %jd); - CHK(fs->fs_sblockloc, <, 0, %jd); - CHK(fs->fs_sblockloc, >, dbtob(fs->fs_fpg), %jd); CHK(fs->fs_sbsize, >, SBLOCKSIZE, %jd); CHK(fs->fs_maxbsize, <, fs->fs_bsize, %jd); CHK(powerof2(fs->fs_maxbsize), ==, 0, %jd); @@ -428,6 +421,9 @@ validate_sblock(struct fs *fs, int flags) CHK(fs->fs_fshift, !=, ILOG2(fs->fs_fsize), %jd); CHK(fs->fs_fragshift, !=, ILOG2(fs->fs_frag), %jd); CHK(fs->fs_fsbtodb, !=, ILOG2(fs->fs_fsize / sectorsize), %jd); + CHK(fs->fs_old_cgoffset, <, 0, %jd); + CHK2(fs->fs_old_cgoffset, >, 0, ~fs->fs_old_cgmask, <, 0, %jd); + CHK(fs->fs_old_cgoffset * (~fs->fs_old_cgmask), >, fs->fs_fpg, %jd); CHK(fs->fs_sblkno, !=, roundup( howmany(fs->fs_sblockloc + SBLOCKSIZE, fs->fs_fsize), fs->fs_frag), %jd);