From nobody Mon Oct 18 13:08:46 2021 X-Original-To: dev-commits-src-branches@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 094561812E78; Mon, 18 Oct 2021 13:08:47 +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 4HXxyk6sxkz4f6f; Mon, 18 Oct 2021 13:08:46 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C89C020F30; Mon, 18 Oct 2021 13:08:46 +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 19ID8kAV086648; Mon, 18 Oct 2021 13:08:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19ID8kGP086647; Mon, 18 Oct 2021 13:08:46 GMT (envelope-from git) Date: Mon, 18 Oct 2021 13:08:46 GMT Message-Id: <202110181308.19ID8kGP086647@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 116a988f99cd - stable/12 - geom_label: Add more validation for NTFS volume tasting List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 116a988f99cd9fcac1a34c17ec0aa81be70d5e4f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=116a988f99cd9fcac1a34c17ec0aa81be70d5e4f commit 116a988f99cd9fcac1a34c17ec0aa81be70d5e4f Author: Mark Johnston AuthorDate: 2021-10-04 21:48:44 +0000 Commit: Mark Johnston CommitDate: 2021-10-18 13:08:32 +0000 geom_label: Add more validation for NTFS volume tasting - Ensure that the computed MFT record size isn't negative or larger than maxphys before trying to read $Volume. - Guard against truncated records in volume metadata. - Ensure that the record length is large enough to contain the volume name. - Verify that the (UTF-16-encoded) volume name's length is a multiple of two. PR: 258833, 258914 Sponsored by: The FreeBSD Foundation (cherry picked from commit f0a08fa9f532a58f5d7a4814d6eb7ddd49f368da) --- sys/geom/label/g_label_ntfs.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/sys/geom/label/g_label_ntfs.c b/sys/geom/label/g_label_ntfs.c index 653524ab654c..bcf6a3a72b36 100644 --- a/sys/geom/label/g_label_ntfs.c +++ b/sys/geom/label/g_label_ntfs.c @@ -101,7 +101,8 @@ g_label_ntfs_taste(struct g_consumer *cp, char *label, size_t size) struct ntfs_filerec *fr; struct ntfs_attr *atr; off_t voloff; - char *filerecp, *ap; + size_t recoff; + char *filerecp; int8_t mftrecsz; char vnchar; int recsize, j; @@ -117,8 +118,9 @@ g_label_ntfs_taste(struct g_consumer *cp, char *label, size_t size) goto done; mftrecsz = bf->bf_mftrecsz; - recsize = (mftrecsz > 0) ? (mftrecsz * bf->bf_bps * bf->bf_spc) : (1 << -mftrecsz); - if (recsize == 0 || recsize % pp->sectorsize != 0) + recsize = (mftrecsz > 0) ? (mftrecsz * bf->bf_bps * bf->bf_spc) : + (1 << -mftrecsz); + if (recsize <= 0 || recsize > maxphys || recsize % pp->sectorsize != 0) goto done; voloff = bf->bf_mftcn * bf->bf_spc * bf->bf_bps + @@ -130,24 +132,33 @@ g_label_ntfs_taste(struct g_consumer *cp, char *label, size_t size) if (filerecp == NULL) goto done; fr = (struct ntfs_filerec *)filerecp; - if (fr->fr_hdrmagic != NTFS_FILEMAGIC) goto done; - for (ap = filerecp + fr->fr_attroff; - atr = (struct ntfs_attr *)ap, atr->a_type != -1; - ap += atr->reclen) { + for (recoff = fr->fr_attroff; + recoff <= recsize - 2 * sizeof(uint32_t); + recoff += atr->reclen) { + atr = (struct ntfs_attr *)(filerecp + recoff); + if (atr->a_type == -1) + break; + if (atr->reclen < sizeof(*atr)) + break; + if (recsize - recoff < atr->reclen) + break; if (atr->a_type == NTFS_A_VOLUMENAME) { - if(atr->a_datalen >= size *2){ - label[0] = 0; - goto done; - } + if (atr->a_dataoff > atr->reclen || + atr->a_datalen > atr->reclen - atr->a_dataoff) + break; + /* - *UNICODE to ASCII. + * UNICODE to ASCII. * Should we need to use iconv(9)? */ + if (atr->a_datalen >= size * 2 || + atr->a_datalen % 2 != 0) + break; for (j = 0; j < atr->a_datalen; j++) { - vnchar = *(ap + atr->a_dataoff + j); + vnchar = ((char *)atr)[atr->a_dataoff + j]; if (j & 1) { if (vnchar) { label[0] = 0;