From nobody Tue May 30 02:28:02 2023 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 4QVbsb27Qjz4Xc0Z; Tue, 30 May 2023 02:28:03 +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 4QVbsb1cZJz44n4; Tue, 30 May 2023 02:28:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685413683; 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=QogiZZqEcStGAp+JXDYEXapQ16+zWekV/Y8qZazqMBA=; b=EDW1Xw9NSjKQKy5vMYaM5fXqLKNtPfMiLvhyLG1oYaoNaWEDLrpJohtD3Y8/zpRBv78wra Aif/yM8efiLzsHNjC5n/oYkZZ4f7rTkKNryHR9ucPO7ZWhuKYZ79oKXVoeykW0y5X9ThE0 gCJASm0YBUbrP5DSSvAGr9pbKXZxSJ3Cs3UV30PWLHpk6PO58t9m37YtX6pa4xKGWoP0d6 RPZjVLWNKZax+wbD0SraflGU2j34HQhByrBTt9/lQxVSoSUpkvUAoTRz4z81SesF4ZPgRp fKphkJ+w2P6UIdb0H5zHq/17uZKSTKx26bSs4jtDfSTQd1q/d0Bvmj/Ozk27sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685413683; 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=QogiZZqEcStGAp+JXDYEXapQ16+zWekV/Y8qZazqMBA=; b=v2QvXjtsM/goEvBkbgEWwHY5zwVxatx2lGNsqUW1yrX6RgBcIYUGODR4pMhvDP2N3nuTYk JP8X739WheciansaSvzXuy92/+U1aKxyhK8uQnDdiMh0r9mkwdTJ1EQ+Xim4kdg6BkmKjd ZxfZ58Q8YaNzckC5hwkIIloi/Iw6qY379iLH3H9q7x/umXs/19righ7GacBbt7wluqSd0y Hpo4tZxsnPEjcxL9EIAibfpiDtpdgIjpmGhYyI9NKE+eFA+CpElP0I+Wex1mu6zXSpm0jW /LXaoX3SZpJl+jqz+ydHV+AsTJi165Ymu/pX2DKw/YniPCDTTuwXDNBKn5kvrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685413683; a=rsa-sha256; cv=none; b=W46EFFbDVgkQP4GOzbfojjA3rqQfnO8Pt8sPapU2ySJ+LrUMUKZv0W9HkvHv0fJZn9SH3W Lae24XiuEE8qefK+WbYfQnCVyQneKk/QxwsSpj6TprTnruV4ErS1Hf9botuqMdRN3ag8tl 18NHWivLgXFosgcx4pVctunZugKgY+DVOUSaet0hr0ipLQVf9B7Nf+KnkHa2z4crBRBDBT CrE3QflZbbDyKunPbAe5pX66BNbfUSuKfnmwvls5dU/NIT+tA7cNxYVID/IDvjYwNPQwj4 tCveHgdCMApvHT0EXAIiGW8m1jWsBXS8WSghOZz+yRF4siCNSRV17G9C1uQ6GQ== 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 4QVbsb0ghQzbvq; Tue, 30 May 2023 02:28:03 +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 34U2S2kH062129; Tue, 30 May 2023 02:28:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34U2S2QI062128; Tue, 30 May 2023 02:28:02 GMT (envelope-from git) Date: Tue, 30 May 2023 02:28:02 GMT Message-Id: <202305300228.34U2S2QI062128@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Chuck Silvers Subject: git: d464a7698de8 - main - ffs: restore backward compatibility of newfs and makefs with older binaries 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: chs X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d464a7698de8fe18530ea65fac90dce56b860a59 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by chs: URL: https://cgit.FreeBSD.org/src/commit/?id=d464a7698de8fe18530ea65fac90dce56b860a59 commit d464a7698de8fe18530ea65fac90dce56b860a59 Author: Chuck Silvers AuthorDate: 2023-05-30 02:26:28 +0000 Commit: Chuck Silvers CommitDate: 2023-05-30 02:26:28 +0000 ffs: restore backward compatibility of newfs and makefs with older binaries The previous change to CGSIZE had the unintended side-effect of allowing newfs and makefs to create file systems that would fail validation when examined by older commands and kernels, by allowing newfs/makefs to pack slightly more blocks into a CG than those older binaries think is valid. Fix this by having newfs/makefs artificially restrict the number of blocks in a CG to the slightly smaller value that those older binaries will accept. The validation code will continue to accept the slightly larger value that the current newfs/makefs (before this change) could create. Fixes: 0a6e34e950cd5889122a199c34519b67569be9cc Reviewed by: mckusick MFC after: 3 days Sponsored by: Netflix --- sbin/newfs/mkfs.c | 26 +++++++++++++++++++++++--- usr.sbin/makefs/ffs/mkfs.c | 26 +++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index adc64f47cac6..28b02d250e17 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -76,6 +76,23 @@ __FBSDID("$FreeBSD$"); #define UMASK 0755 #define POWEROF2(num) (((num) & ((num) - 1)) == 0) +/* + * The definition of "struct cg" used to contain an extra field at the end + * to represent the variable-length data that followed the fixed structure. + * This had the effect of artificially limiting the number of blocks that + * newfs would put in a CG, since newfs thought that the fixed-size header + * was bigger than it really was. When we started validating that the CG + * header data actually fit into one fs block, the placeholder field caused + * a problem because it caused struct cg to be a different size depending on + * platform. The placeholder field was later removed, but this caused a + * backward compatibility problem with older binaries that still thought + * struct cg was larger, and a new file system could fail validation if + * viewed by the older binaries. To avoid this compatibility problem, we + * now artificially reduce the amount of space that the variable-length data + * can use such that new file systems will pass validation by older binaries. + */ +#define CGSIZEFUDGE 8 + static struct csum *fscs; #define sblock disk.d_fs #define acg disk.d_cg @@ -369,7 +386,8 @@ retry: sblock.fs_fpg = minfpg; sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode), INOPB(&sblock)); - if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize) + if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize - + CGSIZEFUDGE) break; density -= sblock.fs_fsize; } @@ -388,9 +406,11 @@ retry: if (Oflag > 1 || (Oflag == 1 && sblock.fs_ipg <= 0x7fff)) { if (sblock.fs_size / sblock.fs_fpg < MINCYLGRPS) break; - if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize) + if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize - + CGSIZEFUDGE) continue; - if (CGSIZE(&sblock) == (unsigned long)sblock.fs_bsize) + if (CGSIZE(&sblock) == (unsigned long)sblock.fs_bsize - + CGSIZEFUDGE) break; } sblock.fs_fpg -= sblock.fs_frag; diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c index d48dc65aac68..4e88dae7aae8 100644 --- a/usr.sbin/makefs/ffs/mkfs.c +++ b/usr.sbin/makefs/ffs/mkfs.c @@ -80,6 +80,23 @@ static int count_digits(int); #define UMASK 0755 #define POWEROF2(num) (((num) & ((num) - 1)) == 0) +/* + * The definition of "struct cg" used to contain an extra field at the end + * to represent the variable-length data that followed the fixed structure. + * This had the effect of artificially limiting the number of blocks that + * newfs would put in a CG, since newfs thought that the fixed-size header + * was bigger than it really was. When we started validating that the CG + * header data actually fit into one fs block, the placeholder field caused + * a problem because it caused struct cg to be a different size depending on + * platform. The placeholder field was later removed, but this caused a + * backward compatibility problem with older binaries that still thought + * struct cg was larger, and a new file system could fail validation if + * viewed by the older binaries. To avoid this compatibility problem, we + * now artificially reduce the amount of space that the variable-length data + * can use such that new file systems will pass validation by older binaries. + */ +#define CGSIZEFUDGE 8 + static union { struct fs fs; char pad[SBLOCKSIZE]; @@ -347,7 +364,8 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) sblock.fs_fpg = minfpg; sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode), INOPB(&sblock)); - if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize) + if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize - + CGSIZEFUDGE) break; density -= sblock.fs_fsize; } @@ -366,9 +384,11 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) INOPB(&sblock)); if (sblock.fs_size / sblock.fs_fpg < 1) break; - if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize) + if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize - + CGSIZEFUDGE) continue; - if (CGSIZE(&sblock) == (unsigned long)sblock.fs_bsize) + if (CGSIZE(&sblock) == (unsigned long)sblock.fs_bsize - + CGSIZEFUDGE) break; sblock.fs_fpg -= sblock.fs_frag; sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),