Skip to contentSkip to conversation

dmaengine: idxd: Do not enable user type Work Queue without Shared Virtual Addressing

PATCH Superseded Fenghua Yu 3 participants 4 messages Oct 12, 2022 – Oct 14, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 dmaengine: idxd: Do not enable user type Work Queue without Shared Virtual Addressing

Userspace can directly access physical address through user type Work Queue (WQ) in two scenarios: no IOMMU or IOMMU Passthrough without Shared Virtual Addressing (SVA). In these two cases, user type WQ allows userspace to issue DMA physical address access without virtual to physical translation.

This is inconsistent with the security goals of a good kernel API.

Plus there is no usage for user type WQ without SVA.

So enable user type WQ only when SVA is enabled (i.e. user PASID is enabled).

Fixes 42d279f9137a ("dmaengine: idxd: add char driver to expose submission portal to userland")
---
 drivers/dma/idxd/cdev.c   | 14 ++++++++++++++
 include/uapi/linux/idxd.h |  1 +
 2 files changed, 15 insertions(+)
drivers/dma/idxd/cdev.c +14 -0
index c2808fd081d6..4cd3400c5a48 100644
@@ -312,6 +312,20 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
 	if (idxd->state != IDXD_DEV_ENABLED)
 		return -ENXIO;
 
+	/*
+	 * User type WQ is enabled only when SVA is enabled for two reasons:
+	 *   - If no IOMMU or IOMMU Passthrough without SVA, userspace
+	 *     can directly access physical address through the WQ.
+	 *   - There is no usage case for the WQ without SVA.
+	 */
+	if (!device_user_pasid_enabled(idxd)) {
+		idxd->cmd_status = IDXD_SCMD_WQ_USER_NO_IOMMU;
+		dev_dbg(&idxd->pdev->dev,
+			"User type WQ cannot be enabled without SVA.\n");
+
+		return -EOPNOTSUPP;
+	}
+
 	mutex_lock(&wq->wq_lock);
 	wq->type = IDXD_WQT_USER;
 	rc = drv_enable_wq(wq);
include/uapi/linux/idxd.h +1 -0
index 095299c75828..2b9e7feba3f3 100644
@@ -29,6 +29,7 @@ enum idxd_scmd_stat {
 	IDXD_SCMD_WQ_NO_SIZE = 0x800e0000,
 	IDXD_SCMD_WQ_NO_PRIV = 0x800f0000,
 	IDXD_SCMD_WQ_IRQ_ERR = 0x80100000,
+	IDXD_SCMD_WQ_USER_NO_IOMMU = 0x80110000,
 };
 
 #define IDXD_SCMD_SOFTERR_MASK	0x80000000
Signature · 1 line
2.32.0
#1 lore raw
FYI: kernel test robot notices the stable kernel rule is not satisfied.

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

Rule: 'Cc: [email protected]' or 'commit <sha1> upstream.'
Subject: [PATCH] dmaengine: idxd: Do not enable user type Work Queue without Shared Virtual Addressing

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#2 lore raw
In reply to Fenghua Yu
Quoted 6 lines · Fenghua Yu

Userspace can directly access physical address through user type Work Queue (WQ) in two scenarios: no IOMMU or IOMMU Passthrough without Shared Virtual Addressing (SVA). In these two cases, user type WQ allows userspace to issue DMA physical address access without virtual to physical translation.

Quoted 6 lines

This is inconsistent with the security goals of a good kernel API.

Plus there is no usage for user type WQ without SVA.

So enable user type WQ only when SVA is enabled (i.e. user PASID is enabled).

I'm not sure the changelog here is great.

The whole "user Work Queue" thing is an entire *DRIVER*. So, this really has zero to do with the type of workqueue and everything to do with the kind of drivers we allow to be loaded and drive the hardware.

Basically, the *hardware* allows pretty arbitrary direct access to physical memory. The 'idxd_user_drv' driver code (including idxd_user_drv_probe()) gives low-level, direct access to the hardware, which is bad news.

Plus, even if userspace got access to the device via this driver, they have to feel physical addresses to it, which is generally not easy from userspace.

That's as close as I can get to rephrasing the above TLA soup in plain old English.

I also detest the "There is no usage case for the WQ without SVA." language. Those words lack meaning. There has to be a *REASON* there is no use case. Please think about what those words *mean*, then delete them and write what they mean.

#3 lore raw

Hi, Dave,

Quoted 28 lines · Dave Hansen
Quoted 6 lines · Fenghua Yu

Userspace can directly access physical address through user type Work Queue (WQ) in two scenarios: no IOMMU or IOMMU Passthrough without Shared Virtual Addressing (SVA). In these two cases, user type WQ allows userspace to issue DMA physical address access without virtual to physical translation.

Quoted 6 lines

This is inconsistent with the security goals of a good kernel API.

Plus there is no usage for user type WQ without SVA.

So enable user type WQ only when SVA is enabled (i.e. user PASID is enabled).

I'm not sure the changelog here is great.

The whole "user Work Queue" thing is an entire *DRIVER*. So, this really has zero to do with the type of workqueue and everything to do with the kind of drivers we allow to be loaded and drive the hardware.

Basically, the *hardware* allows pretty arbitrary direct access to physical memory. The 'idxd_user_drv' driver code (including idxd_user_drv_probe()) gives low-level, direct access to the hardware, which is bad news.

Plus, even if userspace got access to the device via this driver, they have to feel physical addresses to it, which is generally not easy from userspace.

Quoted 6 lines

That's as close as I can get to rephrasing the above TLA soup in plain old English.

I also detest the "There is no usage case for the WQ without SVA." language. Those words lack meaning. There has to be a *REASON* there is no use case. Please think about what those words *mean*, then delete them and write what they mean.

I'm working on changing the changelog and will send v2 with the changes.

Thanks.

-Fenghua