Skip to content

Commit e11452e

Browse files
committed
dmaengine: idxd: add a new security check to deal with a hardware erratum
On Sapphire Rapids and related platforms, the DSA and IAA devices have an erratum that causes direct access (for example, by using the ENQCMD or MOVDIR64 instructions) from untrusted applications to be a security problem. To solve this, add a flag to the PCI device enumeration and device structures to indicate the presence/absence of this security exposure. In the mmap() method of the device, this flag is then used to enforce that the user has the CAP_SYS_RAWIO capability. In a future patch, a write() based method will be added that allows untrusted applications submit work to the accelerator, where the kernel can do sanity checking on the user input to ensure secure operation of the accelerator. Signed-off-by: Arjan van de Ven <[email protected]>
1 parent 95feb31 commit e11452e

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

drivers/dma/idxd/cdev.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,18 @@ static int idxd_cdev_mmap(struct file *filp, struct vm_area_struct *vma)
400400
int rc;
401401

402402
dev_dbg(&pdev->dev, "%s called\n", __func__);
403+
404+
/*
405+
* Due to an erratum in some of the devices supported by the driver,
406+
* direct user submission to the device can be unsafe.
407+
* (See the INTEL-SA-01084 security advisory)
408+
*
409+
* For the devices that exhibit this behavior, require that the user
410+
* has CAP_SYS_RAWIO capabilities.
411+
*/
412+
if (!idxd->user_submission_safe && !capable(CAP_SYS_RAWIO))
413+
return -EPERM;
414+
403415
rc = check_vma(wq, vma, __func__);
404416
if (rc < 0)
405417
return rc;

drivers/dma/idxd/idxd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ struct idxd_driver_data {
288288
int evl_cr_off;
289289
int cr_status_off;
290290
int cr_result_off;
291+
bool user_submission_safe;
291292
load_device_defaults_fn_t load_device_defaults;
292293
};
293294

@@ -374,6 +375,8 @@ struct idxd_device {
374375

375376
struct dentry *dbgfs_dir;
376377
struct dentry *dbgfs_evl_file;
378+
379+
bool user_submission_safe;
377380
};
378381

379382
static inline unsigned int evl_ent_size(struct idxd_device *idxd)

drivers/dma/idxd/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static struct idxd_driver_data idxd_driver_data[] = {
4747
.align = 32,
4848
.dev_type = &dsa_device_type,
4949
.evl_cr_off = offsetof(struct dsa_evl_entry, cr),
50+
.user_submission_safe = false, /* See INTEL-SA-01084 security advisory */
5051
.cr_status_off = offsetof(struct dsa_completion_record, status),
5152
.cr_result_off = offsetof(struct dsa_completion_record, result),
5253
},
@@ -57,6 +58,7 @@ static struct idxd_driver_data idxd_driver_data[] = {
5758
.align = 64,
5859
.dev_type = &iax_device_type,
5960
.evl_cr_off = offsetof(struct iax_evl_entry, cr),
61+
.user_submission_safe = false, /* See INTEL-SA-01084 security advisory */
6062
.cr_status_off = offsetof(struct iax_completion_record, status),
6163
.cr_result_off = offsetof(struct iax_completion_record, error_code),
6264
.load_device_defaults = idxd_load_iaa_device_defaults,
@@ -774,6 +776,8 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
774776
dev_info(&pdev->dev, "Intel(R) Accelerator Device (v%x)\n",
775777
idxd->hw.version);
776778

779+
idxd->user_submission_safe = data->user_submission_safe;
780+
777781
return 0;
778782

779783
err_dev_register:

0 commit comments

Comments
 (0)