All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-buf: Fix possible UAF in dma_buf_export
@ 2022-11-17  6:21 ` Gaosheng Cui
  0 siblings, 0 replies; 28+ messages in thread
From: Gaosheng Cui @ 2022-11-17  6:21 UTC (permalink / raw)
  To: sumit.semwal, christian.koenig, tjmercier, quic_charante, cuigaosheng1
  Cc: linux-media, dri-devel, linaro-mm-sig

Smatch report warning as follows:

drivers/dma-buf/dma-buf.c:681 dma_buf_export() warn:
  '&dmabuf->list_node' not removed from list

If dma_buf_stats_setup() fails in dma_buf_export(), goto err_sysfs
and dmabuf will be freed, but dmabuf->list_node will not be removed
from db_list.head, then list traversal may cause UAF.

Fix by removeing it from db_list.head before free().

Fixes: ef3a6b70507a ("dma-buf: call dma_buf_stats_setup after dmabuf is in valid list")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/dma-buf/dma-buf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index b809513b03fe..6848f50226d5 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -675,6 +675,9 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 	return dmabuf;
 
 err_sysfs:
+	mutex_lock(&db_list.lock);
+	list_del(&dmabuf->list_node);
+	mutex_unlock(&db_list.lock);
 	/*
 	 * Set file->f_path.dentry->d_fsdata to NULL so that when
 	 * dma_buf_release() gets invoked by dentry_ops, it exits
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2022-12-06 13:10 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17  6:21 [PATCH] dma-buf: Fix possible UAF in dma_buf_export Gaosheng Cui
2022-11-17  6:21 ` Gaosheng Cui
2022-11-17  7:48 ` Charan Teja Kalla
2022-11-17  7:48   ` Charan Teja Kalla
2022-11-17 10:16   ` Christian König
2022-11-17 10:16     ` Christian König
2022-11-18  2:36     ` T.J. Mercier
2022-11-18  2:36       ` T.J. Mercier
2022-11-18  8:27       ` Christian König
2022-11-18  8:27         ` Christian König
2022-11-18 17:05         ` T.J. Mercier
2022-11-19 13:30           ` Christian König
2022-11-24  5:56             ` Charan Teja Kalla
2022-11-24  5:56               ` Charan Teja Kalla
2022-11-24 11:31               ` cuigaosheng
2022-11-24 11:31                 ` cuigaosheng
2022-11-24 12:05               ` cuigaosheng
2022-11-24 12:05                 ` cuigaosheng
2022-11-24 12:37                 ` Christian König
2022-11-24 12:37                   ` Christian König
2022-11-24 12:49                   ` cuigaosheng
2022-11-24 12:49                     ` cuigaosheng
2022-11-24 12:55                     ` [Linaro-mm-sig] " Christian König
2022-11-24 12:55                       ` Christian König
2022-12-06 12:55                       ` Charan Teja Kalla
2022-12-06 12:55                         ` Charan Teja Kalla
2022-12-06 13:08                         ` Christian König
2022-12-06 13:08                           ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.