From nobody Wed Jul 06 21:45:56 2022 X-Original-To: dev-commits-src-all@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 049E11D140D6; Wed, 6 Jul 2022 21:45:57 +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 4LdY502vCRz4ZwK; Wed, 6 Jul 2022 21:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657143956; 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=4tnLRCKxf8gqXNO4w6LUevvO134Yb6hRvv30XrAyyCI=; b=hpr0dEKDg9rdeT/mStM6vIl+mqeQ4Sh/mktZ568WDBzqCavBaltXKMtN+2QFXCXazXHKqv S5Qd9nTTzLIM8KoNj8FOuFEzowsaf/JLFJ0o3HWn6FJx2oYjaWOwH4eWLsbVtdJfH9ufOx OQqrzFOAutitzAUIv6smLoXEzUG9QuskJ5hQUX2wRP/WspKuDvRSp7wAe3xmFRt1+xhqhR iHLiJqb8aqw+2BD00CvfRAzOs9PP8GaMfu7OZuJLWRYs9dCd2Ib1VWhRR6TWzhZyKZlR5S S6Pduetz4LvG0QCmsSCMOcmDS7CRUVYBuq4NMdtNPR3/hZdSa3jxSJT9eRutSA== 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 44645227CF; Wed, 6 Jul 2022 21:45:56 +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 266LjuCJ064262; Wed, 6 Jul 2022 21:45:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 266Lju3w064261; Wed, 6 Jul 2022 21:45:56 GMT (envelope-from git) Date: Wed, 6 Jul 2022 21:45:56 GMT Message-Id: <202207062145.266Lju3w064261@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: f3f5368dfbef - main - Bug fix to UFS/FFS superblock integrity checks when reading a superblock. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: f3f5368dfbef4514686ba2d67f01f314b275227e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657143956; 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=4tnLRCKxf8gqXNO4w6LUevvO134Yb6hRvv30XrAyyCI=; b=rbziC8Vc7AVijCFRT/Jd6CS9RdTtbpxG+7t3RtjYlrPGiIpiaZi/+MG0QVnu9U1I/R6zqm 1Y8TTta7UaloPD1CUSyDz8XgrWoGU6oufxw/4hODQvtTdfo3fuyDrupTOc9rOVZa/6UO9n RmUwUMFtv5wGKeKw7qxgjXDN+YAU3Zj/88T1A6JlgRKs9S2Pp0Dz1CAHJjIdjFLOYARhqt WtSgEmLsUwNEid6J5IjEf2W6Yh5JG+c+HIedAJI8PBb8pVgSQpXQai+38ySisx7yWW0MC8 F3ykzVrMeYMHhQ/8JCT87Ymkob2NAUeXMn/IRUgsHfrQ931NYFawtephl4CEdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657143956; a=rsa-sha256; cv=none; b=VjZLGDRkPsfPs42CUNBK2LdBFjR42CCMJfqXKZ9IpdvHtIFcO3GXRmeqo+/W/CQNwnCqYN /ZN4HjD7LKNIm6Al7lzCkLdwEbv/AxUK4PS5Xr28OUU3iIfEaPPeT7/2+Dk1+NQMP8BvCe H+WKHFbhL81L/Odqjg4BmGK1+oCMaClhkpKZ9u7PapLU1sC5wH6z842bQJ4bSTdwljXTmU AZ6fiGCGtfhHdpKzMAZFszGYiUGcW0Yj6SxmRMQ829TUmsejWsO3mQ9DUND+yNv4dycb6x mFaLqf+suFSneRGrpv91llSisK/CYv6RwhggP/IfRqbG4uhYHojTbJH0Ilzu1w== 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=f3f5368dfbef4514686ba2d67f01f314b275227e commit f3f5368dfbef4514686ba2d67f01f314b275227e Author: Kirk McKusick AuthorDate: 2022-07-06 20:28:07 +0000 Commit: Kirk McKusick CommitDate: 2022-07-06 21:45:29 +0000 Bug fix to UFS/FFS superblock integrity checks when reading a superblock. The tests for number of cylinder groups (fs_ncg), inodes per cylinder group (fs_ipg), and the size and layout of the cylinder group summary information (fs_csaddr and fs_cssize) were overly restrictive and would exclude some valid filesystems. These updates avoid precluding valid fiesystems while still detecting rogue values that can crash or hang the kernel. Reported by: Chuck Silvers Tested by: Peter Holm MFC after: 1 month (with 076002f24d35) Differential Revision: https://reviews.freebsd.org/D35219 --- sys/ufs/ffs/ffs_subr.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c index f4c854172fb3..438745f8eb49 100644 --- a/sys/ufs/ffs/ffs_subr.c +++ b/sys/ufs/ffs/ffs_subr.c @@ -330,8 +330,8 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk, static int validate_sblock(struct fs *fs, int isaltsblk) { - int i, sectorsize; - u_int64_t maxfilesize, minfpg, sizepb; + u_long i, sectorsize, cgnum; + u_int64_t maxfilesize, sizepb; sectorsize = dbtob(1); if (fs->fs_magic == FS_UFS2_MAGIC) { @@ -409,7 +409,6 @@ validate_sblock(struct fs *fs, int isaltsblk) CHK(fs->fs_iblkno, !=, fs->fs_cblkno + fs->fs_frag, %jd); CHK(fs->fs_dblkno, !=, fs->fs_iblkno + fs->fs_ipg / INOPF(fs), %jd); CHK(fs->fs_cgsize, >, fs->fs_bsize, %jd); - CHK(fs->fs_csaddr, !=, cgdmin(fs, 0), %jd); CHK(fs->fs_cssize, !=, fragroundup(fs, fs->fs_ncg * sizeof(struct csum)), %jd); CHK(fs->fs_dsize, !=, fs->fs_size - fs->fs_sblkno - @@ -429,24 +428,24 @@ validate_sblock(struct fs *fs, int isaltsblk) * makes it hard to tightly bound them. So we can only check * that they are within a broader possible range. * - * Calculate minfpg, the minimum number of fragments that can be - * in a cylinder group. The value 12289 is calculated in newfs(8) - * when creating the smallest block size UFS version 1 filesystem - * (4096 block size) with no fragments (4096 fragment size). That - * number may be depressed even further for very small filesystems - * since newfs(8) strives to have at least four cylinder groups. + * The size cannot always be accurately determined, but ensure + * that it is consistent with the number of cylinder groups (fs_ncg) + * and the number of fragments per cylinder group (fs_fpg). Ensure + * that the summary information size is correct and that it starts + * and ends in the data area of the same cylinder group. */ - minfpg = MIN(12289, fs->fs_size / 4); CHK(fs->fs_ncg, <, 1, %jd); - CHK(fs->fs_ncg, >, (fs->fs_size / minfpg) + 1, %jd); - CHK(fs->fs_fpg, <, minfpg, %jd); - CHK(fs->fs_fpg, >, fs->fs_size, %jd); - CHK(fs->fs_ipg * fs->fs_ncg, >, (((int64_t)(1)) << 32) - INOPB(fs), - %jd); - CHK(fs->fs_ipg, >, fs->fs_fpg, %jd); CHK(fs->fs_size, <, 8 * fs->fs_frag, %jd); CHK(fs->fs_size, <=, (fs->fs_ncg - 1) * fs->fs_fpg, %jd); CHK(fs->fs_size, >, fs->fs_ncg * fs->fs_fpg, %jd); + CHK(fs->fs_cssize, !=, + fragroundup(fs, fs->fs_ncg * sizeof(struct csum)), %jd); + cgnum = dtog(fs, fs->fs_csaddr); + CHK(fs->fs_csaddr, <, cgdmin(fs, cgnum), %jd); + CHK(dtog(fs, fs->fs_csaddr + howmany(fs->fs_cssize, fs->fs_fsize)), >, + cgnum, %jd); + CHK(fs->fs_ipg * fs->fs_ncg, >, (((int64_t)(1)) << 32) - INOPB(fs), + %jd); /* * With file system clustering it is possible to allocate * many contiguous blocks. The kernel variable maxphys defines @@ -466,9 +465,8 @@ validate_sblock(struct fs *fs, int isaltsblk) * those (mostly 32-bit machines) can (very slowly) handle I/O * requests that exceed maxphys. */ - CHK(fs->fs_maxcontig, <, 1, %jd); - CHK(fs->fs_maxcontig, >, MAX(256, maxphys / fs->fs_bsize), %jd); CHK(fs->fs_maxcontig, <, 0, %jd); + CHK(fs->fs_maxcontig, >, MAX(256, maxphys / fs->fs_bsize), %jd); CHK2(fs->fs_maxcontig, ==, 0, fs->fs_contigsumsize, !=, 0, %jd); CHK2(fs->fs_maxcontig, >, 1, fs->fs_contigsumsize, !=, MIN(fs->fs_maxcontig, FS_MAXCONTIG), %jd);