Re: [Security] Fwd: Oops (bad memory deref) in slab_alloc() due tofilp_cachep holding incorrect values

From: Robert ÅwiÄcki
Date: Wed May 25 2011 - 09:26:37 EST


On Wed, May 25, 2011 at 10:28 AM, Eugene Teo <eugeneteo@xxxxxxxxx> wrote:
> Cc'ed David as well.
>
> On Tue, May 24, 2011 at 8:52 PM, Robert ÅwiÄcki <robert@xxxxxxxxxxx> wrote:
>> And the repro - I think this might be exploitable (user-space NULL ptr
>> deref at the first glance, in cap_capable() while in sys_setgid()).
>> Works for me with 2.6.39 and the following config:
>> http://alt.swiecki.net/linux_kernel/ise-test-2.6.39-kernel-config.txt
>>
>> It works for me with apparmor loaded, but looking at the code it
>> should work with SELinux as well (both call cap_capable()). Could be
>> some regression of http://securitytracker.com/id?1024384
>>
>> It works with 2.6.39 but not with 2.6.39-rc4. Found with Tavis
>> Ormandy's http://code.google.com/p/iknowthis/

Given that it doesn't seem to appear in 2.6.39-rc4, and judging by the
names of functions involved, this change looks suspiciously related to
this oops (even if it just made the keyctl problem visible)
http://git.itanic.dy.fi/?p=linux-stable;a=commitdiff;h=47a150edc2ae734c0f4bf50aa19499e23b9a46f8

>> #include <sys/stat.h>
>> #include <sys/wait.h>
>> #include <unistd.h>
>> #include <sys/syscall.h>
>> #include <linux/keyctl.h>
>> #include <linux/sched.h>
>>
>> int TH1(void *dummy) {
>> Â Â Â Âsyscall(__NR_keyctl, KEYCTL_SESSION_TO_PARENT);
>> Â Â Â Âsyscall(__NR_exit, 0);
>> }
>>
>> int main(int argc, char **argv)
>> {
>> Â Â Â Âchar stack[1024 * 32];
>> Â Â Â Âpid_t pid = clone(TH1, stack + sizeof(stack), CLONE_VM, NULL);
>> Â Â Â Âif (pid == -1) {
>> Â Â Â Â Â Â Â Âperror("clone");
>> Â Â Â Â Â Â Â Âreturn -1;
>> Â Â Â Â}
>> Â Â Â Âint status;
>> Â Â Â Âwhile(waitpid(pid, &status, __WALL) != pid);
>> Â Â Â Âsetgid(4286409707);
>> Â Â Â Âreturn 0;
>> }
>>
>> Oops (stacktraces from the previous emails are also valid). Basically
>> 'struct user_namespace *targ_ns' in cap_capable() is NULL.
>>
>> [ Â288.431402] CPU 0
>> [ Â288.431402] Pid: 875, comm: apparmor Not tainted 2.6.39 #1 Dell
>> Inc. Â Â Â Â Â Â Â Â Precision WorkStation 390 Â Â/0GH911
>> [ Â288.431402] RIP: 0010:[<ffffffff8134cbdf>] Â[<ffffffff8134cbdf>]
>> cap_capable+0x18/0x67
>> [ Â288.431402] RSP: 0018:ffff880120d43ec8 ÂEFLAGS: 00010203
>> [ Â288.431402] RAX: ffff8801220ee0c0 RBX: 0000000000000001 RCX: 0000000000000006
>> [ Â288.431402] RDX: 0000000000000000 RSI: ffff880120ebb600 RDI: 0000000000000006
>> [ Â288.431402] RBP: ffff880120d43ec8 R08: 0000000000000001 R09: 000000000000005a
>> [ Â288.431402] R10: ffffffff813d42ea R11: 0000000000000246 R12: ffff880120ebb600
>> [ Â288.431402] R13: 0000000000000006 R14: ffff8801205aaee0 R15: 0000000000000000
>> [ Â288.431402] FS: Â00007f919efc2720(0000) GS:ffff88012bc00000(0000)
>> knlGS:0000000000000000
>> [ Â288.431402] CS: Â0010 DS: 0000 ES: 0000 CR0: 000000008005003b
>> [ Â288.431402] CR2: 0000000000000408 CR3: 00000001205de000 CR4: 00000000000006f0
>> [ Â288.431402] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
>> [ Â288.431402] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
>> [ Â288.431402] Process apparmor (pid: 875, threadinfo
>> ffff880120d42000, task ffff8801205aaee0)
>> [ Â288.431402] Stack:
>> [ Â288.431402] Âffff880120d43f08 ffffffff81378bfb ffff880120d43ee8
>> ffff8801205aaee0
>> [ Â288.431402] Â00000000ff7d6beb ffff880120ebb600 0000000000000000
>> 0000000000000000
>> [ Â288.431402] Âffff880120d43f18 ffffffff8134d932 ffff880120d43f38
>> ffffffff8109d99d
>> [ Â288.431402] Call Trace:
>> [ Â288.431402] Â[<ffffffff81378bfb>] apparmor_capable+0x27/0x61
>> [ Â288.431402] Â[<ffffffff8134d932>] security_capable+0x2a/0x2c
>> [ Â288.431402] Â[<ffffffff8109d99d>] ns_capable+0x3a/0x4f
>> [ Â288.431402] Â[<ffffffff8109da2b>] nsown_capable+0x24/0x29
>> [ Â288.431402] Â[<ffffffff810a6695>] sys_setgid+0x43/0x8d
>> [ Â288.431402] Â[<ffffffff81ed4902>] system_call_fastpath+0x16/0x1b
>> [ Â288.431402] Code: c1 fe 05 d3 e0 48 63 f6 23 44 b2 38 c9 83 f8 01
>> 19 c0 c3 55 48 89 e5 0f 1f 44 00 00 89 cf 48 81 fa f0 16 a2 82 74 0d
>> 48 8b 46 70
>> [ Â288.431402] Â39 82 08 04 00 00 74 3d 48 8b 46 70 48 3b 50 60 75 1d 89 f9
>> [ Â288.431402] RIP Â[<ffffffff8134cbdf>] cap_capable+0x18/0x67
>> [ Â288.431402] ÂRSP <ffff880120d43ec8>
>> [ Â288.431402] CR2: 0000000000000408
>>
>> (gdb) bt
>> #0 Â0xffffffff8134cbdf in cap_capable (tsk=<value optimized out>,
>> cred=0x0, targ_ns=0x0, cap=6, audit=1) at security/commoncap.c:88
>> #1 Â0xffffffff81378bfb in apparmor_capable (task=0xffff880120e3aee0,
>> cred=0xffff88011f540500, ns=<value optimized out>, cap=6, audit=1) at
>> security/apparmor/lsm.c:144
>> #2 Â0xffffffff8134d932 in security_capable (ns=<value optimized out>,
>> cred=<value optimized out>, cap=<value optimized out>) at
>> security/security.c:160
>> #3 Â0xffffffff8109d99d in ns_capable (ns=<value optimized out>,
>> cap=<value optimized out>) at kernel/capability.c:381
>> #4 Â0xffffffff8109da2b in nsown_capable (cap=<value optimized out>) at
>> kernel/capability.c:412
>> #5 Â0xffffffff810a6695 in sys_setgid (gid=1540) at kernel/sys.c:570
>> #6 Â0xffffffff810c1e11 in sys_setgid16 (gid=<value optimized out>) at
>> kernel/uid16.c:53

--
Robert ÅwiÄcki
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/