mirror of
https://github.com/torvalds/linux.git
synced 2026-09-26 01:52:03 +02:00
iommu/amd: Fix undefined behavior in devid_write debugfs function
When for_each_pci_segment() loop completes without finding a matching
segment, the pci_seg pointer is not NULL but points to an invalid memory
location (the list head). Accessing pci_seg->id after the loop causes
undefined behavior.
Fix this by handling the successful case inside the loop and returning
-EINVAL after the loop if no matching segment is found.
Fixes: 2e98940f12 ("iommu/amd: Add support for device id user input")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Ankit Soni <Ankit.Soni@amd.com>
Signed-off-by: Will Deacon <will@kernel.org>
This commit is contained in:
parent
16f52863b2
commit
843e149989
|
|
@ -176,19 +176,13 @@ static ssize_t devid_write(struct file *filp, const char __user *ubuf,
|
|||
kfree(srcid_ptr);
|
||||
return -ENODEV;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (pci_seg->id != seg) {
|
||||
sbdf = PCI_SEG_DEVID_TO_SBDF(seg, devid);
|
||||
kfree(srcid_ptr);
|
||||
return -EINVAL;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
sbdf = PCI_SEG_DEVID_TO_SBDF(seg, devid);
|
||||
|
||||
kfree(srcid_ptr);
|
||||
|
||||
return cnt;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int devid_show(struct seq_file *m, void *unused)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user