public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Sasha Levin <sasha.levin@oracle.com>
Cc: john@johnmccutchan.com, rlove@rlove.org, eparis@parisplace.org,
	linux-kernel@vger.kernel.org, Jan Kara <jack@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] fsnotify: don't put user context if it was never assigned
Date: Thu, 11 Sep 2014 19:52:09 +0200	[thread overview]
Message-ID: <5411E149.5090305@gmx.de> (raw)
In-Reply-To: <1406640314-25201-1-git-send-email-sasha.levin@oracle.com>

Hello Sasha,

I have CCed Jan, because he has been the only one working on this file 
in the last 18 months.

A failure path in which group->inotify_data.user is not yet assigned 
starts here:

static struct fsnotify_group *inotify_new_group(unsigned int max_events)
{
...
	oevent = kmalloc(sizeof(struct inotify_event_info), GFP_KERNEL);
	if (unlikely(!oevent)) {
		fsnotify_destroy_group(group);
		return ERR_PTR(-ENOMEM);
	}

So your check
   if (group->inotify_data.user)
is reasonable.

3.17.0-rc3 compiles with the patch applied.

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

@Andrew
Please, add the patch to the mm-tree.

Best regards

Heinrich Schuchardt

On 29.07.2014 15:25, Sasha Levin wrote:
> On some failure paths we may attempt to free user context even
> if it wasn't assigned yet. This will cause a NULL ptr deref
> and a kernel BUG.
>
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
>   fs/notify/inotify/inotify_fsnotify.c |    6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
> index 43ab1e1..9c8187e 100644
> --- a/fs/notify/inotify/inotify_fsnotify.c
> +++ b/fs/notify/inotify/inotify_fsnotify.c
> @@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
>   	/* ideally the idr is empty and we won't hit the BUG in the callback */
>   	idr_for_each(&group->inotify_data.idr, idr_callback, group);
>   	idr_destroy(&group->inotify_data.idr);
> -	atomic_dec(&group->inotify_data.user->inotify_devs);
> -	free_uid(group->inotify_data.user);
> +	if (group->inotify_data.user) {
> +		atomic_dec(&group->inotify_data.user->inotify_devs);
> +		free_uid(group->inotify_data.user);
> +	}
>   }
>
>   static void inotify_free_event(struct fsnotify_event *fsn_event)
>


  parent reply	other threads:[~2014-09-11 17:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 13:25 [PATCH] fsnotify: don't put user context if it was never assigned Sasha Levin
2014-09-03 21:31 ` Sasha Levin
2014-09-08 14:24   ` Sasha Levin
2014-09-11 17:52 ` Heinrich Schuchardt [this message]
2014-09-12 16:20   ` Jan Kara
2014-09-11 20:43 ` Andrew Morton
2014-09-12  1:49   ` Sasha Levin

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=5411E149.5090305@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=akpm@linux-foundation.org \
    --cc=eparis@parisplace.org \
    --cc=jack@suse.cz \
    --cc=john@johnmccutchan.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rlove@rlove.org \
    --cc=sasha.levin@oracle.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