From nobody Wed May 17 13:40:52 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 4QLvPw1xFbz4B8tk; Wed, 17 May 2023 13:40:52 +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 4QLvPw1VG3z3LLS; Wed, 17 May 2023 13:40:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684330852; 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=7QPKydAUb/QLv00jku7MtB4gEwt03rwGX2Pzk1+YcB4=; b=SrDL63PPfK2z9gD68jtIsDRxPPG0e/NApsiShR9SQaFNtzUy1rA2UKZt89rdfwQVtvS0Jj YLk6N0RoChCJP/o1wzj6N9yZQ8LcB8ULL7EBW5dlpSfWJvm8jtztheK5nHkZFzZrf5oI6X q9zbfbGcLAKzTpnLgqRXKrIt3SCw13WqnNUh4IA8wFk+1SrwjGFF6EXlx5mtHDB8L2l2j9 nc/qwO0RiyofvxsUnN7dvQnPLNrrdGvx+xJcCht9GDX0J2vkd6bf3gBTKbnGn7OucfmZqA Q0IXuZ5z8W8K9T0PnbY24bslNyvEgVoil7raK7tpaKzEHDHdXmv1HOYayv/x9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684330852; 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=7QPKydAUb/QLv00jku7MtB4gEwt03rwGX2Pzk1+YcB4=; b=buiyTd3eZEisVbpmAkqPFzukbyagQv8Pu/LbTsLCKRCVTHpb3HSICaNKkk4VRwtM4rZUGw DDWNzK8zTk74IjjEMIWN4JJMRsWJ10aOD4mHSRBvCv8vFYNt5YhPKrTqcIpAyGMncLRjK/ EErWRr4tGP13XWKrVwFWveTzACzVCE04RpkLbSNNLe+o6uBtrszGhV5R7uWCHf9wBYkd33 sz2J2HOQDO1ho0CMsdrhn3LzfOkl1jOUWhH+xx25wAqBjc0q7ozqazQjsbyuwygSYVTvH9 JQzIIVquuvfMXvicgAncdJwkKprm8LUSEKUWiwbPkUFAY47VHl5jWnI6JwX3pw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684330852; a=rsa-sha256; cv=none; b=D690G4z8HL8vx0DLhS6Nlw/qyL6RlaLKwABN51sOeI7cG6UhKyN1erSfzMCBvwpU2HGuX0 s0Sa3m28OwP+Zyh3De1v9exoq+wVpYXXbskQI/hfv1LjmD5L4TW8anBqGewGx434pKd1Et EWxND0A/dPg8jh/HU8dj4ZwuuhHPtZ7tpv43qoeG/Kygb0MfkZWCW0jIafkNj4B3TF3qLL ZkmmLKs0naEaRsxtm2XciJB0fg5f3voM7nqqzFqi8sDOLjYee3PLcOzHXMCJCCABla0IuG I0AglklHeBZmhFpFutbaLjLJh106TL8H7VjhC9KaX8RZhjxGvZYXp5xP1y2m3g== 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 4QLvPw0btdz15Pf; Wed, 17 May 2023 13:40:52 +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 34HDeqWV010944; Wed, 17 May 2023 13:40:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34HDeqIw010928; Wed, 17 May 2023 13:40:52 GMT (envelope-from git) Date: Wed, 17 May 2023 13:40:52 GMT Message-Id: <202305171340.34HDeqIw010928@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 26d9f973d869 - main - bhyve: error out if fwcfg user file isn't read completely 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: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 26d9f973d8691eccc098ded7326137d6f76ad243 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=26d9f973d8691eccc098ded7326137d6f76ad243 commit 26d9f973d8691eccc098ded7326137d6f76ad243 Author: Corvin Köhne AuthorDate: 2023-05-12 05:37:32 +0000 Commit: Corvin Köhne CommitDate: 2023-05-17 13:39:37 +0000 bhyve: error out if fwcfg user file isn't read completely At the moment, fwcfg reads the file once at startup and passes these data to the guest. Therefore, we should always read the whole file. Otherwise we should error out. Additionally, GCC12 complains that the comparison whether fwcfg_file->size is lower than 0 is always false due to the limited range of data type. Reviewed by: markj Fixes: ca14781c8170f3517ae79e198c0c880dbc3142dd ("bhyve: add cmdline option for user defined fw_cfg items") MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40076 --- usr.sbin/bhyve/qemu_fwcfg.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c index 45c4a885ae96..e845c70950b1 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -524,6 +524,7 @@ qemu_fwcfg_parse_cmdline_arg(const char *opt) struct qemu_fwcfg_user_file *fwcfg_file; struct stat sb; const char *opt_ptr, *opt_end; + ssize_t bytes_read; int fd; fwcfg_file = malloc(sizeof(*fwcfg_file)); @@ -593,16 +594,14 @@ qemu_fwcfg_parse_cmdline_arg(const char *opt) close(fd); return (ENOMEM); } - fwcfg_file->size = read(fd, fwcfg_file->data, sb.st_size); - if ((ssize_t)fwcfg_file->size < 0) { + bytes_read = read(fd, fwcfg_file->data, sb.st_size); + if (bytes_read < 0 || bytes_read != sb.st_size) { warn("Unable to read file \"%s\"", opt_ptr); free(fwcfg_file->data); close(fd); return (-1); - } else if (fwcfg_file->size < sb.st_size) { - warnx("Only read %u bytes of file \"%s\"", - fwcfg_file->size, opt_ptr); } + fwcfg_file->size = bytes_read; close(fd); } else {