Skip to contentSkip to conversation

seccomp: fix memory leak on filter attach

PATCH Applied Kees Cook 2 participants 3 messages Apr 16, 2014 Secure computing

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 seccomp: fix memory leak on filter attach

This sets the correct error code when final filter memory is unavailable, and frees the raw filter no matter what.

unreferenced object 0xffff8800d6ea4000 (size 512):
comm "sshd", pid 278, jiffies 4294898315 (age 46.653s) hex dump (first 32 bytes):

    21 00 00 00 04 00 00 00 15 00 01 00 3e 00 00 c0  !...........>...
    06 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00  ........!.......
  backtrace:
    [<ffffffff8151414e>] kmemleak_alloc+0x4e/0xb0
    [<ffffffff811a3a40>] __kmalloc+0x280/0x320
    [<ffffffff8110842e>] prctl_set_seccomp+0x11e/0x3b0
    [<ffffffff8107bb6b>] SyS_prctl+0x3bb/0x4a0
    [<ffffffff8152ef2d>] system_call_fastpath+0x1a/0x1f
    [<ffffffffffffffff>] 0xffffffffffffffff

---
David, since you just pushed the a0-a5 fix, can you push this fix as well?

v2:
- drop stable cc, not needed.
- added tested-by and acked-by.

---
 kernel/seccomp.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/seccomp.c +2 -0
index 590c37925084..b35c21503a36 100644
@@ -255,6 +255,7 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
 		goto free_prog;
 
 	/* Allocate a new seccomp_filter */
+	ret = -ENOMEM;
 	filter = kzalloc(sizeof(struct seccomp_filter) +
 			 sizeof(struct sock_filter_int) * new_len,
 			 GFP_KERNEL|__GFP_NOWARN);
@@ -264,6 +265,7 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
 	ret = sk_convert_filter(fp, fprog->len, filter->insnsi, &new_len);
 	if (ret)
 		goto free_filter;
+	kfree(fp);
 
 	atomic_set(&filter->usage, 1);
 	filter->len = new_len;
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
Applied
#1 lore raw

From: Kees Cook <[email protected]>
Date: Wed, 16 Apr 2014 10:54:34 -0700

Quoted 16 lines

This sets the correct error code when final filter memory is unavailable, and frees the raw filter no matter what.

unreferenced object 0xffff8800d6ea4000 (size 512):
comm "sshd", pid 278, jiffies 4294898315 (age 46.653s) hex dump (first 32 bytes):

    21 00 00 00 04 00 00 00 15 00 01 00 3e 00 00 c0  !...........>...
    06 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00  ........!.......
  backtrace:
    [<ffffffff8151414e>] kmemleak_alloc+0x4e/0xb0
    [<ffffffff811a3a40>] __kmalloc+0x280/0x320
    [<ffffffff8110842e>] prctl_set_seccomp+0x11e/0x3b0
    [<ffffffff8107bb6b>] SyS_prctl+0x3bb/0x4a0
    [<ffffffff8152ef2d>] system_call_fastpath+0x1a/0x1f
    [<ffffffffffffffff>] 0xffffffffffffffff
Quoted 6 lines

---
David, since you just pushed the a0-a5 fix, can you push this fix as well?

Applied, but please in the future CC: netdev on patches you want me to apply so that they get properly a) reviewed and b) queued up in patchwork.

Thanks.

author
#2 lore raw
Quoted 26 lines · David Miller

From: Kees Cook <[email protected]>
Date: Wed, 16 Apr 2014 10:54:34 -0700

Quoted 16 lines

This sets the correct error code when final filter memory is unavailable, and frees the raw filter no matter what.

unreferenced object 0xffff8800d6ea4000 (size 512):
comm "sshd", pid 278, jiffies 4294898315 (age 46.653s) hex dump (first 32 bytes):

    21 00 00 00 04 00 00 00 15 00 01 00 3e 00 00 c0  !...........>...
    06 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00  ........!.......
  backtrace:
    [<ffffffff8151414e>] kmemleak_alloc+0x4e/0xb0
    [<ffffffff811a3a40>] __kmalloc+0x280/0x320
    [<ffffffff8110842e>] prctl_set_seccomp+0x11e/0x3b0
    [<ffffffff8107bb6b>] SyS_prctl+0x3bb/0x4a0
    [<ffffffff8152ef2d>] system_call_fastpath+0x1a/0x1f
    [<ffffffffffffffff>] 0xffffffffffffffff
Quoted 6 lines

---
David, since you just pushed the a0-a5 fix, can you push this fix as well?

Quoted 2 lines

Applied, but please in the future CC: netdev on patches you want me to apply so that they get properly a) reviewed and b) queued up in patchwork.

Ah! Yes, sorry for the oversight on that. Thanks for taking it!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security