memory leak in lapb_create_cb

27 views
Skip to first unread message

Dmitry Vyukov

unread,
Dec 30, 2015, 4:01:04 PM12/30/15
to David S. Miller, linu...@vger.kernel.org, netdev, LKML, Peter Hurley, Greg Kroah-Hartman, Jiri Slaby, syzkaller, Kostya Serebryany, Alexander Potapenko, Sasha Levin, Eric Dumazet
Hello,

The following program leads to a leak of struct lapb_cb:

// autogenerated by syzkaller (http://github.com/google/syzkaller)
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdint.h>

int main()
{
syscall(SYS_mmap, 0x20000000ul, 0x10000ul, 0x3ul, 0x32ul,
0xfffffffffffffffful, 0x0ul);
int fd = syscall(SYS_open, "/dev/ptmx", 0x103002ul, 0x0ul, 0, 0, 0);
*(uint32_t*)0x20001000 = (uint32_t)0x6;
syscall(SYS_ioctl, fd, 0x5423ul, 0x20001000ul, 0, 0, 0);
*(uint32_t*)0x20006ff8 = (uint32_t)0x1;
*(uint8_t*)0x20006ffc = (uint8_t)0x29c;
*(uint8_t*)0x20006ffd = (uint8_t)0x3;
*(uint8_t*)0x20006ffe = (uint8_t)0x4;
*(uint8_t*)0x20006fff = (uint8_t)0x8;
*(uint8_t*)0x20007000 = (uint8_t)0x3;
*(uint8_t*)0x20007001 = (uint8_t)0x1;
syscall(SYS_ioctl, fd, 0x400442c9ul, 0x20006ff8ul, 0, 0, 0);
*(uint8_t*)0x20006f64 = (uint8_t)0xe7;
*(uint8_t*)0x20006f65 = (uint8_t)0xfb49;
*(uint16_t*)0x20006f66 = (uint16_t)0x3;
syscall(SYS_ioctl, fd, 0x4b46ul, 0x20006f64ul, 0, 0, 0);
*(uint16_t*)0x20003000 = (uint16_t)0x8;
*(uint16_t*)0x20003002 = (uint16_t)0x5;
*(uint16_t*)0x20003004 = (uint16_t)0x8;
*(uint16_t*)0x20003006 = (uint16_t)0x3;
*(uint8_t*)0x20003008 = (uint8_t)0x6;
*(uint8_t*)0x20003009 = (uint8_t)0x4b8;
*(uint8_t*)0x2000300a = (uint8_t)0x2;
*(uint8_t*)0x2000300b = (uint8_t)0x1;
*(uint32_t*)0x2000300c = (uint32_t)0x5;
*(uint8_t*)0x20003010 = (uint8_t)0x802;
syscall(SYS_ioctl, fd, 0x5404ul, 0x20003000ul, 0, 0, 0);
return 0;
}


unreferenced object 0xffff8800633575d0 (size 512):
comm "softirq", pid 0, jiffies 4299764624 (age 16.395s)
hex dump (first 32 bytes):
00 01 00 00 00 00 ad de 00 02 00 00 00 00 ad de ................
c0 a3 d4 34 00 88 ff ff 00 00 00 00 00 00 00 00 ...4............
backtrace:
[<ffffffff85c73a22>] kmemleak_alloc+0x72/0xc0 mm/kmemleak.c:915
[< inline >] kmemleak_alloc_recursive include/linux/kmemleak.h:47
[< inline >] slab_post_alloc_hook mm/slub.c:1335
[< inline >] slab_alloc_node mm/slub.c:2594
[< inline >] slab_alloc mm/slub.c:2602
[<ffffffff816cc6f8>] kmem_cache_alloc_trace+0x138/0x2f0 mm/slub.c:2619
[< inline >] kzalloc include/linux/slab.h:458
[< inline >] lapb_create_cb net/lapb/lapb_iface.c:121
[<ffffffff852ec5ea>] lapb_register+0xfa/0x590 net/lapb/lapb_iface.c:158
[< inline >] x25_asy_open drivers/net/wan/x25_asy.c:485
[<ffffffff83a69351>] x25_asy_open_tty+0x431/0x740
drivers/net/wan/x25_asy.c:573
[<ffffffff82bacd58>] tty_ldisc_open.isra.2+0x78/0xd0
drivers/tty/tty_ldisc.c:447
[<ffffffff82bad41a>] tty_set_ldisc+0x1ca/0xa30 drivers/tty/tty_ldisc.c:567
[< inline >] tiocsetd drivers/tty/tty_io.c:2650
[<ffffffff82b9481a>] tty_ioctl+0xb2a/0x2160 drivers/tty/tty_io.c:2883
[< inline >] vfs_ioctl fs/ioctl.c:43
[<ffffffff81750d41>] do_vfs_ioctl+0x681/0xe40 fs/ioctl.c:607
[< inline >] SYSC_ioctl fs/ioctl.c:622
[<ffffffff8175158f>] SyS_ioctl+0x8f/0xc0 fs/ioctl.c:613
[<ffffffff85c8eaf6>] entry_SYSCALL_64_fastpath+0x16/0x7a
arch/x86/entry/entry_64.S:185
[<ffffffffffffffff>] 0xffffffffffffffff


On commit 8513342170278468bac126640a5d2d12ffbff106 (Dec 28).

David Miller

unread,
Jan 13, 2016, 11:46:38 AM1/13/16
to dvy...@google.com, linu...@vger.kernel.org, net...@vger.kernel.org, linux-...@vger.kernel.org, pe...@hurleysoftware.com, gre...@linuxfoundation.org, jsl...@suse.com, syzk...@googlegroups.com, k...@google.com, gli...@google.com, sasha...@oracle.com, edum...@google.com
From: Dmitry Vyukov <dvy...@google.com>
Date: Wed, 30 Dec 2015 22:00:44 +0100

> The following program leads to a leak of struct lapb_cb:

I looked into this report a bit, and although I couldn't figure out
how lapb_cb could be leaked, I definitely found an x25_asy object
leak in this driver.

====================
[PATCH] x25_asy: Free x25_asy on x25_asy_open() failure.

Based upon a report by Dmitry Vyukov.

Signed-off-by: David S. Miller <da...@davemloft.net>
---
drivers/net/wan/x25_asy.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
index cd39025..1bc5e93 100644
--- a/drivers/net/wan/x25_asy.c
+++ b/drivers/net/wan/x25_asy.c
@@ -571,8 +571,10 @@ static int x25_asy_open_tty(struct tty_struct *tty)

/* Perform the low-level X.25 async init */
err = x25_asy_open(sl->dev);
- if (err)
+ if (err) {
+ x25_asy_free(sl);
return err;
+ }
/* Done. We have linked the TTY line to a channel. */
return 0;
}
--
2.1.0

Reply all
Reply to author
Forward
0 new messages