Received: from eggs.gnu.org ([140.186.70.92]:49559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhLcH-0001jn-5G for qemu-devel@nongnu.org; Thu, 14 Jul 2011 09:06:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QhLcC-0008JE-Nt for qemu-devel@nongnu.org; Thu, 14 Jul 2011 09:06:08 -0400 Received: from adelie.canonical.com ([91.189.90.139]:57396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhLcC-0008Iz-7q for qemu-devel@nongnu.org; Thu, 14 Jul 2011 09:06:04 -0400 Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QhLcA-0001EV-7c for ; Thu, 14 Jul 2011 13:06:02 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 78D302EAB22 for ; Thu, 14 Jul 2011 13:05:58 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Thu, 14 Jul 2011 13:00:18 -0000 From: Andrew Griffiths <807893@bugs.launchpad.net> Sender: bounces@canonical.com References: <20110709081416.14384.20718.malonedeb@wampee.canonical.com> Message-Id: <20110714130018.31713.75007.malone@gac.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 807893] Re: qemu privilege escalation Reply-To: Bug 807893 <807893@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org with some grepping of parent callers, looks like the cpu is probably my issue static void qemu_kvm_start_vcpu(CPUState *env) { env->thread =3D qemu_mallocz(sizeof(QemuThread)); env->halt_cond =3D qemu_mallocz(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env); /* init the dynamic translator */ cpu_exec_init_all(tb_size * 1024 * 1024); .. etc 6613 clone(child_stack=3D0xa75df454, flags=3DCLONE_VM|CLONE_FS|CLONE_FILES|= CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|C= LONE_CHILD_CLEARTID, parent_tidptr=3D0xa75dfbd8, {entry_number:6, base_addr= :0xa75dfb70, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limi= t_in_pages:1, seg_not_present:0, useable:1}, child_tidptr=3D0xa75dfbd8) =3D= 16615 .. etc 16615 ioctl(4, KVM_CREATE_VCPU, 0) =3D 7 16615 ioctl(3, KVM_GET_VCPU_MMAP_SIZE, 0) =3D 12288 16615 mmap2(NULL, 12288, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0) =3D 0xa6dd= c000 16615 ioctl(7, KVM_SET_VAPIC_ADDR, 0xa75de1a4) =3D 0 later on it does chroot/setgid/setuid -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/807893 Title: qemu privilege escalation Status in QEMU: Confirmed Bug description: If qemu is started as root, with -runas, the extra groups is not dropped correctly /proc/`pidof qemu`/status .. Uid: 100 100 100 100 Gid: 100 100 100 100 FDSize: 32 Groups: 0 1 2 3 4 6 10 11 26 27 = ... The fix is to add initgroups() or setgroups(1, [gid]) where appropriate to os-posix.c. The extra gid's allow read or write access to other files (such as /dev etc). Emulating the qemu code: # python ... >>> import os >>> os.setgid(100) >>> os.setuid(100) >>> os.execve("/bin/sh", [ "/bin/sh" ], os.environ) sh-4.1$ xxd /dev/sda | head -n2 0000000: eb48 9000 0000 0000 0000 0000 0000 0000 .H.............. 0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ sh-4.1$ ls -l /dev/sda brw-rw---- 1 root disk 8, 0 Jul 8 11:54 /dev/sda sh-4.1$ id uid=3D100(qemu00) gid=3D100(users) groups=3D100(users),0(root),1(bin),2(d= aemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),26(tape),27(video) To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/807893/+subscriptions