All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: Phil Staub <phils@windriver.com>
Cc: Adam Jiang <jiang.adam@gmail.com>, linux-mips@linux-mips.org
Subject: Re: How to detect STACKOVEFLOW on mips
Date: Wed, 30 Jun 2010 15:57:25 +0100	[thread overview]
Message-ID: <20100630145725.GB31938@linux-mips.org> (raw)
In-Reply-To: <4C2B543E.2010309@windriver.com>

On Wed, Jun 30, 2010 at 07:27:10AM -0700, Phil Staub wrote:

> >I'm having a problem with kernel mode stack on my box. It seems that
> >STACKOVERFLOW happened to Linux kernel. However, I can't prove it
> >because the lack of any detection in __do_IRQ() function just like on
> >the other architectures. If you know something about, please help me
> >on following two questions.
> >- Is there any possible to do this on MIPS?
> 
> The mechanisms I know about for detecting stack overflow include:
> 
> 1. Use of the MMU - stack ends at a page boundary, adjacent page is
> either unmapped or mapped read-only and causes an exception if violated.

Won't easily work on MIPS as the stack is allocated in KSEG0 / XKPHYS
which are unmapped segments.  It would be necessary to relocate the stack
into a mapped space.

Ultra-ancient Linux/MIPS kernels actually used to do that but that code
may well even predate everything that still exists on linux-mips.org.

> 2. Hooks inserted into toolchain to cause any stack decrement to be
> first tested against a limit.
> 
> 3. Fill entire stack with a recognizable pattern before first
> use. After suspected stack overflow, check to see if the pattern has
> been disturbed in the area of the stack limit.

This was afaik never ported to MIPS though that'd be easy.

> (Disclaimer: I've used all of these in some form on other OSes, but
> not on Linux. Someone else may have a more directly relevant answer.)
> 
> >- or, more simple question, how could I get the address $sp pointed by
> >asm() notation in C?
> 
> How about something like:
> 
> {
> 	long x;
> 	...
> 	asm("move %0,$29":"=g"(x));
> 	...
> }

That will do.  Or even something portable like:

{
	unsigned long foo;

	return &foo;
}

which used to work (GNU alloca and others were using this) but I'm sure
GCC has learned how to optimize this to shreds.

  Ralf

  reply	other threads:[~2010-06-30 20:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-30  5:59 How to detect STACKOVEFLOW on mips Adam Jiang
2010-06-30 14:27 ` Phil Staub
2010-06-30 14:57   ` Ralf Baechle [this message]
2010-06-30 18:16   ` David VomLehn
2010-06-30 22:13     ` Maciej W. Rozycki
2010-06-30 14:50 ` Ralf Baechle
2010-06-30 21:57   ` Matt Fleming
2010-07-05 10:56     ` Ralf Baechle
2010-07-05 13:09       ` Matt Fleming
2010-07-05 13:35         ` Ralf Baechle
2010-07-05 14:08           ` Matt Fleming

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=20100630145725.GB31938@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=jiang.adam@gmail.com \
    --cc=linux-mips@linux-mips.org \
    --cc=phils@windriver.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 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.