All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
	Jessica Yu <jeyu@kernel.org>,
	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] livepatch: Fix ftrace module text permissions race
Date: Thu, 30 May 2019 15:54:14 +0200	[thread overview]
Message-ID: <20190530135414.taftuprranwtowry@pathway.suse.cz> (raw)
In-Reply-To: <bb69d4ac34111bbd9cb16180a6fafe471a88d80b.1559156299.git.jpoimboe@redhat.com>

On Wed 2019-05-29 14:02:24, Josh Poimboeuf wrote:
> The above panic occurs when loading two modules at the same time with
> ftrace enabled, where at least one of the modules is a livepatch module:
> 
> CPU0					CPU1
> klp_enable_patch()
>   klp_init_object_loaded()
>     module_disable_ro()
>     					ftrace_module_enable()
> 					  ftrace_arch_code_modify_post_process()
> 				    	    set_all_modules_text_ro()
>       klp_write_object_relocations()
>         apply_relocate_add()
> 	  *patches read-only code* - BOOM

This patch looks fine and fixes the race:

Reviewed-by: Petr Mladek <pmladek@suse.com>


That said, the semantic of text_mutex is a bit unclear:

   + It serializes RO/RW setting but not NX

   + Nothing prevents manipulation of the access rights
     by external code before the module is ready-enough.
     I mean before the sections are set RO by the module
     loader itself.

     Most sections are ready in MODULE_STATE_COMMING state.
     Only ro_after_init sections need to stay RW longer,
     see my question below.


> diff --git a/kernel/module.c b/kernel/module.c
> index 6e6712b3aaf5..3c056b56aefa 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);

The "true" parameter causes that also ro_after_init section is
set read only. What is the purpose of this section, please?

I ask because module_enable_ro(mod, true) can be called
earlier from klp_init_object_loaded() from do_one_initcall().

For example, it could some MODULE_STATE_LIVE notifier
when it requires write access to ro_after_init section.

Anyway, the above is a separate problem. This patch looks
fine for the original problem.

Best Regards,
Petr

  parent reply	other threads:[~2019-05-30 13:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 19:02 [PATCH] livepatch: Fix ftrace module text permissions race Josh Poimboeuf
2019-05-30 11:57 ` Jessica Yu
2019-05-30 13:54 ` Petr Mladek [this message]
2019-05-31 19:12   ` Josh Poimboeuf
2019-05-31 22:25     ` Josh Poimboeuf
2019-06-13 21:38       ` Steven Rostedt
2019-06-14  0:57         ` Josh Poimboeuf
2019-05-31  8:49 ` Miroslav Benes

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=20190530135414.taftuprranwtowry@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=jeyu@kernel.org \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=johannes@erdfelt.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mingo@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.