mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@gmail.com>
To: Eric Paris <eparis@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>
Cc: LKML <linux-kernel@vger.kernel.org>, Eugene Teo <eugene@redhat.com>
Subject: Inotify memory leak
Date: Wed, 24 Nov 2010 00:15:03 +0100	[thread overview]
Message-ID: <AANLkTimkna-R1bhnx6inanobSUye423xqx99nZ27CLBA@mail.gmail.com> (raw)

Hi,

Inotify does not clean up properly when it fails to create the file
descriptor. So it leaks kernel memory. Watch "slabtop" while running
this program:

#include <sys/inotify.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
        int fds[2];

        /* Circumvent max inotify instances limit */
        while (pipe(fds) != -1)
                ;

        while (1)
                inotify_init();

        return 0;
}

Specifically, the problem is in inotify_init1 where the group pointer is leaked:

        group = inotify_new_group(user, inotify_max_queued_events);
[...]
        ret = anon_inode_getfd("inotify", &inotify_fops, group,
                                  O_RDONLY | flags);
        if (ret >= 0)
                return ret;

        atomic_dec(&user->inotify_devs);
out_free_uid:
        free_uid(user);
        return ret;

I think it should be easily fixed by calling fsnotify_put_group() at
the right place.


Vegard

             reply	other threads:[~2010-11-23 23:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-23 23:15 Vegard Nossum [this message]
2010-11-23 23:25 ` Eric Paris

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=AANLkTimkna-R1bhnx6inanobSUye423xqx99nZ27CLBA@mail.gmail.com \
    --to=vegard.nossum@gmail.com \
    --cc=eparis@redhat.com \
    --cc=eugene@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®