From nobody Mon May 30 18:05:33 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 D277B1B4596D; Mon, 30 May 2022 18:05:40 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LBjxv2zm9z3C8n; Mon, 30 May 2022 18:05:39 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-io1-xd31.google.com with SMTP id 2so11981958iou.5; Mon, 30 May 2022 11:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hJsWO0QFF8fxnZHEhVte+ibpAFfGcTjtDfY6VdbGYys=; b=g9XKx2LzMpO8p7S20BzBTvb7OpC14Ri7gN1H8wSffUr0/0kURFc0p7P44eTT1Ldons ojzZF1KqYJRLNAGpoRzSfeN6wsb+Qf/M/cE/69ONbF8FXbvm9XPWaFgUuU6lpIuoHwqX 1sC2UfV0G6YLgxO62A4rno7Hf7DIXFMOjL6QmuA0BBgZ0PXA0ZzD5MlfDPspQqh3+aJ4 WjVDv5ZEqUAYIpewynsyilygTumTw23mUSqJkPrAkIcjWqg/7kPE94ov2Y7PH8U1zxMi 3QU7GDs63Vqk00fBA3IfXzVVOdMEqoOi0BPdqffgwM0ESXGhhY5+p5lpBLUvTJ79qNfM gJMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=hJsWO0QFF8fxnZHEhVte+ibpAFfGcTjtDfY6VdbGYys=; b=MEFKLF6uwANnV59kfSO++JFwJaAOkews8S4lEETMBUF2KAaU0BJu4C5iRU55TYV9oV D4revXXnuwnO9bJ/F2aIdlgZTsm1QSxbfdY+kq3d6YH1dsbToGsmk+nlmOBUH/VJA2lg qyBgW4IKMFKaJ29VOgARVeeU+/ca+3+fAzATNROS1ulqJboMB3RgdUegmFjuXj+Z5aWD gZCrQBoZQVDFgD3h0JHtw+z6PIDvpxts1ZXi3MEzQlnWJ/lT7xDonET6zJIRuMsOczBD fbvYGgQlFUpWFpiCerJl9Of2D+HhtLoX3PI1oKBuIzCDREqdrcj2ErKS3SzR0SmoLxmt Nm+g== X-Gm-Message-State: AOAM532aLm3fEhocza75nZA/UW188nAtMZmLZhdvaQLuOhs9KLdGoUiE vhsfm4474a+Fv1hMFxbi7bnvChqCW3w= X-Google-Smtp-Source: ABdhPJzVJFPx3VUMHFqbtsNhm+IBxi8UYZTY/9HCeJFrJKABYfefrXazK6cY1qfyjlDaA9Ml6YmtNg== X-Received: by 2002:a02:90ce:0:b0:32e:e2ce:b17c with SMTP id c14-20020a0290ce000000b0032ee2ceb17cmr17687165jag.268.1653933936776; Mon, 30 May 2022 11:05:36 -0700 (PDT) Received: from nuc (198-84-189-58.cpe.teksavvy.com. [198.84.189.58]) by smtp.gmail.com with ESMTPSA id q8-20020a056e020c2800b002cde6e352f8sm3899652ilg.66.2022.05.30.11.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 11:05:35 -0700 (PDT) Date: Mon, 30 May 2022 14:05:33 -0400 From: Mark Johnston To: Kirk McKusick Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 076002f24d35 - main - Do comprehensive UFS/FFS superblock integrity checks when reading a superblock. Message-ID: References: <202205271922.24RJMOJ2039923@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202205271922.24RJMOJ2039923@gitrepo.freebsd.org> X-Rspamd-Queue-Id: 4LBjxv2zm9z3C8n X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=g9XKx2Lz; dmarc=none; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::d31 as permitted sender) smtp.mailfrom=markjdb@gmail.com X-Spamd-Result: default: False [-2.60 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; MID_RHS_NOT_FQDN(0.50)[]; DMARC_NA(0.00)[freebsd.org]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; NEURAL_HAM_SHORT(-0.90)[-0.898]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::d31:from]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; RCVD_TLS_ALL(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-ThisMailContainsUnwantedMimeParts: N On Fri, May 27, 2022 at 07:22:24PM +0000, Kirk McKusick wrote: > The branch main has been updated by mckusick: > > URL: https://cgit.FreeBSD.org/src/commit/?id=076002f24d35962f0d21f44bfddd34ee4d7f015d > > commit 076002f24d35962f0d21f44bfddd34ee4d7f015d > Author: Kirk McKusick > AuthorDate: 2022-05-27 19:21:11 +0000 > Commit: Kirk McKusick > CommitDate: 2022-05-27 19:22:07 +0000 > > Do comprehensive UFS/FFS superblock integrity checks when reading a superblock. > > Historically only minimal checks were made of a superblock when it > was read in as it was assumed that fsck would have been run to > correct any errors before attempting to use the filesystem. Recently > several bug reports have been submitted reporting kernel panics > that can be triggered by deliberately corrupting filesystem superblocks, > see Bug 263979 - [meta] UFS / FFS / GEOM crash (panic) tracking > which is tracking the reported corruption bugs. > > This change upgrades the checks that are performed. These additional > checks should prevent panics from a corrupted superblock. Although > it appears in only one place, the new code will apply to the kernel > modules and (through libufs) user applications that read in superblocks. > > Reported by: Robert Morris and Neeraj > Reviewed by: kib > Tested by: Peter Holm > PR: 263979 > MFC after: 1 month > Differential Revision: https://reviews.freebsd.org/D35219 > --- > sys/ufs/ffs/ffs_subr.c | 163 +++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 146 insertions(+), 17 deletions(-) > > diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c > index 01e9f45e1205..28c2fee1cb37 100644 > --- a/sys/ufs/ffs/ffs_subr.c > +++ b/sys/ufs/ffs/ffs_subr.c > [...] > +static int > +validate_sblock(struct fs *fs, int isaltsblk) > +{ > + int i, sectorsize; > + u_int64_t maxfilesize, minfpg, sizepb; > + > + sectorsize = dbtob(1); > + if (fs->fs_magic == FS_UFS2_MAGIC) { > + if ((!isaltsblk && (fs->fs_sblockloc != SBLOCK_UFS2 || > + fs->fs_sblockactualloc != SBLOCK_UFS2)) || > + fs->fs_maxsymlinklen != ((UFS_NDADDR + UFS_NIADDR) * > + sizeof(ufs2_daddr_t)) || > + fs->fs_nindir != fs->fs_bsize / sizeof(ufs2_daddr_t) || > + fs->fs_inopb != fs->fs_bsize / sizeof(struct ufs2_dinode)) > + return (ENOENT); > + } else if (fs->fs_magic == FS_UFS1_MAGIC) { > + if ((!isaltsblk && (fs->fs_sblockloc > SBLOCK_UFS1 || > + fs->fs_sblockactualloc != SBLOCK_UFS1)) || Hi Kirk, The tests of fs_sblockactualloc fail on older filesystems or those created by makefs(8), causing mount to fail. That field was added relatively recently, so I suspect a value of zero should also be permitted?