From nobody Thu Jul 21 05:52:41 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 4LpMD94BfCz4WkYX; Thu, 21 Jul 2022 05:52:41 +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 4LpMD93hGMz3M6j; Thu, 21 Jul 2022 05:52:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658382761; 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=DzNQEioqC5lV/UmTugaOy2GWCAChTkh+9YRFD47ynNM=; b=OivlrI+VbTmKPllxB5mPV6uCNwHdefbclGYfz8vl074F1cScBdJXQxALndMRwqJT57yQGp sbHrlFwnDsu1PAeE9ZLM2a27puyCHhTN+Gd0uZmOXfVRRiC3zulh6q3OAxM9+SA+CHLwux Dv5wNAOxS0nlMEWbZ15EguKrqqtEl35JRJAWQRW74QdPcrXJmivWhhD4Tcz1ZwDGRCYkFV +nVdWswApceUl41AqU7D+K6jyk7w34QZzsSwMpndquHpztJSv6WSRU9iOQkw+hMC6S4wDg IqJICl6m+Y00R4jBPZFvapdWP9ZImmLQGT371Vz+2bcNAzKiOCSJ4ffbCJ26vQ== 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 4LpMD92l2rz1QBN; Thu, 21 Jul 2022 05:52:41 +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 26L5qfPZ065931; Thu, 21 Jul 2022 05:52:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26L5qfan065930; Thu, 21 Jul 2022 05:52:41 GMT (envelope-from git) Date: Thu, 21 Jul 2022 05:52:41 GMT Message-Id: <202207210552.26L5qfan065930@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: f030f1102c62 - main - Delete UFS2 backup superblock recovery info when building a UFS1 filesystem. 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: f030f1102c62d3de498cf2b5f0ce8d3582182923 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658382761; 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=DzNQEioqC5lV/UmTugaOy2GWCAChTkh+9YRFD47ynNM=; b=gk/p/VJizn5YLm7bfDVCxJzIqQrfmul4xBeeSCMKwYFA4k0gjJwHvCmze11urAFt5T1Eka urQaQN3Ralg0erejuq5XiEJZVRz69mXUhDDpgRlRWk7MXbF2QarcY1Tp0bgE87/lmfZp4Z NQ5ZSCC1CqElnRqUifq4Ysh30686chvTgHMOMFWyA6u78z+P3/FEu80OqMw9qceaxkgBcZ MCmHLaz7KH5NzAcBkLSNr2Zzh4hE9bjhripAM8sdEK0FNrrcXpUNA5T8Rf6CuiR8rkwrDi jRwJ5GVwYVGjwnODRSZmgav3QoHiJmMyMhVDJjwsC5XRrYqpBMst4cmTylLVAQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658382761; a=rsa-sha256; cv=none; b=Zw7/wQswcZfjLWAkVQxi3FQhcwCZAWqBLNeI2FBmZ0fc9ZojpXksO3bIXX6DmdQisiBv6x 74hqhRxH10Z0mumv1x89kt/GwRIaRPBBfQxvGf4scPXZkTof2jOFBu09vcxh54lNr1DyUq U4UrO0phKqihCobvwCJbzUxp2XftEo4iER0O3Ec8tPkWl1QtwPgTRlWTU5VxTOiUN0nmg5 IkIsozEOK88sJxu0RBaEwhd7bP+34tAyOOCLugVpUzItBchEna4q2ozKZ4ncN+kl2oWQY/ SaYO4FFoUb/07fDr6gRWzQGLAEHUotgnHc10kjFmlkcbJHV3eYcLiqnXox7gBQ== 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=f030f1102c62d3de498cf2b5f0ce8d3582182923 commit f030f1102c62d3de498cf2b5f0ce8d3582182923 Author: Kirk McKusick AuthorDate: 2022-07-21 05:45:18 +0000 Commit: Kirk McKusick CommitDate: 2022-07-21 05:52:10 +0000 Delete UFS2 backup superblock recovery info when building a UFS1 filesystem. Only the UFS2 filesystem has support for storing information needed to find alternate superblocks. If that information is inadvertently left in place when building a UFS1 filesystem, fsck_ffs may stumble across it and attempt to use it to recover the UFS1 filesystem which can only end poorly. --- sbin/newfs/mkfs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index a6c4ee60c2d5..48091d7882d0 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -636,23 +636,26 @@ restart: * Read the last sector of the boot block, replace the last * 20 bytes with the recovery information, then write it back. * The recovery information only works for UFS2 filesystems. + * For UFS1, zero out the area to ensure that an old UFS2 + * recovery block is not accidentally found. */ - if (sblock.fs_magic == FS_UFS2_MAGIC) { - if ((fsrbuf = malloc(realsectorsize)) == NULL || bread(&disk, - part_ofs + (SBLOCK_UFS2 - realsectorsize) / disk.d_bsize, - fsrbuf, realsectorsize) == -1) - err(1, "can't read recovery area: %s", disk.d_error); - fsr = - (struct fsrecovery *)&fsrbuf[realsectorsize - sizeof *fsr]; + if ((fsrbuf = malloc(realsectorsize)) == NULL || bread(&disk, + part_ofs + (SBLOCK_UFS2 - realsectorsize) / disk.d_bsize, + fsrbuf, realsectorsize) == -1) + err(1, "can't read recovery area: %s", disk.d_error); + fsr = (struct fsrecovery *)&fsrbuf[realsectorsize - sizeof *fsr]; + if (sblock.fs_magic != FS_UFS2_MAGIC) { + memset(fsr, 0, sizeof *fsr); + } else { fsr->fsr_magic = sblock.fs_magic; fsr->fsr_fpg = sblock.fs_fpg; fsr->fsr_fsbtodb = sblock.fs_fsbtodb; fsr->fsr_sblkno = sblock.fs_sblkno; fsr->fsr_ncg = sblock.fs_ncg; - wtfs((SBLOCK_UFS2 - realsectorsize) / disk.d_bsize, - realsectorsize, fsrbuf); - free(fsrbuf); } + wtfs((SBLOCK_UFS2 - realsectorsize) / disk.d_bsize, + realsectorsize, fsrbuf); + free(fsrbuf); /* * Update information about this partition in pack * label, to that it may be updated on disk.