From nobody Thu Mar 23 12:50:29 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 4Pj4vB3C8lz41Jtn; Thu, 23 Mar 2023 12:50:30 +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 4Pj4v952DPz4MrP; Thu, 23 Mar 2023 12:50:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679575829; 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=/pA7MnLEvyEYMq5hmt9lIDVivzNPpTxB1l2H12Rg8Bs=; b=ns1yptR8K/qzSjnTZCS+6rXWAZ8jggVC8s8tARX/YD8vc776klZTLkDc8576c2JhOGttSa rGnMttt98ZzGxnmPz8UKoybAF9BR3cg3VJZGLJiGnH6JoIhTlnBQajDeYgNVQ2LU7MgJG0 WQTxZNOVlgZd1o4bbAuYvSdvOzOIXBBkCzSd8EMoJnG73useu5XKG2naacK4TGsv05eu3k fa++3ME59VLvRQqFDv6EyMCdYb1cFxUEcSisvgglTCkaQLQXNFHMjgjI6AumT1GDQAPwfW v/8m40IOowy6IXuru/PqiTSxtNf+K9Au7dZvWL+oSx58lCVK8imv3cak/WqXkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679575829; 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=/pA7MnLEvyEYMq5hmt9lIDVivzNPpTxB1l2H12Rg8Bs=; b=bZKQLiH/o6hMHHhwbkYBlkB5IXSmMfUDrjC3vOVzzBnqB6iXkq9GOYqvi8a3qkjPmoP8d0 lTDlnx0iLHdX46QXEGuZymnEydwUqHhnfju6QjeIViJr2Hjx3FcNRgW2K3Qh5FLP0GeiqL 9LSDNq8K+JU0fllf/99zqOH46LNN0xS0nHneeUvRfLPL5BeDw1X7ftFXEDYNMGS952uRJT /aVS7NuEVNIWjuiUx8VM4s5+3CTmMYDe8fez2NKl5/k7TvCzplrHdUbDRx3kX0+TDDDaVL N51zc/5M9XTLQueXU6PXWlKwLoW3Ev8Q/ZT7+y9xO0kTUcGKtYCV5vTrht3/IQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679575829; a=rsa-sha256; cv=none; b=Bjmc60uSMplE9mBNaAL6AYC7LreBzoz/XMzjwT3ToN/xZ0iGFiZaUgTOorEcra73A/s2c5 oqBpDVosS5urx9sUUmTkt3XdTA+LdwuMUegtc7gBuzvlhJrA7CMh9SpZaYdHOwG5zWg5VZ HcHxUqXWCjr8/QXNaiY7icU9/Y7taNk0jnK0RQaKnoYng99AI4MHEiVSrHUnVksBKNoaRa UkY+9D+maHyPNlfCTTfoqmD5BAiQfHW6jLvfzGsiwoiJDfSfw1KTXDDCm3Uv8kR877B8uC gQ1rtCpfZkTfrP6b2y0T2x/EU+NM3HeHh4NCln3sxEX8ahmXHbi6K/+vumsnig== 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 4Pj4v946vDzbjY; Thu, 23 Mar 2023 12:50:29 +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 32NCoTWd022935; Thu, 23 Mar 2023 12:50:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32NCoTEE022934; Thu, 23 Mar 2023 12:50:29 GMT (envelope-from git) Date: Thu, 23 Mar 2023 12:50:29 GMT Message-Id: <202303231250.32NCoTEE022934@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: dc3d0ff61575 - stable/12 - etdump: exit on error if section header or entry offset is OOB 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: dc3d0ff61575870614ba3691a0cbbbf8f6ff2065 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=dc3d0ff61575870614ba3691a0cbbbf8f6ff2065 commit dc3d0ff61575870614ba3691a0cbbbf8f6ff2065 Author: Ed Maste AuthorDate: 2022-05-03 20:13:37 +0000 Commit: Ed Maste CommitDate: 2023-03-23 12:49:43 +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 aedd53a9f6d1..38220c821439 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; }