Skip to contentSkip to conversation

dmaengine: idxd: Fix allowing write() from different address spaces

PATCH In review Vinicius Costa Gomes 3 participants 4 messages Apr 16, 2025 – Apr 21, 2025

Subsystems (2)
lore
Share & tools
lore

Vinicius Costa Gomes

author maintainer
#0 lore raw

PATCH 1/1 dmaengine: idxd: Fix allowing write() from different address spaces

Check if the process submitting the descriptor belongs to the same address space as the one that opened the file, reject otherwise.

Fixes 6827738dc684 ("dmaengine: idxd: add a write() method for applications to submit work")
---
 drivers/dma/idxd/cdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dma/idxd/cdev.c +3 -0
index ff94ee892339..373c622fcddc 100644
@@ -473,6 +473,9 @@ static ssize_t idxd_cdev_write(struct file *filp, const char __user *buf, size_t
 	ssize_t written = 0;
 	int i;
 
+	if (current->mm != ctx->mm)
+		return -EPERM;
+
 	for (i = 0; i < len/sizeof(struct dsa_hw_desc); i++) {
 		int rc = idxd_submit_user_descriptor(ctx, udesc + i);
 
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Vinicius Costa Gomes

Check if the process submitting the descriptor belongs to the same address space as the one that opened the file, reject otherwise.

Fixes 6827738dc684 ("dmaengine: idxd: add a write() method for applications to submit work")
Quoted 18 lines
---
 drivers/dma/idxd/cdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dma/idxd/cdev.c +3 -0
index ff94ee892339..373c622fcddc 100644
@@ -473,6 +473,9 @@ static ssize_t idxd_cdev_write(struct file *filp, const char __user *buf, size_t
 	ssize_t written = 0;
 	int i;
 
+	if (current->mm != ctx->mm)
+		return -EPERM;
+
 	for (i = 0; i < len/sizeof(struct dsa_hw_desc); i++) {
 		int rc = idxd_submit_user_descriptor(ctx, udesc + i);
 
#2 lore raw
In reply to Vinicius Costa Gomes
Quoted 2 lines · Vinicius Costa Gomes

Check if the process submitting the descriptor belongs to the same address space as the one that opened the file, reject otherwise.

I assume this can happen after a fork.

Do idxd_cdev_mmap() and idxd_cdev_poll() need similar protection?

Quoted 23 lines
Fixes 6827738dc684 ("dmaengine: idxd: add a write() method for applications to submit work")
---
 drivers/dma/idxd/cdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dma/idxd/cdev.c +3 -0
index ff94ee892339..373c622fcddc 100644
@@ -473,6 +473,9 @@ static ssize_t idxd_cdev_write(struct file *filp, const char __user *buf, size_t
 	ssize_t written = 0;
 	int i;
 
+	if (current->mm != ctx->mm)
+		return -EPERM;
+
 	for (i = 0; i < len/sizeof(struct dsa_hw_desc); i++) {
 		int rc = idxd_submit_user_descriptor(ctx, udesc + i);
 
Signature · 1 line
2.49.0
reviewer
#3 lore raw
Quoted 7 lines · Nathan Lynch
Quoted 2 lines · Vinicius Costa Gomes

Check if the process submitting the descriptor belongs to the same address space as the one that opened the file, reject otherwise.

I assume this can happen after a fork.

Do idxd_cdev_mmap() and idxd_cdev_poll() need similar protection?

Seems reasonable. Vinicius is on sabbatical. I'll respin his code and add the suggested checks. Thanks Nathan.

DJ

Quoted 24 lines
Quoted 24 lines
Fixes 6827738dc684 ("dmaengine: idxd: add a write() method for applications to submit work")
---
 drivers/dma/idxd/cdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dma/idxd/cdev.c +3 -0
index ff94ee892339..373c622fcddc 100644
@@ -473,6 +473,9 @@ static ssize_t idxd_cdev_write(struct file *filp, const char __user *buf, size_t
 	ssize_t written = 0;
 	int i;
 
+	if (current->mm != ctx->mm)
+		return -EPERM;
+
 	for (i = 0; i < len/sizeof(struct dsa_hw_desc); i++) {
 		int rc = idxd_submit_user_descriptor(ctx, udesc + i);
 
Signature · 1 line
2.49.0