memory leak in get_sg_table
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: fbafc3e621c3 Merge tag 'for_linus' of git://git.kernel.org.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=10ae11cee80000 kernel config: https://syzkaller.appspot.com/x/.config?x=e81921f96ae24ec0 dashboard link: https://syzkaller.appspot.com/bug?extid=9b4adfed366b14496e7e compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1635d436e80000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15e8171ae80000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/76e4a40f41aa/disk-fbafc3e6.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/a2f88511ce98/vmlinux-fbafc3e6.xz
kernel image: https://storage.googleapis.com/syzbot-assets/2b21933ed8f1/bzImage-fbafc3e6.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Warning: Permanently added '10.128.0.162' (ED25519) to the list of known hosts. executing program
executing program
BUG: memory leak
unreferenced object 0xffff88810af03840 (size 16):
comm "syz-executor111", pid 5038, jiffies 4294942820 (age 13.250s)
hex dump (first 16 bytes):
80 8b 89 0b 81 88 ff ff 04 00 00 00 04 00 00 00 ................
backtrace:
[<ffffffff816346ed>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff816346ed>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff816346ed>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff816346ed>] __kmem_cache_alloc_node+0x2dd/0x3f0 mm/slub.c:3517
[<ffffffff8157f315>] kmalloc_trace+0x25/0x90 mm/slab_common.c:1098
[<ffffffff82cfd7fa>] kmalloc include/linux/slab.h:600 [inline]
[<ffffffff82cfd7fa>] kzalloc include/linux/slab.h:721 [inline]
[<ffffffff82cfd7fa>] get_sg_table.isra.0+0x2a/0xe0 drivers/dma-buf/udmabuf.c:93
[<ffffffff82cfd943>] begin_cpu_udmabuf+0x63/0xa0 drivers/dma-buf/udmabuf.c:156
[<ffffffff82cf114b>] dma_buf_begin_cpu_access+0x3b/0xc0 drivers/dma-buf/dma-buf.c:1402
[<ffffffff82cf1d90>] dma_buf_ioctl+0x550/0x660 drivers/dma-buf/dma-buf.c:475
[<ffffffff816bf4a2>] vfs_ioctl fs/ioctl.c:51 [inline]
[<ffffffff816bf4a2>] __do_sys_ioctl fs/ioctl.c:871 [inline]
[<ffffffff816bf4a2>] __se_sys_ioctl fs/ioctl.c:857 [inline]
[<ffffffff816bf4a2>] __x64_sys_ioctl+0xf2/0x140 fs/ioctl.c:857
[<ffffffff84b71e2f>] do_syscall_x64 arch/x86/entry/common.c:52 [inline]
[<ffffffff84b71e2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:83
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b
BUG: memory leak
unreferenced object 0xffff88810b898b80 (size 128):
comm "syz-executor111", pid 5038, jiffies 4294942820 (age 13.250s)
hex dump (first 32 bytes):
c0 09 2a 04 00 ea ff ff 00 00 00 00 00 10 00 00 ..*.............
00 70 82 0a 01 00 00 00 00 10 00 00 00 00 00 00 .p..............
backtrace:
[<ffffffff816346ed>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff816346ed>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff816346ed>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff816346ed>] __kmem_cache_alloc_node+0x2dd/0x3f0 mm/slub.c:3517
[<ffffffff8157f9bb>] __do_kmalloc_node mm/slab_common.c:1006 [inline]
[<ffffffff8157f9bb>] __kmalloc+0x4b/0x150 mm/slab_common.c:1020
[<ffffffff8251661f>] kmalloc_array include/linux/slab.h:637 [inline]
[<ffffffff8251661f>] sg_kmalloc lib/scatterlist.c:167 [inline]
[<ffffffff8251661f>] get_next_sg lib/scatterlist.c:402 [inline]
[<ffffffff8251661f>] sg_alloc_append_table_from_pages+0x35f/0x770 lib/scatterlist.c:526
[<ffffffff82516abc>] sg_alloc_table_from_pages_segment+0x8c/0x120 lib/scatterlist.c:586
[<ffffffff82cfd82e>] sg_alloc_table_from_pages include/linux/scatterlist.h:477 [inline]
[<ffffffff82cfd82e>] get_sg_table.isra.0+0x5e/0xe0 drivers/dma-buf/udmabuf.c:96
[<ffffffff82cfd943>] begin_cpu_udmabuf+0x63/0xa0 drivers/dma-buf/udmabuf.c:156
[<ffffffff82cf114b>] dma_buf_begin_cpu_access+0x3b/0xc0 drivers/dma-buf/dma-buf.c:1402
[<ffffffff82cf1d90>] dma_buf_ioctl+0x550/0x660 drivers/dma-buf/dma-buf.c:475
[<ffffffff816bf4a2>] vfs_ioctl fs/ioctl.c:51 [inline]
[<ffffffff816bf4a2>] __do_sys_ioctl fs/ioctl.c:871 [inline]
[<ffffffff816bf4a2>] __se_sys_ioctl fs/ioctl.c:857 [inline]
[<ffffffff816bf4a2>] __x64_sys_ioctl+0xf2/0x140 fs/ioctl.c:857
[<ffffffff84b71e2f>] do_syscall_x64 arch/x86/entry/common.c:52 [inline]
[<ffffffff84b71e2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:83
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
On Sun, 31 Dec 2023 15:38:19 -0800
Quoted 3 lines
HEAD commit: fbafc3e621c3 Merge tag 'for_linus' of git://git.kernel.org.. git tree: upstream C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15e8171ae80000
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
drivers/dma-buf/udmabuf.c +6 -1
@@ -153,7 +153,12 @@ static int begin_cpu_udmabuf(struct dma_int ret =0 ;if (!ubuf->sg) { - ubuf->sg =get_sg_table (dev, buf, direction); +static DEFINE_MUTEX (lock); + +mutex_lock (&lock); +if (!ubuf->sg) + ubuf->sg =get_sg_table (dev, buf, direction); +mutex_unlock (&lock);if (IS_ERR (ubuf->sg)) { ret =PTR_ERR (ubuf->sg); ubuf->sg =NULL ;
--
syzbot
syzbotsyzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 610a9b8f Linux 6.7-rc8 git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master console output: https://syzkaller.appspot.com/x/log.txt?x=115abdd9e80000 kernel config: https://syzkaller.appspot.com/x/.config?x=dcb7609da8da79e3 dashboard link: https://syzkaller.appspot.com/bug?extid=9b4adfed366b14496e7e compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=12c685b5e80000
Note: testing is done by a robot and is best-effort only.
please test memory leak in get_sg_table
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git fbafc3e621c3
drivers/dma-buf/dma-buf.c +4 -1
@@ -471,8 +471,11 @@ static long dma_buf_ioctl(struct file *file,if (sync.flags &DMA_BUF_SYNC_END ) ret =dma_buf_end_cpu_access (dmabuf, direction); -else +else { +if (dmabuf->doing) +return -EBUSY ; ret =dma_buf_begin_cpu_access (dmabuf, direction); + }return ret;
drivers/dma-buf/udmabuf.c +2 -0
@@ -152,6 +152,7 @@ static int begin_cpu_udmabuf(struct dma_buf *buf,struct device *dev = ubuf->device->this_device;int ret =0 ; + buf->doing = true;if (!ubuf->sg) { ubuf->sg =get_sg_table (dev, buf, direction);if (IS_ERR (ubuf->sg)) {
@@ -162,6 +163,7 @@ static int begin_cpu_udmabuf(struct dma_buf *buf,dma_sync_sg_for_cpu (dev, ubuf->sg->sgl, ubuf->sg->nents, direction); } + buf->doing = false;return ret; }
include/linux/dma-buf.h +1 -0
@@ -446,6 +446,7 @@ struct dma_buf { struct dma_buf *dmabuf; } *sysfs_entry;#endif +bool doing; };/**
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: memory leak in get_sg_table
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in get_sg_table
2024/01/01 02:58:28 executed programs: 1
BUG: memory leak
unreferenced object 0xffff88811b080600 (size 16):
comm "syz-executor.0", pid 5492, jiffies 4294944266 (age 13.620s)
hex dump (first 16 bytes):
80 22 25 1b 81 88 ff ff 04 00 00 00 04 00 00 00 ."%.............
backtrace:
[<ffffffff816346ed>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff816346ed>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff816346ed>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff816346ed>] __kmem_cache_alloc_node+0x2dd/0x3f0 mm/slub.c:3517
[<ffffffff8157f315>] kmalloc_trace+0x25/0x90 mm/slab_common.c:1098
[<ffffffff82cfd82a>] kmalloc include/linux/slab.h:600 [inline]
[<ffffffff82cfd82a>] kzalloc include/linux/slab.h:721 [inline]
[<ffffffff82cfd82a>] get_sg_table.isra.0+0x2a/0xe0 drivers/dma-buf/udmabuf.c:93
[<ffffffff82cfd986>] begin_cpu_udmabuf+0x76/0xb0 drivers/dma-buf/udmabuf.c:157
[<ffffffff82cf114b>] dma_buf_begin_cpu_access+0x3b/0xc0 drivers/dma-buf/dma-buf.c:1405
[<ffffffff82cf1bd4>] dma_buf_ioctl+0x394/0x690 drivers/dma-buf/dma-buf.c:477
[<ffffffff816bf4a2>] vfs_ioctl fs/ioctl.c:51 [inline]
[<ffffffff816bf4a2>] __do_sys_ioctl fs/ioctl.c:871 [inline]
[<ffffffff816bf4a2>] __se_sys_ioctl fs/ioctl.c:857 [inline]
[<ffffffff816bf4a2>] __x64_sys_ioctl+0xf2/0x140 fs/ioctl.c:857
[<ffffffff84b71e2f>] do_syscall_x64 arch/x86/entry/common.c:52 [inline]
[<ffffffff84b71e2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:83
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b
BUG: memory leak
unreferenced object 0xffff88811b252280 (size 128):
comm "syz-executor.0", pid 5492, jiffies 4294944266 (age 13.620s)
hex dump (first 32 bytes):
00 b1 52 04 00 ea ff ff 00 00 00 00 00 10 00 00 ..R.............
00 40 ac 14 01 00 00 00 00 10 00 00 00 00 00 00 .@..............
backtrace:
[<ffffffff816346ed>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff816346ed>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff816346ed>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff816346ed>] __kmem_cache_alloc_node+0x2dd/0x3f0 mm/slub.c:3517
[<ffffffff8157f9bb>] __do_kmalloc_node mm/slab_common.c:1006 [inline]
[<ffffffff8157f9bb>] __kmalloc+0x4b/0x150 mm/slab_common.c:1020
[<ffffffff8251661f>] kmalloc_array include/linux/slab.h:637 [inline]
[<ffffffff8251661f>] sg_kmalloc lib/scatterlist.c:167 [inline]
[<ffffffff8251661f>] get_next_sg lib/scatterlist.c:402 [inline]
[<ffffffff8251661f>] sg_alloc_append_table_from_pages+0x35f/0x770 lib/scatterlist.c:526
[<ffffffff82516abc>] sg_alloc_table_from_pages_segment+0x8c/0x120 lib/scatterlist.c:586
[<ffffffff82cfd85e>] sg_alloc_table_from_pages include/linux/scatterlist.h:477 [inline]
[<ffffffff82cfd85e>] get_sg_table.isra.0+0x5e/0xe0 drivers/dma-buf/udmabuf.c:96
[<ffffffff82cfd986>] begin_cpu_udmabuf+0x76/0xb0 drivers/dma-buf/udmabuf.c:157
[<ffffffff82cf114b>] dma_buf_begin_cpu_access+0x3b/0xc0 drivers/dma-buf/dma-buf.c:1405
[<ffffffff82cf1bd4>] dma_buf_ioctl+0x394/0x690 drivers/dma-buf/dma-buf.c:477
[<ffffffff816bf4a2>] vfs_ioctl fs/ioctl.c:51 [inline]
[<ffffffff816bf4a2>] __do_sys_ioctl fs/ioctl.c:871 [inline]
[<ffffffff816bf4a2>] __se_sys_ioctl fs/ioctl.c:857 [inline]
[<ffffffff816bf4a2>] __x64_sys_ioctl+0xf2/0x140 fs/ioctl.c:857
[<ffffffff84b71e2f>] do_syscall_x64 arch/x86/entry/common.c:52 [inline]
[<ffffffff84b71e2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:83
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6bTested on:
commit: fbafc3e6 Merge tag 'for_linus' of git://git.kernel.org.. git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=13cf2909e80000 kernel config: https://syzkaller.appspot.com/x/.config?x=e81921f96ae24ec0 dashboard link: https://syzkaller.appspot.com/bug?extid=9b4adfed366b14496e7e compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=14778665e80000
please test memory leak in get_sg_table
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git fbafc3e621c3
drivers/dma-buf/dma-buf.c +4 -1
@@ -471,8 +471,11 @@ static long dma_buf_ioctl(struct file *file,if (sync.flags &DMA_BUF_SYNC_END ) ret =dma_buf_end_cpu_access (dmabuf, direction); -else +else { +if (dmabuf->doing) +return -EBUSY ; ret =dma_buf_begin_cpu_access (dmabuf, direction); + }return ret;
drivers/dma-buf/udmabuf.c +5 -0
@@ -151,7 +151,10 @@ static int begin_cpu_udmabuf(struct dma_buf *buf,struct udmabuf *ubuf = buf->priv;struct device *dev = ubuf->device->this_device;int ret =0 ; +static DEFINE_MUTEX (lock); +mutex_lock (&lock); + buf->doing = true;if (!ubuf->sg) { ubuf->sg =get_sg_table (dev, buf, direction);if (IS_ERR (ubuf->sg)) {
@@ -162,6 +165,8 @@ static int begin_cpu_udmabuf(struct dma_buf *buf,dma_sync_sg_for_cpu (dev, ubuf->sg->sgl, ubuf->sg->nents, direction); } + buf->doing = false; +mutex_unlock (&lock);return ret; }
include/linux/dma-buf.h +1 -0
@@ -446,6 +446,7 @@ struct dma_buf { struct dma_buf *dmabuf; } *sysfs_entry;#endif +bool doing; };/**
syzbot
syzbotsyzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: fbafc3e6 Merge tag 'for_linus' of git://git.kernel.org.. git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=103d8899e80000 kernel config: https://syzkaller.appspot.com/x/.config?x=e81921f96ae24ec0 dashboard link: https://syzkaller.appspot.com/bug?extid=9b4adfed366b14496e7e compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=113c3829e80000
Note: testing is done by a robot and is best-effort only.