Skip to contentSkip to conversation

dma-buf: acquire name lock before read/write dma_buf.name

PATCH Superseded [email protected] 1 participant 1 message Oct 8, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dma-buf: acquire name lock before read/write dma_buf.name

From: Guangming Cao <[email protected]>

Because dma-buf.name can be freed in func: "dma_buf_set_name", so, we need to acquire lock first before we read/write dma_buf.name to prevent Use After Free(UAF) issue.

---
 drivers/dma-buf/dma-buf.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/dma-buf/dma-buf.c +5 -0
index 511fe0d217a0..9436483a9cfd 100644
@@ -80,7 +80,9 @@ static void dma_buf_release(struct dentry *dentry)
 		dma_resv_fini(dmabuf->resv);
 
 	module_put(dmabuf->owner);
+	spin_lock(&dmabuf->name_lock);
 	kfree(dmabuf->name);
+	spin_unlock(&dmabuf->name_lock);
 	kfree(dmabuf);
 }
 
@@ -1372,6 +1374,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)
 		if (ret)
 			goto error_unlock;
 
+
+		spin_lock(&buf_obj->name_lock);
 		seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\t%s\n",
 				buf_obj->size,
 				buf_obj->file->f_flags, buf_obj->file->f_mode,
@@ -1379,6 +1383,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)
 				buf_obj->exp_name,
 				file_inode(buf_obj->file)->i_ino,
 				buf_obj->name ?: "");
+		spin_unlock(&buf_obj->name_lock);
 
 		robj = buf_obj->resv;
 		fence = dma_resv_excl_fence(robj);
Signature · 1 line
2.17.1