From nobody Thu Jan 26 20:27:15 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 4P2sh34Jzmz3btQt; Thu, 26 Jan 2023 20:27:15 +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 4P2sh33ZTxz3R3t; Thu, 26 Jan 2023 20:27:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674764835; 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=SHQ84Tf2sj8WxsvTjKheO6ilGIzHDzJUtpzZQXb+hxs=; b=xRNc25J8w03JRYYyLea0v9STjYTRkWaOCU0qD5W5zvFsnuQaE3RJRkIJi3mu2UvseSzhv+ az19TkFjw2W8Q2P/eJ7L9guUMdPujdC5W8G1Onq9L58No0Xh7EGUKB7UvJdFUDt+SRNZAz ki+32gi+Mga2rBeHJ8Vl7aubuvrsHbWVKHjdUMpxsKxV5ncc4nqlw5i0gLN8L8elUrkJZu 1qCU4ue3qSxjCN0GyX9UXN6hzB0R9Qw3RnmqvxZuDOvEXRI3nKqAS0JGB6MtSaXsTQrSnT hnwq5XacHowoAfll46BymjuNMKEcboHuQRv3fq5WIjemAaFD17vsT26DD4/fxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674764835; 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=SHQ84Tf2sj8WxsvTjKheO6ilGIzHDzJUtpzZQXb+hxs=; b=jKXHqqizUux3fI0tAsJkzoKQQOFiAnH+VvMyU1qbrzNhGZaX+wX9VRzPO7X7OGIzkMVv25 kHOnKAws0WwhT2IdPxG+8wATjFP/UOlNxj8hqt3iXU4EtGxcmg00amsCbAx7Dl175wJkyt MzEwG35hK6PaW6k19uIfHqypHQhZlycHY/zJkNzY1Vvie3H4OBwwyEYZRQj8HTwmgNYnjw Zpg6+QqoGYF5TcJyJXjkXNU+AeKwe6WpCROlk/c3nir/3zSLc363ioous4k8lyS5s6SjnB RbDmWnzB4b2JMxitlDXB6q2uqiKwzZJGCwn5jEFeJouYKhFLZIoGcdlJYJqo4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674764835; a=rsa-sha256; cv=none; b=sbNU8eaHhmmJ9OawaGIbWkJa/Bv7ajgcB/oBT5fIfIWnmZh2TI4Kg7ljlIOvt9GhrlzeEX LvemF1yKIYny2VX6OYLioM9RwfsrHJaMV8Wjc1Pu/7C7ZF336vMhs+31I6t+WALj4WCsSZ 4qSwZYB7yvzIzzxo0rurKSSChZCfS8TZGUmxpaqcZ7FgpFNDD4Z5XV9ikzx/kykjdRehtH dsCnHgHR/uHG09C28iruZd6zllBEotoLoWlDjDMh/MDgfwNxBsQ3fWyKHikFW/WNPdZcht slEyEniyx2NqQfBgeXilDIFCu3H2fHLAMuzH1s3W56SKkvet6uEZ0vUQAgmCJA== 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 4P2sh32cvDzjXT; Thu, 26 Jan 2023 20:27:15 +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 30QKRFWv064922; Thu, 26 Jan 2023 20:27:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QKRFQi064921; Thu, 26 Jan 2023 20:27:15 GMT (envelope-from git) Date: Thu, 26 Jan 2023 20:27:15 GMT Message-Id: <202301262027.30QKRFQi064921@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: eb8d8798a0eb - stable/13 - bhyve: Avoid unlikely truncation of the blockif ident strings. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: eb8d8798a0eb49e58fb8f38ef33c3eabec9e7071 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=eb8d8798a0eb49e58fb8f38ef33c3eabec9e7071 commit eb8d8798a0eb49e58fb8f38ef33c3eabec9e7071 Author: John Baldwin AuthorDate: 2022-11-29 01:09:15 +0000 Commit: John Baldwin CommitDate: 2023-01-26 20:23:58 +0000 bhyve: Avoid unlikely truncation of the blockif ident strings. The ident string for NVMe and VirtIO block deivces do not contain the bus, and the various fields can potentially use up to three characters when printed as unsigned values (full range of uint8_t) even if not likely in practice. Reviewed by: corvink, chuck Differential Revision: https://reviews.freebsd.org/D37488 (cherry picked from commit 5d805962ca9347bbf62750452c4c980decb94793) --- usr.sbin/bhyve/pci_ahci.c | 4 ++-- usr.sbin/bhyve/pci_nvme.c | 4 ++-- usr.sbin/bhyve/pci_virtio_block.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bhyve/pci_ahci.c b/usr.sbin/bhyve/pci_ahci.c index 4571f4caeffb..09b996476774 100644 --- a/usr.sbin/bhyve/pci_ahci.c +++ b/usr.sbin/bhyve/pci_ahci.c @@ -2422,7 +2422,7 @@ pci_ahci_hd_legacy_config(nvlist_t *nvl, const char *opts) static int pci_ahci_init(struct vmctx *ctx __unused, struct pci_devinst *pi, nvlist_t *nvl) { - char bident[sizeof("XX:XX:XX")]; + char bident[sizeof("XXX:XXX:XXX")]; char node_name[sizeof("XX")]; struct blockif_ctxt *bctxt; struct pci_ahci_softc *sc; @@ -2469,7 +2469,7 @@ pci_ahci_init(struct vmctx *ctx __unused, struct pci_devinst *pi, nvlist_t *nvl) * Attempt to open the backing image. Use the PCI slot/func * and the port number for the identifier string. */ - snprintf(bident, sizeof(bident), "%d:%d:%d", pi->pi_slot, + snprintf(bident, sizeof(bident), "%u:%u:%u", pi->pi_slot, pi->pi_func, p); bctxt = blockif_open(port_nvl, bident); diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index 571a6a9fda62..edbac73c7ed5 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -3152,7 +3152,7 @@ pci_nvme_read(struct vmctx *ctx __unused, int vcpu __unused, static int pci_nvme_parse_config(struct pci_nvme_softc *sc, nvlist_t *nvl) { - char bident[sizeof("XX:X:X")]; + char bident[sizeof("XXX:XXX")]; const char *value; uint32_t sectsz; @@ -3226,7 +3226,7 @@ pci_nvme_parse_config(struct pci_nvme_softc *sc, nvlist_t *nvl) return (-1); } } else { - snprintf(bident, sizeof(bident), "%d:%d", + snprintf(bident, sizeof(bident), "%u:%u", sc->nsc_pi->pi_slot, sc->nsc_pi->pi_func); sc->nvstore.ctx = blockif_open(nvl, bident); if (sc->nvstore.ctx == NULL) { diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 2b2e6a412a5a..06d2a9671c0b 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -453,7 +453,7 @@ static int pci_vtblk_init(struct vmctx *ctx __unused, struct pci_devinst *pi, nvlist_t *nvl) { - char bident[sizeof("XX:X:X")]; + char bident[sizeof("XXX:XXX")]; struct blockif_ctxt *bctxt; const char *path, *serial; MD5_CTX mdctx; @@ -465,7 +465,7 @@ pci_vtblk_init(struct vmctx *ctx __unused, struct pci_devinst *pi, /* * The supplied backing file has to exist */ - snprintf(bident, sizeof(bident), "%d:%d", pi->pi_slot, pi->pi_func); + snprintf(bident, sizeof(bident), "%u:%u", pi->pi_slot, pi->pi_func); bctxt = blockif_open(nvl, bident); if (bctxt == NULL) { perror("Could not open backing file");