From: Borislav Petkov <bp@alien8.de>
To: Tianlin Li <tli@digitalocean.com>
Cc: kernel-hardening@lists.openwall.com, keescook@chromium.org,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Russell King <linux@armlinux.org.uk>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Greentime Hu <green.hu@gmail.com>,
Vincent Chen <deanbo422@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H . Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Jessica Yu <jeyu@kernel.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
Petr Mladek <pmladek@suse.com>,
Joe Lawrence <joe.lawrence@redhat.com>
Subject: Re: [RFC PATCH] kernel/module: have the callers of set_memory_*() check the return value
Date: Wed, 20 Nov 2019 10:58:04 +0100 [thread overview]
Message-ID: <20191120095804.GB2634@zn.tnic> (raw)
In-Reply-To: <20191119155149.20396-1-tli@digitalocean.com>
On Tue, Nov 19, 2019 at 09:51:49AM -0600, Tianlin Li wrote:
> Right now several architectures allow their set_memory_*() family of
> functions to fail, but callers may not be checking the return values. We
> need to fix the callers and add the __must_check attribute.
Please formulate commit messages in passive tone. "we" is ambiguous.
From Documentation/process/submitting-patches.rst:
"Describe your changes in imperative mood, e.g. "make xyzzy do frotz"
instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy
to do frotz", as if you are giving orders to the codebase to change
its behaviour."
Also, you could add a high-level summary of the failure case from:
https://lore.kernel.org/netdev/20180628213459.28631-4-daniel@iogearbox.net/
as a more real-life, convincing justification for this.
> They also may not provide any level of atomicity, in the sense that
> the memory protections may be left incomplete on failure.
> This issue likely has a few
> steps on effects architectures[1]:
> 1)Have all callers of set_memory_*() helpers check the return value.
> 2)Add __much_check to all set_memory_*() helpers so that new uses do not
__must_check
> ignore the return value.
> 3)Add atomicity to the calls so that the memory protections aren't left in
> a partial state.
>
> Ideally, the failure of set_memory_*() should be passed up the call stack,
> and callers should examine the failure and deal with it. But currently,
> some callers just have void return type.
>
> We need to fix the callers to handle the return all the way to the top of
> stack, and it will require a large series of patches to finish all the three
> steps mentioned above. I start with kernel/module, and will move onto other
> subsystems. I am not entirely sure about the failure modes for each caller.
> So I would like to get some comments before I move forward. This single
> patch is just for fixing the return value of set_memory_*() function in
> kernel/module, and also the related callers. Any feedback would be greatly
> appreciated.
>
> [1]:https://github.com/KSPP/linux/issues/7
>
> Signed-off-by: Tianlin Li <tli@digitalocean.com>
> ---
> arch/arm/kernel/ftrace.c | 8 +-
> arch/arm64/kernel/ftrace.c | 6 +-
> arch/nds32/kernel/ftrace.c | 6 +-
> arch/x86/kernel/ftrace.c | 13 ++-
> include/linux/module.h | 16 ++--
> kernel/livepatch/core.c | 15 +++-
> kernel/module.c | 170 +++++++++++++++++++++++++++----------
> kernel/trace/ftrace.c | 15 +++-
> 8 files changed, 175 insertions(+), 74 deletions(-)
Yeah, general idea makes sense but you'd need to redo your patch ontop
of linux-next because there are some changes in flight in ftrace-land at
least and your patch won't apply anymore after next week, when the merge
window opens.
Also, you should use checkpatch before sending a patch as sometimes it makes
sense what it complains about:
WARNING: Missing a blank line after declarations
#79: FILE: arch/arm/kernel/ftrace.c:68:
+ int ret;
+ ret = set_all_modules_text_ro();
WARNING: Missing a blank line after declarations
#150: FILE: arch/x86/kernel/ftrace.c:61:
+ int ret;
+ ret = set_all_modules_text_ro();
WARNING: trailing semicolon indicates no statements, indent implies otherwise
#203: FILE: kernel/livepatch/core.c:731:
+ if (module_enable_ro(patch->mod, true));
+ pr_err("module_enable_ro failed.\n");
ERROR: trailing statements should be on next line
#203: FILE: kernel/livepatch/core.c:731:
+ if (module_enable_ro(patch->mod, true));
WARNING: Missing a blank line after declarations
#451: FILE: kernel/module.c:2091:
+ int ret;
+ ret = frob_text(&mod->core_layout, set_memory_x);
WARNING: Missing a blank line after declarations
#511: FILE: kernel/trace/ftrace.c:5819:
+ int ret = ftrace_arch_code_modify_prepare();
+ if (ret) {
WARNING: Missing a blank line after declarations
#527: FILE: kernel/trace/ftrace.c:5864:
+ int ret = ftrace_arch_code_modify_post_process();
+ FTRACE_WARN_ON(ret);
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index c4ce08f43bd6..39bfc0685854 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -721,16 +721,25 @@ static int klp_init_object_loaded(struct klp_patch *patch,
>
> mutex_lock(&text_mutex);
>
> - module_disable_ro(patch->mod);
> + ret = module_disable_ro(patch->mod);
> + if (ret) {
> + mutex_unlock(&text_mutex);
> + return ret;
> + }
> ret = klp_write_object_relocations(patch->mod, obj);
> if (ret) {
> - module_enable_ro(patch->mod, true);
> + if (module_enable_ro(patch->mod, true));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and if you look at its output above closely, it might even help you
catch the bug you've added.
[ Don't worry, happens to the best of us. :-) ]
Also, what would help review is if you split your patch:
patch 1: Change functions to return a retval
patch 2-n: Change call sites to handle retval properly
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2019-11-20 9:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-19 15:51 [RFC PATCH] kernel/module: have the callers of set_memory_*() check the return value Tianlin Li
2019-11-19 17:07 ` Kees Cook
2019-11-19 21:43 ` Peter Zijlstra
2019-11-19 21:51 ` Tianlin Li
2019-11-19 21:38 ` Peter Zijlstra
2019-11-19 21:54 ` Tianlin Li
2019-11-20 9:58 ` Borislav Petkov [this message]
2019-11-20 16:19 ` Tianlin Li
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=20191120095804.GB2634@zn.tnic \
--to=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=deanbo422@gmail.com \
--cc=green.hu@gmail.com \
--cc=hpa@zytor.com \
--cc=jeyu@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux@armlinux.org.uk \
--cc=mbenes@suse.cz \
--cc=mingo@redhat.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tli@digitalocean.com \
--cc=will@kernel.org \
--cc=x86@kernel.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;
as well as URLs for NNTP newsgroup(s).