mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Jessica Yu <jeyu@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
	Joe Lawrence <joe.lawrence@redhat.com>,
	linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
	Johannes Erdfelt <johannes@erdfelt.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 2/3] module: Add text_mutex lockdep assertions for page attribute changes
Date: Fri, 14 Jun 2019 13:21:21 -0500	[thread overview]
Message-ID: <20190614182121.l4qvrfsjettoc7mi@treble> (raw)
In-Reply-To: <20190614140457.urqjlosesvdtmiia@pathway.suse.cz>

On Fri, Jun 14, 2019 at 04:04:57PM +0200, Petr Mladek wrote:
> On Thu 2019-06-13 20:07:23, Josh Poimboeuf wrote:
> > External callers of the module page attribute change functions now need
> > to have the text_mutex.  Enforce that with lockdep assertions.
> > 
> > diff --git a/kernel/module.c b/kernel/module.c
> > index 6e6712b3aaf5..e43a90ee2d23 100644
> > --- a/kernel/module.c
> > +++ b/kernel/module.c
> > @@ -3519,7 +3534,7 @@ static noinline int do_init_module(struct module *mod)
> >  	/* Switch to core kallsyms now init is done: kallsyms may be walking! */
> >  	rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms);
> >  #endif
> > -	module_enable_ro(mod, true);
> > +	__module_enable_ro(mod, true);
> 
> This one must be called under text_mutex. Otherwise it might get
> called when ftrace is in the middle of modifying the functions.
> 
> It should be enough to take text_mutex right around this call.
> It will prevent making the code ro when ftrace is doing
> the modification. It safe also the other way.
> set_all_modules_text_ro() does not call frob_ro_after_init().
> Therefore ftrace could not make the after_init section RO prematurely.
> 
> >  	mod_tree_remove_init(mod);
> >  	module_arch_freeing_init(mod);
> >  	mod->init_layout.base = NULL;
> > @@ -3626,8 +3641,8 @@ static int complete_formation(struct module *mod, struct load_info *info)
> >  	/* This relies on module_mutex for list integrity. */
> >  	module_bug_finalize(info->hdr, info->sechdrs, mod);
> >  
> > -	module_enable_ro(mod, false);
> > -	module_enable_nx(mod);
> > +	__module_enable_ro(mod, false);
> > +	__module_enable_nx(mod);
> 
> This one is OK. It is called when the module is in
> MODULE_STATE_UNFORMED. Therefore it is ignored by ftrace.
> The module state is manipulated and checked under module_mutex.

Yes, good catch.  Thanks.

-- 
Josh

  reply	other threads:[~2019-06-14 18:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14  1:07 [PATCH 0/3] module: Livepatch/ftrace fixes Josh Poimboeuf
2019-06-14  1:07 ` [PATCH 1/3] module: Fix livepatch/ftrace module text permissions race Josh Poimboeuf
2019-06-14 21:04   ` Steven Rostedt
2019-06-26  8:22     ` Miroslav Benes
2019-06-26 13:37       ` Petr Mladek
2019-06-26 14:44         ` Thomas Gleixner
2019-06-26 14:52           ` Josh Poimboeuf
2019-06-26 14:59           ` Steven Rostedt
2019-06-14  1:07 ` [PATCH 2/3] module: Add text_mutex lockdep assertions for page attribute changes Josh Poimboeuf
2019-06-14 14:04   ` Petr Mladek
2019-06-14 18:21     ` Josh Poimboeuf [this message]
2019-06-14  1:07 ` [PATCH 3/3] module: Improve module __ro_after_init handling Josh Poimboeuf
2019-06-14 14:14   ` Petr Mladek
2019-06-14 18:23     ` Josh Poimboeuf

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=20190614182121.l4qvrfsjettoc7mi@treble \
    --to=jpoimboe@redhat.com \
    --cc=jeyu@kernel.org \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=johannes@erdfelt.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mingo@kernel.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®