mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Edward Adam Davis <eadavis@qq.com>
To: syzbot+9b4adfed366b14496e7e@syzkaller.appspotmail.com
Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [dri?] [media?] memory leak in get_sg_table
Date: Mon,  1 Jan 2024 10:42:58 +0800	[thread overview]
Message-ID: <tencent_1C4C8CE7D046CC52DC0664498C6ED52EDB06@qq.com> (raw)
In-Reply-To: <0000000000009e6825060dd6c287@google.com>

please test memory leak in get_sg_table

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git fbafc3e621c3

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 21916bba77d5..709260211546 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -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;
 
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index c40645999648..ed98c0319e03 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -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;
 }
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index 3f31baa3293f..4316ad0e6155 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -446,6 +446,7 @@ struct dma_buf {
 		struct dma_buf *dmabuf;
 	} *sysfs_entry;
 #endif
+	bool doing;
 };
 
 /**


  parent reply	other threads:[~2024-01-01  2:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31 23:38 syzbot
2024-01-01  2:25 ` Hillf Danton
2024-01-01  2:45   ` syzbot
2024-01-01  2:42 ` Edward Adam Davis [this message]
2024-01-01  3:07   ` syzbot
2024-01-01  4:01 ` Edward Adam Davis
2024-01-01  4:27   ` syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_1C4C8CE7D046CC52DC0664498C6ED52EDB06@qq.com \
    --to=eadavis@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+9b4adfed366b14496e7e@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®