From nobody Sun Jun 04 17:18:38 2023 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 4QZ3Nt2pFhz4ZN2M; Sun, 4 Jun 2023 17:18:38 +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 4QZ3Nt2Fzpz411V; Sun, 4 Jun 2023 17:18:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685899118; 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=2P7akGGa7W3lSHY47S7RacqZtvIg2tv3f2cmgq0+jg0=; b=MaDO7JTbT4789+/eG3SS+RnIEf42aN0hFlN8MBfKtB85doQg1f3MyYD4im1HSAt91Dv9mZ x8CxaGe5g3dRxHvs5uUivukBLhCQgIN5D32kT8J2T2C7OL5NtskQlUs+ayiV7ZxuG2ukwh p5jyLE5muuLXJ/edsKY89L/StiEexvHHy77lw3wIjuY4GHnjcl9TDUgmAZOORix2dAsQ0K QuXApEaVFIOaqGLDEwfutkWdqxJagzwvrKcVfAQmt4cLEQRxosU6ZLs9SwvWy3Tc2B4aQA aRp8Um+HlaU9AzmlUid1pp4JLlt6l5oCYP0bLYp7oGzlZNFRluwP+kVUg7DKKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685899118; 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=2P7akGGa7W3lSHY47S7RacqZtvIg2tv3f2cmgq0+jg0=; b=NHxc72mi1eGtl1cdzUQ1EXVX1qUqM6Jeg1N2kCOIEhSKGTtOeDH3dMN1xZmt5sub9YbGm5 hXPtcb8tb+iLy/5UtZvv5ektbCBWYJUMpBAOvirs0PEspMNDlalYX5UNzaRaRZbBxAVWuC ZsQCVCKTdf67k7tgFVTAPzp1FUR73LrcpIagSc563s1Fen6rqP3NWUIgtCgim5bf++3zkL NwU+SUlo444MVXXLVGBUkEg3pJ7TTLtxpifRf0zxcf+Zvrth6FHhrXvtyZJ3yB3B6QUCqb J/uPxvyf6LIpHdny1o2xac2yhyAC9ymR3gXfKGJunqTi4cXmf/qOPHJkzNvARw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685899118; a=rsa-sha256; cv=none; b=iav4Fk6LFt1S72S9qmaaDpgBLkB18HLg8aBP6Gld66RfWRtrRD4Xq/VcBegZUeLLPUxXpp 8bHcQ3FdShY07hqpqClGEXU3nTJM0yzecXYGV20pq/AIruL7fKJcwzvasXOSdVXp5246Ud virVphZRd44G3YeLDyWkj4slcXxemzBwjFfaf+gsumxvTwcCHyad9s9kEI6ANRULWTqVR+ UA7EctUS/leypWc/8aM36CW/SQC8UjBioXU07SAgEEzk4BywF+Lv/WQTYA+v9go91gmja4 RmeiDkNJc4EMkl0MVt5IcNayrUVBl9WgBRHzfe0X7DQzEOhRys5QN2XMCPu95Q== 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 4QZ3Nt1MsmzF1Y; Sun, 4 Jun 2023 17:18:38 +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 354HIcls010197; Sun, 4 Jun 2023 17:18:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 354HIcR4010196; Sun, 4 Jun 2023 17:18:38 GMT (envelope-from git) Date: Sun, 4 Jun 2023 17:18:38 GMT Message-Id: <202306041718.354HIcR4010196@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Chuck Silvers Subject: git: 89bd147dbf8e - stable/13 - ffs: restore backward compatibility of newfs and makefs with older binaries 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: chs X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 89bd147dbf8e30acf76838a4170025261c2f3b38 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by chs: URL: https://cgit.FreeBSD.org/src/commit/?id=89bd147dbf8e30acf76838a4170025261c2f3b38 commit 89bd147dbf8e30acf76838a4170025261c2f3b38 Author: Chuck Silvers AuthorDate: 2023-05-30 02:26:28 +0000 Commit: Chuck Silvers CommitDate: 2023-06-04 11:00:22 +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 (cherry picked from commit d464a7698de8fe18530ea65fac90dce56b860a59) --- 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 42866f9b1426..7b55c5c1f229 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),