From: Al Viro <viro@ZenIV.linux.org.uk>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: Gregory Haskins <ghaskins@novell.com>,
kvm@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
avi@redhat.com
Subject: Re: [KVM PATCH v3 2/2] kvm: add support for irqfd via eventfd-notification interface
Date: Sun, 3 May 2009 20:01:36 +0100 [thread overview]
Message-ID: <20090503190136.GY8633@ZenIV.linux.org.uk> (raw)
In-Reply-To: <alpine.DEB.1.10.0905031103290.7899@makko.or.mcafeemobile.com>
On Sun, May 03, 2009 at 11:07:26AM -0700, Davide Libenzi wrote:
> On Sun, 3 May 2009, Al Viro wrote:
> > On Mon, Apr 27, 2009 at 02:33:34PM -0400, Gregory Haskins wrote:
> > > + /* We re-use eventfd for irqfd */
> > > + fd = sys_eventfd2(0, 0);
> > > + if (fd < 0) {
> > > + ret = fd;
> > > + goto fail;
> > > + }
> > > +
> > > + /* We maintain a reference to eventfd for the irqfd lifetime */
> > > + file = eventfd_fget(fd);
> > > + if (IS_ERR(file)) {
> > > + ret = PTR_ERR(file);
> > > + goto fail;
> > > + }
> > > +
> > > + irqfd->file = file;
> >
> > This is just plain wrong. You have no promise whatsoever that caller of
> > that sucker won't race with e.g. dup2(). IOW, you can't assume that
> > file will be of the expected kind.
>
> The eventfd_fget() checks for the file_operations pointer, before
> returning the file*, and fails if the fd in not an eventfd. Or you have
> other concerns?
OK, but... it's still wrong. Descriptor numbers are purely for interaction
with userland; using them that way violates very general race-prevention
rules, even if you do paper over the worst of consequences with check in
eventfd_fget().
General rules:
* descriptor you've generated is fit only for return to userland;
* descriptor you've got from userland is fit only for *single*
fget() or equivalent, unless you are one of the core syscalls manipulating
the descriptor table itself (dup2, etc.)
* once file is installed in descriptor table, you'd better be past
the last failure exit; sys_close() on cleanup path is not acceptable.
That's what reserving descriptors is for.
IOW, the sane solution would be to export something that returns your
struct file *. And stop playing with fd completely.
next prev parent reply other threads:[~2009-05-03 19:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-27 18:33 [KVM PATCH v3 0/2] irqfd Gregory Haskins
2009-04-27 18:33 ` [KVM PATCH v3 1/2] eventfd: export fget and signal interfaces for module use Gregory Haskins
2009-04-27 18:33 ` [KVM PATCH v3 2/2] kvm: add support for irqfd via eventfd-notification interface Gregory Haskins
2009-04-30 13:07 ` Michael S. Tsirkin
2009-05-03 16:59 ` Avi Kivity
2009-05-03 19:04 ` Michael S. Tsirkin
2009-05-03 19:17 ` Avi Kivity
2009-05-03 19:25 ` Michael S. Tsirkin
2009-05-03 6:44 ` Al Viro
2009-05-03 18:07 ` Davide Libenzi
2009-05-03 19:01 ` Al Viro [this message]
2009-05-03 19:22 ` file descriptor abuses Al Viro
2009-05-03 20:11 ` [KVM PATCH v3 2/2] kvm: add support for irqfd via eventfd-notification interface Davide Libenzi
2009-05-03 20:31 ` Al Viro
2009-04-29 6:10 ` [KVM PATCH v3 0/2] irqfd Andrew Morton
2009-04-29 8:18 ` Avi Kivity
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=20090503190136.GY8633@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=avi@redhat.com \
--cc=davidel@xmailserver.org \
--cc=ghaskins@novell.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox