From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Greg Kurz <groug@kaod.org>, Michael Tokarev <mjt@tls.msk.ru>
Subject: Re: [PATCH] hw/9pfs: Check for error return from local_fid_fd()
Date: Fri, 03 Jul 2026 18:22:13 +0200 [thread overview]
Message-ID: <2193677.KlZ2vcFHjT@weasel> (raw)
In-Reply-To: <20260703132528.4035684-1-peter.maydell@linaro.org>
On Friday, 3 July 2026 15:25:28 CEST Peter Maydell wrote:
> The local_fid_fd() function can fail (returning -1 if dirfd() fails);
> check for this explicitly rather than relying on something later on
> failing because it was passed a -1 file descriptor.
>
> This was flagged up by Coverity: CID 1660923, 1660924, 1660925
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/9pfs/9p-local.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
> index ee592b62f8..8f27c562b5 100644
> --- a/hw/9pfs/9p-local.c
> +++ b/hw/9pfs/9p-local.c
> @@ -788,6 +788,9 @@ static int local_fstat(FsContext *fs_ctx, int fid_type,
> {
> int err, fd = local_fid_fd(fid_type, fs);
>
> + if (fd < 0) {
> + return fd;
> + }
Officially only -1 is an invalid file descriptor, and if you look at this file
we therefore check file descriptors exactly against -1 for that reason.
For the Linux kernel the entire negative range is invalid for file
descriptors, but keep in mind that 9pfs in QEMU also supports FreeBSD and
macOS hosts and we have Windows host patches lurking around where things are
not for certain, at least not for me. So I would not break that assumption.
You might also consider adding error_report_once() in local_fid_fd() as this
would be an unexpected case, even though gracefully handled already.
/Christian
prev parent reply other threads:[~2026-07-03 16:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 13:25 [PATCH] hw/9pfs: Check for error return from local_fid_fd() Peter Maydell
2026-07-03 13:52 ` Michael Tokarev
2026-07-03 14:03 ` Peter Maydell
2026-07-03 16:22 ` Christian Schoenebeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2193677.KlZ2vcFHjT@weasel \
--to=qemu_oss@crudebyte.com \
--cc=groug@kaod.org \
--cc=mjt@tls.msk.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.