From nobody Thu Mar 23 12:53:16 2023 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 4Pj4yP1dZQz41JjL; Thu, 23 Mar 2023 12:53:17 +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 4Pj4yP0MQvz4Ppf; Thu, 23 Mar 2023 12:53:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679575997; 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=8aQWZtwOeMeYgVVAVXFsgJy+ftMgG1THaVsf0U9F0QE=; b=Tt0EGoToLIqcIAJqBL5qZcwVaEZg0DOTAsIT5WLt5cEeQC4OjzHzkhMnnGo4dOQrhEU8EO n/UH6Yzka5dERbx0UyaHeHVu/GI5HwaWMqHyeDFBL1frIyNdPiS91l8F/TkxfQcjZBZ3lp oV+MJISeMLBGhCCeuMCFE5h87NqHFmEfUY+0RpgFrqqh08n/N8YUA1sLR6WirgQMnEpRCf PffUBiVlArKYvphC4s6j5FlvdLtV8kzMIRjefvkZQLEk8sKKxVSTpkqXNyFeDhUoP2cwko vcuTiZGqYVEnebfcFPrPdKrThLROjSfOlABBA8RXq5HclrG7lVyYXJwLJpFV0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679575997; 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=8aQWZtwOeMeYgVVAVXFsgJy+ftMgG1THaVsf0U9F0QE=; b=mkZBbGDLqSYp0oNYOR0TAdhlyad3xLIEmXh2mvak1aAFd9LQr/HMt1fsmLXSYojYKuXsgC xnI9/9IXbDDQ7spO3ifMsv28PYqfWWnAq3LcQl/GZ10QSjMEXAZJ2NA522d44NXK8mwaSu IV9K11VA4FpbiP6Koml7EqcJJ/zt1gKeybhsjWOktfb5P8Jf7DJMr/WysKOSU1ICimeZGQ rv9hxnT+szTGYFOafU3lu4Z0bAYq9mxLN042vh9fSSkq85p2XNcBXU9cSKnIxMVtsPbBxv PQOyfFwoP4LneBM7H8Eqru9hMVpwaTHGM3XZyOIpna/8iA/aEch7XmSQh4zgGw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679575997; a=rsa-sha256; cv=none; b=U4hBWQOXJcxUg7PeNwBrl0sTOHgSKrbwXq4dm86wBLvzoRkF4M1nVEa0DYTUHNt0g4uPEj cFvjlz71fCOkFZS7gG2tAkmlAEx68i5msO/b5Fsnv7IzvW5hdGwDmYuMUhR7x4DiqthWTT kY0qfbN9JrUnhxU69XmZJC/y1HnBDgogrgh3gCE8TpFuw/WzbWup1pLwuwAHbgITrACsQ1 Vh3Co7rj5p7gCOBW5/lY0vHd5BgjK+cy/bZclLCEYU/QZbEsqFFNhtJAGVw7JM6+7GXp5g BinzQgEdXQAawBurTiK7sj9KyB1a/oRIugjTF9KE7OjAgHqGxPKYzeeU1RLzeQ== 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 4Pj4yN6CM5zcfb; Thu, 23 Mar 2023 12:53:16 +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 32NCrGUO029588; Thu, 23 Mar 2023 12:53:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32NCrGNR029587; Thu, 23 Mar 2023 12:53:16 GMT (envelope-from git) Date: Thu, 23 Mar 2023 12:53:16 GMT Message-Id: <202303231253.32NCrGNR029587@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 3976ad45bb06 - stable/13 - etdump: exit on error if section header or entry offset is OOB 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3976ad45bb0646dc2f0a98c138239f1eb84ac0e7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=3976ad45bb0646dc2f0a98c138239f1eb84ac0e7 commit 3976ad45bb0646dc2f0a98c138239f1eb84ac0e7 Author: Ed Maste AuthorDate: 2022-05-03 20:13:37 +0000 Commit: Ed Maste CommitDate: 2023-03-23 12:53:04 +0000 etdump: exit on error if section header or entry offset is OOB PR: 263663 Reported by: Robert Morris Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35868 (cherry picked from commit ddf77ec392717e7eaf278c0f201b561afac97b87) --- usr.bin/etdump/etdump.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/usr.bin/etdump/etdump.c b/usr.bin/etdump/etdump.c index e536aa5e51cb..b234fc9d7ff8 100644 --- a/usr.bin/etdump/etdump.c +++ b/usr.bin/etdump/etdump.c @@ -116,8 +116,8 @@ boot_catalog_valid(char *entry) } static int -dump_section(char *buffer, size_t offset, FILE *outfile, const char *filename, - struct outputter *outputter) +dump_section(char *buffer, size_t bufsize, size_t offset, FILE *outfile, + const char *filename, struct outputter *outputter) { boot_catalog_section_header *sh; u_char platform_id; @@ -125,6 +125,8 @@ dump_section(char *buffer, size_t offset, FILE *outfile, const char *filename, size_t entry_offset; boot_catalog_section_entry *entry; + if (offset + sizeof(boot_catalog_section_header) > bufsize) + errx(1, "%s: section header out of bounds", filename); sh = (boot_catalog_section_header *)&buffer[offset]; if (outputter->output_section != NULL) { outputter->output_section(outfile, filename, sh); @@ -135,6 +137,10 @@ dump_section(char *buffer, size_t offset, FILE *outfile, const char *filename, if (outputter->output_entry != NULL) { for (i = 1; i <= (int)sh->num_section_entries[0]; i++) { entry_offset = offset + i * ET_BOOT_ENTRY_SIZE; + if (entry_offset + sizeof(boot_catalog_section_entry) > + bufsize) + errx(1, "%s: section entry out of bounds", + filename); entry = (boot_catalog_section_entry *)&buffer[entry_offset]; outputter->output_entry(outfile, filename, entry, @@ -195,8 +201,8 @@ dump_eltorito(FILE *iso, const char *filename, FILE *outfile, (uint8_t)entry[0] != ET_SECTION_HEADER_LAST) break; - entry_count = dump_section(buffer, offset, outfile, filename, - outputter); + entry_count = dump_section(buffer, sizeof(buffer), offset, + outfile, filename, outputter); offset += entry_count * ET_BOOT_ENTRY_SIZE; }