From: Ingo Molnar <mingo@kernel.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] x86/unwind: ensure stack grows down
Date: Thu, 27 Oct 2016 08:30:11 +0200 [thread overview]
Message-ID: <20161027063010.GA3884@gmail.com> (raw)
In-Reply-To: <65e1ac5a17bd20d43c21d400ea2fcd84e6d09e78.1477496147.git.jpoimboe@redhat.com>
* Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> Add a sanity check to ensure the stack only grows down, and print a
> warning if the check fails.
>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
> arch/x86/kernel/unwind_frame.c | 36 ++++++++++++++++++++++++++++++++----
> 1 file changed, 32 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
> index 9be9a8f..0d8d2f2 100644
> --- a/arch/x86/kernel/unwind_frame.c
> +++ b/arch/x86/kernel/unwind_frame.c
> @@ -24,6 +24,15 @@ unsigned long unwind_get_return_address(struct unwind_state *state)
> }
> EXPORT_SYMBOL_GPL(unwind_get_return_address);
>
> +static size_t regs_size(struct pt_regs *regs)
> +{
> + /* x86_32 regs from kernel mode are two words shorter */
> + if (IS_ENABLED(CONFIG_X86_32) && !user_mode(regs))
> + return sizeof(*regs) - (2*sizeof(long));
Unnecessary parentheses.
> +
> + return sizeof(*regs);
> +}
> +
> static bool is_last_task_frame(struct unwind_state *state)
> {
> unsigned long bp = (unsigned long)state->bp;
> @@ -71,6 +80,7 @@ bool unwind_next_frame(struct unwind_state *state)
> struct pt_regs *regs;
> unsigned long *next_bp, *next_frame;
> size_t next_len;
> + enum stack_type prev_type = state->stack_info.type;
>
> if (unwind_done(state))
> return false;
> @@ -134,6 +144,18 @@ bool unwind_next_frame(struct unwind_state *state)
> goto bad_address;
> }
>
> + /* make sure it only unwinds up and doesn't overlap the last frame */
Please capitalize comments - and if the comment refers to a control block please
also add ':', i.e. something like:
/* Make sure it only unwinds up and doesn't overlap the last frame: */
This also applies to other places in this patch series.
> + if (state->stack_info.type == prev_type) {
> + if (state->regs &&
> + (void *)next_frame < (void *)state->regs +
> + regs_size(state->regs))
No line breaks that make the code worse please.
> + goto bad_address;
> +
> + if (state->bp &&
> + (void *)next_frame < (void *)state->bp + FRAME_HEADER_SIZE)
Ditto.
> + goto bad_address;
> + }
> +
> /* move to the next frame */
> if (regs) {
> state->regs = regs;
> @@ -146,10 +168,16 @@ bool unwind_next_frame(struct unwind_state *state)
> return true;
>
> bad_address:
> - printk_deferred_once(KERN_WARNING
> - "WARNING: kernel stack frame pointer at %p in %s:%d has bad value %p\n",
> - state->bp, state->task->comm,
> - state->task->pid, next_bp);
> + if (state->regs)
> + printk_deferred_once(KERN_WARNING
> + "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
> + state->regs, state->task->comm,
> + state->task->pid, next_frame);
> + else
> + printk_deferred_once(KERN_WARNING
> + "WARNING: kernel stack frame pointer at %p in %s:%d has bad value %p\n",
> + state->bp, state->task->comm,
> + state->task->pid, next_frame);
Multi-line statements should have curly braces.
Thanks,
Ingo
next prev parent reply other threads:[~2016-10-27 6:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-26 15:41 [PATCH 0/4] x86/unwind: add some unwinder warnings Josh Poimboeuf
2016-10-26 15:41 ` [PATCH 1/4] x86/unwind: warn on bad frame pointer Josh Poimboeuf
2016-10-27 7:37 ` [tip:x86/asm] x86/unwind: Warn " tip-bot for Josh Poimboeuf
2016-10-26 15:41 ` [PATCH 2/4] x86/unwind: ensure stack grows down Josh Poimboeuf
2016-10-27 6:30 ` Ingo Molnar [this message]
2016-10-27 13:10 ` [PATCH v2] " Josh Poimboeuf
2016-10-28 6:49 ` [tip:x86/asm] x86/unwind: Ensure " tip-bot for Josh Poimboeuf
2016-10-26 15:41 ` [PATCH 3/4] x86/dumpstack: warn on stack recursion Josh Poimboeuf
2016-10-27 7:38 ` [tip:x86/asm] x86/dumpstack: Warn " tip-bot for Josh Poimboeuf
2016-10-26 15:41 ` [PATCH 4/4] x86/unwind: detect bad stack return address Josh Poimboeuf
2016-10-27 7:38 ` [tip:x86/asm] x86/unwind: Detect " tip-bot for 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=20161027063010.GA3884@gmail.com \
--to=mingo@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.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).