esas2r: fix possible array out-of-bounds caused by bad DMA value in esas2r_process_vda_ioctl()
Subsystems (3)
PATCH v2 1/1 esas2r: fix possible array out-of-bounds caused by bad DMA value in esas2r_process_vda_ioctl()
In line 1854 of the file esas2r_ioctl.c, the function esas2r_process_vda_ioctl() is called with the parameter vi being assigned the value of a->vda_buffer. On line 1892, a->vda_buffer is stored in DMA memory with the statementa->vda_buffer = dma_alloc_coherent(&a->pcid->dev, ..., indicating that the parameter vi passed to the function is also stored in DMA memory. This suggests that the parameter vi could be altered at any time by malicious hardware. If vi’s value is changed after the first conditional check if (vi->function >= vercnt), it is likely that an array out-of-bounds access could occur in the subsequent check
if (vi->version > esas2r_vdaioctl_versions[vi_function]), leading to serious issues.
To fix this issue, we will store the value of vi->function in a local variable to ensure that the subsequent checks remain valid.
---
V2:
Changed the incorrect patch title
--- drivers/scsi/esas2r/esas2r_vda.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/scsi/esas2r/esas2r_vda.c +6 -5
@@ -70,16 +70,17 @@ bool esas2r_process_vda_ioctl(struct esas2r_adapter *a,u32 datalen =0 ;struct atto_vda_sge *firstsg =NULL ;u8 vercnt = (u8 )ARRAY_SIZE (esas2r_vdaioctl_versions); +u8 vi_function = vi->function; vi->status =ATTO_STS_SUCCESS ; vi->vda_status =RS_PENDING ; -if (vi->function >= vercnt) { +if (vi_function >= vercnt) { vi->status =ATTO_STS_INV_FUNC ;return false; } -if (vi->version > esas2r_vdaioctl_versions[vi->function]) { +if (vi->version > esas2r_vdaioctl_versions[vi_function]) { vi->status =ATTO_STS_INV_VERSION ;return false; }
@@ -89,14 +90,14 @@ bool esas2r_process_vda_ioctl(struct esas2r_adapter *a,return false; } -if (vi->function !=VDA_FUNC_SCSI ) +if (vi_function !=VDA_FUNC_SCSI )clear_vda_request (rq); - rq->vrq->scsi.function = vi->function; + rq->vrq->scsi.function = vi_function; rq->interrupt_cb = esas2r_complete_vda_ioctl; rq->interrupt_cx = vi; -switch (vi->function) { +switch (vi_function) {case VDA_FUNC_FLASH : if (vi->cmd.flash.sub_func != VDA_FLASH_FREAD
Signature · 1 line
2.34.1
James Bottomley
maintainerQuoted 8 lines · Qiu-ji Chen
In line 1854 of the file
esas2r_ioctl.c, the functionesas2r_process_vda_ioctl()is called with the parameter vi being assigned the value ofa->vda_buffer. On line 1892,a->vda_bufferis stored in DMA memory with the statementa->vda_buffer= dma_alloc_coherent(&a->pcid->dev, ..., indicating that the parameter vi passed to the function is also stored in DMA memory. This suggests that the parameter vi could be altered at any time by malicious hardware.
Absent a specific threat (such as TPM with an interposer) this isn't a vector the kernel protects against (we have to believe what hardware says unless we know it to be specifically buggy about something). However, even supposing a PCI Interposer were considered a threat, the answer now is hardware based: SPDM/PCI-IDE.
Regards,
James