From nobody Tue Jan 23 16:45:30 2024 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 4TKCd70cdFz57gNY; Tue, 23 Jan 2024 16:45:31 +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 4TKCd705C3z4vbH; Tue, 23 Jan 2024 16:45:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706028331; 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=CdZqraYeLLjzio4RUkRn2HMhdfUTR1/3yqZXtoPoKDw=; b=BRQebV1hASERdB4JxscuqQNoDtN+hU/WGxK+toSoLpacvDUA+kMRzK6z9rlbZpNg5UcSt9 kV7F0jx/mW5WeauIuk4mwrIY4lMITjJQZkogKZ0gj7NnTQCRcXE4gcEklXs1d87/CZic3O nq7tlRphrAFLdQdqZFBHAnfqZeI0NSv6zhA7JUrB6KJPW1DRDudPCdOvMg7VShcp07ipk0 lm/CFTJgh94kIXNN686opI/AfLCr6OW8uEd9rGV3Qu6o9rcaVbZXlkPsARZ3fdytW8nUmv jnH3OYENY5uet5MEFy2OvpsLGDeHZumpzk8rLddJM1KzhST6slLhlCu1qhJZrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706028331; 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=CdZqraYeLLjzio4RUkRn2HMhdfUTR1/3yqZXtoPoKDw=; b=F3X5FRF0v5Wyean8ifUoaMWjhNP/23KcL9vvzyFR9jFZa40Z0CHjZHRSlZF36N9wxwzq1D FiM7GNUZwByIPzRZu1OUVsvc5ACRAMfHw4cFQJhWR3jMO4lV2EEAaSwIHbqDaquPAz2cAO FhpwuuZvJs/vqKm99nTWiNJK7w+S6lQLzjFfN4W72sFIMBTloFlykYl8QMdtxqdqrM+4ha XptSdokrUr7d7DoZTp8FhL4TAlvHh5E/D/5Z9TG9ON93ffdv8b5d12zhBdA0r9Vo2X8K09 jU4rjIZZkWglhUKctkP4ZHs5xRlKhP20IkS4+D5UKVbvxYSmYDRJCix1/CFxDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706028331; a=rsa-sha256; cv=none; b=meA+uteF/kde9t7SyJxpIxq5XE5PiWxJ4wToSFEdk3wP+Q26Hg8q3PTMFZ1wFx9u3XAZds SRfzXyFdDj0dLAdVaK+WLKX2itPKEdoG8CjkM0Xe0ZYwLkv8p+gpHl7GE+RrcpsYQaIMDj xx7ngOUpiIlVxBspXKNGHJQGzbZPNqSzL9pqrvB5gFBv4mdTWa9keo8W8NNyECWqy4e/GG Mjd7YxBpbm2gtvDACZG/7GrC/k0pHQUATwx8Hs9fv2+ffRtIxiHcJNBdWv6fu4plrw1S++ GlYAMxisNriwdxDPXqBLajyJ7zKhPQadCtHbeXKZ2t2pXw7xKbJzpnnQSmCPeQ== 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 4TKCd66DVXzddJ; Tue, 23 Jan 2024 16:45:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40NGjU6G074248; Tue, 23 Jan 2024 16:45:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NGjUps074245; Tue, 23 Jan 2024 16:45:30 GMT (envelope-from git) Date: Tue, 23 Jan 2024 16:45:30 GMT Message-Id: <202401231645.40NGjUps074245@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: cfa2c78aee85 - main - bhyve: Avoid underflows when handling remote commands 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cfa2c78aee859bfc6549951bb6a36085fdd374e8 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cfa2c78aee859bfc6549951bb6a36085fdd374e8 commit cfa2c78aee859bfc6549951bb6a36085fdd374e8 Author: Mark Johnston AuthorDate: 2024-01-23 16:40:40 +0000 Commit: Mark Johnston CommitDate: 2024-01-23 16:40:40 +0000 bhyve: Avoid underflows when handling remote commands Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D43480 --- usr.sbin/bhyve/gdb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 2d49469c2e11..f1aabbde43fd 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -1052,6 +1052,8 @@ gdb_read_mem(const uint8_t *data, size_t len) bool started; int error; + assert(len >= 1); + /* Skip 'm' */ data += 1; len -= 1; @@ -1163,6 +1165,8 @@ gdb_write_mem(const uint8_t *data, size_t len) size_t resid, todo, bytes; int error; + assert(len >= 1); + /* Skip 'M' */ data += 1; len -= 1; @@ -1557,7 +1561,7 @@ gdb_query(const uint8_t *data, size_t len) data += strlen("qThreadExtraInfo"); len -= strlen("qThreadExtraInfo"); - if (*data != ',') { + if (len == 0 || *data != ',') { send_error(EINVAL); return; } @@ -1608,7 +1612,7 @@ handle_command(const uint8_t *data, size_t len) case 'H': { int tid; - if (data[1] != 'g' && data[1] != 'c') { + if (len < 2 || (data[1] != 'g' && data[1] != 'c')) { send_error(EINVAL); break; }