Re: [syzbot] [dri?] [media?] memory leak in get_sg_table

Hillf Danton
2024-01-01T02:28:09Z

On Sun, 31 Dec 2023 15:38:19 -0800
> 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

--- x/drivers/dma-buf/udmabuf.c
+++ y/drivers/dma-buf/udmabuf.c
@@ -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;
--