From nobody Tue Nov 29 01:10:58 2022 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 4NLkmg10s3z4jSmy; Tue, 29 Nov 2022 01:10:59 +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 4NLkmf2sb4z42vj; Tue, 29 Nov 2022 01:10:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669684258; 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=OyKM1acKsTLZV/st7FpmNyGma8gvIxIXRE+U9JFhoKE=; b=G0Xyz1vZLIuLYOOndjcliBw30nK1eESfgnhaKRTwlZZfuRPum9znvpLRJBjHb+G3InTbtv gcbj+CxwtobI7pYPfq72yukOqIrRMEKSia+3JGKuZlDsBgMXG88en08AnFHUMCCWm3lzSZ 3TAcfAyy6DFfgr1+UhSVhK9ZomDE5JiSjSblvQMoJNmFyvajthK9HFmMfhTDC6zWaG9r98 o8B2914+RzJv9e7idImONRs9/iiC1qHXj5EvbwsN8lRQpkcSwEhTsqmp4joM//P7ilJXBD cyoXBU7yXzx4hiUPBAxR2uOZMkqZreTjB4FVNpkkSyHoXDk7nMh3/wjGdmjYbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669684258; 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=OyKM1acKsTLZV/st7FpmNyGma8gvIxIXRE+U9JFhoKE=; b=pHL2ZVnp+pdSe1YbJ4SEwRvXuPCZAdwORyPq7vf3+IAayH3iRtHFs6aF871qxEZKt2ltT3 XGUUGH5P4orm6cOykwreG1LZNBhMLBNeNgts9M0m76lz8qKAOwR9O0AvALfjzsnzKmYfUs ZgMCJIUm/bf9P10Tn3tRmCQVw+hNXLRa2VnsEzmxGDYP9OIWMTimGBilQdZgMgZt3LAJPR NEgttOYlice5lTb21iZM/UE9xXtfW6gOq4g5hGCIY/MiCRlNi4pZlsm6foMFz/LyMqfRWs VYs53+RvyNnUEt3xfm4PkYCXttU+ykiRV5MatUqVrbIwg9edraa0pkGU0MBGWg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669684258; a=rsa-sha256; cv=none; b=Q8J4s/uyJUszcGi0jZKeZRoJ3itg8RWIPjlsCuOAhX7f4pxg3UY8eK/1tzkYiCyDaE7+Uz ANHIt0ZKNOPLxcH9PFJAduiKhbC3NUuegVKisZhDQ9uJ0SOThNr0EopJY5GG9DZPcVRy2r x+vzWW6MF7ymziMIypKW54xmTovRsnuVWRZjz0O+yOMbKlTi18gJhx8DGsK5ik9qrj7t7h wycQxm48aXyumTrsYPcx0NRzHq3BKSJBulNVutT4pJnbCtPGOYzY06tvxvmgnYEGVtCHAb SRrawXG2w9Y+x6uQ2qbfROq6pd1QVNkI4uVCwefbDCAqBmklOT57XXRELi7J0Q== 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 4NLkmf1zS9zyS6; Tue, 29 Nov 2022 01:10:58 +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 2AT1AwTf045270; Tue, 29 Nov 2022 01:10:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AT1Awg8045269; Tue, 29 Nov 2022 01:10:58 GMT (envelope-from git) Date: Tue, 29 Nov 2022 01:10:58 GMT Message-Id: <202211290110.2AT1Awg8045269@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 5d805962ca93 - main - bhyve: Avoid unlikely truncation of the blockif ident strings. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5d805962ca9347bbf62750452c4c980decb94793 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=5d805962ca9347bbf62750452c4c980decb94793 commit 5d805962ca9347bbf62750452c4c980decb94793 Author: John Baldwin AuthorDate: 2022-11-29 01:09:15 +0000 Commit: John Baldwin CommitDate: 2022-11-29 01:09:15 +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 --- 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");