From: Al Viro <viro@ZenIV.linux.org.uk>
To: Josef Bacik <josef@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
russell@rickstewart.com, bugme-daemon@bugzilla.kernel.org,
linux-fsdevel@vger.kernel.org, john@johnmccutchan.com,
rlove@rlove.org
Subject: Re: [Bugme-new] [Bug 12754] New: inotify doesn't free memory allocated to watches
Date: Wed, 25 Feb 2009 03:13:04 +0000 [thread overview]
Message-ID: <20090225031304.GL28946@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20090225023850.GA6269@unused.rdu.redhat.com>
On Tue, Feb 24, 2009 at 09:38:50PM -0500, Josef Bacik wrote:
> > Actually, looking at inotify_user.c, we seem to be doing something rather
> > fishy. Look: event gets triggered, we pick the watch, get inotify_device
> > (inotify_user-specific stuff) from it, grap mutex on it (dev->ev_mutex)
> > and drop reference to inotify_watch. Which happily triggers ->destroy_watch,
> > which does put_inotify_dev(). Which is
> > if (atomic_dec_and_test(&dev->count)) {
> > atomic_dec(&dev->user->inotify_devs);
> > free_uid(dev->user);
> > kfree(dev);
> > }
> > What's to stop that from happening when we'd been holding the last reference
> > to that sucker? kfree() while holding a mutex inside the structure being
> > freed is not nice...
>
> That shouldn't happen, we should only be doing the last put on the dev when all
> watches have been removed. When we do the inotify_init we do the get on the
> dev, and then for every watch theres a pair of get/put for instantiation and
> removal, so we can't free the dev when doing a put for a watch (well obviously
> we can, but we shouldn't be anyway).
Hold on. Either that sucker can happen after inotify_release() has dropped
its reference or it can not. In the former case, we are screwed since _we_
are holding the last remaining reference. In the latter, WTF are we grabbing
references to ->dev at watch creation?
> If the user is getting back -ENOSPC from
> inotify then it can only mean we've run out of watches
>
> if (atomic_read(&dev->user->inotify_watches) >=
> inotify_max_user_watches)
> return -ENOSPC;
... or that idr_pre_get() has failed in inotify.c
prev parent reply other threads:[~2009-02-25 3:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-12754-10286@http.bugzilla.kernel.org/>
2009-02-24 21:05 ` [Bugme-new] [Bug 12754] New: inotify doesn't free memory allocated to watches Andrew Morton
2009-02-24 21:38 ` Al Viro
2009-02-24 23:23 ` Al Viro
2009-02-24 23:40 ` Andrew Morton
2009-02-25 0:28 ` Al Viro
2009-02-25 0:40 ` Andrew Morton
2009-02-25 2:38 ` Josef Bacik
2009-02-25 3:13 ` Al Viro [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=20090225031304.GL28946@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=akpm@linux-foundation.org \
--cc=bugme-daemon@bugzilla.kernel.org \
--cc=john@johnmccutchan.com \
--cc=josef@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=rlove@rlove.org \
--cc=russell@rickstewart.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).