Skip to contentSkip to conversation

iommu/amd: Use array_index_nospec() for rlookup_table index

PATCH In review Dheeraj Kumar Srivastava 2 participants 4 messages Jan 9

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

PATCH 1/1 iommu/amd: Use array_index_nospec() for rlookup_table index

Use array_index_nospec() to prevent speculative out-of-bounds access when indexing pci_seg->rlookup_table with a user provided device id.

---
 drivers/iommu/amd/debugfs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/amd/debugfs.c +1 -0
index 10fa217a7119..4990f6db99ef 100644
@@ -174,6 +174,7 @@ static ssize_t devid_write(struct file *filp, const char __user *ubuf,
 			kfree(srcid_ptr);
 			return -EINVAL;
 		}
+		devid = array_index_nospec(devid, (u32)pci_seg->last_bdf + 1);
 		iommu = pci_seg->rlookup_table[devid];
 		if (!iommu) {
 			kfree(srcid_ptr);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Dheeraj Kumar Srivastava

Use array_index_nospec() to prevent speculative out-of-bounds access when indexing pci_seg->rlookup_table with a user provided device id.

This is interesting because more and more people are using lei to recieve email and now they get unfiltered Smatch warnings from zero day bot.

Normally, I just ignore these warnings because they're hard to review and I recently modified Smatch to stop the zero day bot from warning about them.

The problem is that I've tried to contact people from Intel to help review some of the warnings but I've never recieved a response. I've heard that Intel has a handful of people that deal with Spectre v1 bugs but I've never seen any evidence of that... I've never tried reaching out to AMD.

drivers/iommu/amd/debugfs.c static ssize_t devid_write(struct file *filp, const char __user *ubuf, · line 177

Quoted 13 lines
---
 drivers/iommu/amd/debugfs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/amd/debugfs.c +1 -0
index 10fa217a7119..4990f6db99ef 100644
@@ -174,6 +174,7 @@ static ssize_t devid_write(struct file *filp, const char __user *ubuf,
 			kfree(srcid_ptr);
 			return -EINVAL;
 		}
+		devid = array_index_nospec(devid, (u32)pci_seg->last_bdf + 1);

This is debugfs so it's already root only. The cast to (u32) is unnecessary.

regards,
dan carpenter

Quoted 5 lines
drivers/iommu/amd/debugfs.c +0 -0
 		iommu = pci_seg->rlookup_table[devid];
 		if (!iommu) {
 			kfree(srcid_ptr);
Signature · 1 line
2.25.1
#2 lore raw

Hi Dan,

Quoted 29 lines · Dan Carpenter
Quoted 9 lines · Dheeraj Kumar Srivastava

Use array_index_nospec() to prevent speculative out-of-bounds access when indexing pci_seg->rlookup_table with a user provided device id.

This is interesting because more and more people are using lei to recieve email and now they get unfiltered Smatch warnings from zero day bot.

Normally, I just ignore these warnings because they're hard to review and I recently modified Smatch to stop the zero day bot from warning about them.

The problem is that I've tried to contact people from Intel to help review some of the warnings but I've never recieved a response. I've heard that Intel has a handful of people that deal with Spectre v1 bugs but I've never seen any evidence of that... I've never tried reaching out to AMD.

Quoted 4 lines
---
  drivers/iommu/amd/debugfs.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/iommu/amd/debugfs.c static ssize_t devid_write(struct file *filp, const char __user *ubuf, · line 177

Quoted 9 lines
drivers/iommu/amd/debugfs.c +1 -0
index 10fa217a7119..4990f6db99ef 100644
@@ -174,6 +174,7 @@ static ssize_t devid_write(struct file *filp, const char __user *ubuf,
  			kfree(srcid_ptr);
  			return -EINVAL;
  		}
+		devid = array_index_nospec(devid, (u32)pci_seg->last_bdf + 1);

This is debugfs so it's already root only. The cast to (u32) is unnecessary.

I agree that the (u32) cast is unnecessary here and will remove it.

When you mentioned that this is debugfs and therefore root-only, could you clarify the context of that comment? I just want to make sure I’m interpreting the rationale correctly.

Thanks
Dheeraj

Quoted 8 lines

regards,
dan carpenter

Quoted 5 lines
drivers/iommu/amd/debugfs.c +0 -0
  		iommu = pci_seg->rlookup_table[devid];
  		if (!iommu) {
  			kfree(srcid_ptr);
Signature · 1 line
2.25.1
#3 lore raw
Quoted 46 lines · Dheeraj Kumar Srivastava

Hi Dan,

Quoted 29 lines · Dan Carpenter
Quoted 9 lines · Dheeraj Kumar Srivastava

Use array_index_nospec() to prevent speculative out-of-bounds access when indexing pci_seg->rlookup_table with a user provided device id.

This is interesting because more and more people are using lei to recieve email and now they get unfiltered Smatch warnings from zero day bot.

Normally, I just ignore these warnings because they're hard to review and I recently modified Smatch to stop the zero day bot from warning about them.

The problem is that I've tried to contact people from Intel to help review some of the warnings but I've never recieved a response. I've heard that Intel has a handful of people that deal with Spectre v1 bugs but I've never seen any evidence of that... I've never tried reaching out to AMD.

Quoted 4 lines
---
  drivers/iommu/amd/debugfs.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/iommu/amd/debugfs.c static ssize_t devid_write(struct file *filp, const char __user *ubuf, · line 177

Quoted 9 lines
drivers/iommu/amd/debugfs.c +1 -0
index 10fa217a7119..4990f6db99ef 100644
@@ -174,6 +174,7 @@ static ssize_t devid_write(struct file *filp, const char __user *ubuf,
  			kfree(srcid_ptr);
  			return -EINVAL;
  		}
+		devid = array_index_nospec(devid, (u32)pci_seg->last_bdf + 1);

This is debugfs so it's already root only. The cast to (u32) is unnecessary.

Quoted 6 lines

I agree that the (u32) cast is unnecessary here and will remove it.

When you mentioned that this is debugfs and therefore root-only, could you clarify the context of that comment? I just want to make sure I’m interpreting the rationale correctly.

Debugfs is always read only unless you are root. Anything else is insane. So it's like sure, this patch is correct from a correctness point of view but in terms of is this exploitable? No.

regards,
dan carpenter