mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Amerigo Wang <xiyou.wangcong@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>,
	Roland McGrath <roland@redhat.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] exec: fix set_binfmt() vs sys_delete_module() race
Date: Tue, 28 Jul 2009 16:58:17 +0200	[thread overview]
Message-ID: <20090728145817.GB6664@redhat.com> (raw)
In-Reply-To: <20090728071949.GD6036@cr0.nay.redhat.com>

On 07/28, Amerigo Wang wrote:
>
> On Fri, Jul 24, 2009 at 07:19:43PM +0200, Oleg Nesterov wrote:
> >sys_delete_module() can set MODULE_STATE_GOING after search_binary_handler()
> >does try_module_get(). In this case set_binfmt()->try_module_get() fails but
> >since none of the callers check the returned error, the task will run with
> >the wrong old ->binfmt.
> >
> >The proper fix should change all ->load_binary() methods, but we can rely
> >on fact that the caller must hold a reference to binfmt->module and use
> >__module_get() which never fails.
> >
>
> Sounds reasonable.
>
> Would like to put the last words as comments into code below?

Yes, thanks.

Rusty pointed out this too, and I already sent the updated patch.
But due to my mistake (I forgot to CC lkml) this was discussed
off-list.

> >-int set_binfmt(struct linux_binfmt *new)
> >+void set_binfmt(struct linux_binfmt *new)
> > {
> >-	struct linux_binfmt *old = current->binfmt;
> >+	if (current->binfmt)
> >+		module_put(current->binfmt->module);
> >
> >-	if (new) {
> >-		if (!try_module_get(new->module))
> >-			return -1;
> >-	}
> > 	current->binfmt = new;
> >-	if (old)
> >-		module_put(old->module);
> >-	return 0;
> >+	if (new)
> >+		__module_get(new->module);
>
>
> I prefer to put the 'current->binfmt = new;' line as the last
> statement within this function, since this is more readable for me.

Perhaps... but this is purely cosmetic, and the patch is already
in -mm. Unless you have a strong feeleing, I'd prefer to not send
yet another update.

Oleg.


  reply	other threads:[~2009-07-28 15:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 17:19 Oleg Nesterov
2009-07-28  7:19 ` Amerigo Wang
2009-07-28 14:58   ` Oleg Nesterov [this message]
2009-07-29  8:51     ` Amerigo 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=20090728145817.GB6664@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=h-shimamoto@ct.jp.nec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=xiyou.wangcong@gmail.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

Powered by JetHome