From: Eric Blake <eblake@redhat.com>
To: Amos Kong <akong@redhat.com>, qemu-devel@nongnu.org
Cc: jasowang@redhat.com, stefanha@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH] check return value of fcntl() to detect invalid fd
Date: Fri, 19 Dec 2014 08:58:33 -0700 [thread overview]
Message-ID: <54944B29.6050501@redhat.com> (raw)
In-Reply-To: <1418995502-14908-1-git-send-email-akong@redhat.com>
On 12/19/2014 06:25 AM, Amos Kong wrote:
> Passing some invalid fds in QEMU commandline, the fds don't exist.
> QEMU will get error "TUNGETIFF ioctl() failed: Bad file descriptor",
> and coredump in setting queues.
>
> This patch checked return value of first operate to fd, QEMU will
> report error and exit without coredump. It's effected for both netdev
s/effected/needed/
> fds and vhost_net fds.
>
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
> net/tap.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
>
> - fcntl(fd, F_SETFL, O_NONBLOCK);
> + ret = fcntl(fd, F_SETFL, O_NONBLOCK);
> + if (ret < 0) {
> + error_report("Fail to set file status to nonblock, "
> + "%s", strerror(-ret));
Awkward grammar; I would suggest s/Fail/Failed/;
s/nonblock/nonblocking/, if you still end up reporting the error here.
Wrong, in multiple ways. fcntl does not return negative errno values,
just -1, and strerror(1) is not what you want. Furthermore, this code
is blindly clearing all other flags as part of setting O_NONBLOCK. The
correct way to set O_NONBLOCK is to call F_GETFL first. Which is what
qemu_set_nonblock() from oslib-posix.c already does (so reuse that
instead of reinventing it here).
Except _that_ function fails to report failure, so we need a bigger
audit to fix it and all callers.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
next prev parent reply other threads:[~2014-12-19 17:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-19 13:25 [Qemu-devel] [PATCH] check return value of fcntl() to detect invalid fd Amos Kong
2014-12-19 15:58 ` Eric Blake [this message]
2014-12-22 3:48 ` Jason Wang
2014-12-22 5:28 ` Amos Kong
2014-12-22 5:54 ` Jason Wang
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=54944B29.6050501@redhat.com \
--to=eblake@redhat.com \
--cc=akong@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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.