megaraid_mbox: fix Oops on SG_IO
Subsystems (2)
This patch fixes an Oops in megaraid_mbox that happens when a MODE_SENSE command for a logical drive is started via ioctl(SG_IO).
The problem only occures, if the buffer specified by the user to receive the mode data resides in highmem and if the buffer is aligned for direct dma (no bounce buffer necessary). megaraid_mbox emulates the MODE_SENSE command and writes the data using memset() directly into user buffer. If the buffer is at a currently unmapped highmem page, this leads to an Oops.
The second hunk of the patch is untested! AFAICS, it should fix the same problem at another place. I'm not shure, but maybe other LLDs must be fixed similarly, as they also seem to call sg_virt() without doing kmap before.
Please CC me, I'm not on the list.
---
drivers/scsi/megaraid/megaraid_mbox.c renamed from drivers/scsi/megaraid/megaraid_mbox.c.orig +23 -5
@@ -1580,13 +1580,20 @@ megaraid_mbox_build_cmd(adapter_t *adaptcase MODE_SENSE : {struct scatterlist *sgl; -caddr_t vaddr; +struct page *pg; +unsigned char *vaddr; +unsigned long flags; sgl =scsi_sglist (scp); -if (sg_page (sgl)) { - vaddr = (caddr_t )sg_virt (&sgl[0 ]); + pg =sg_page (sgl); +if (pg) { +local_irq_save (flags); + vaddr =kmap_atomic (pg,KM_BIO_SRC_IRQ ) + sgl->offset;memset (vaddr,0 , scp->cmnd[4 ]); + +kunmap_atomic (vaddr,KM_BIO_SRC_IRQ ); +local_irq_restore (flags); }else { con_log(CL_ANN, (KERN_WARNING
@@ -2324,9 +2331,20 @@ megaraid_mbox_dpc(unsigned long devp)if (scp->cmnd[0 ] ==INQUIRY && status ==0 && islogical ==0 &&IS_RAID_CH (raid_dev, scb->dev_channel)) { +struct page *pg; +unsigned char *vaddr; +unsigned long flags; + sgl =scsi_sglist (scp); -if (sg_page (sgl)) { - c = *(unsigned char *)sg_virt (&sgl[0 ]); + pg =sg_page (sgl); +if (pg) { +local_irq_save (flags); + vaddr =kmap_atomic (pg,KM_BIO_SRC_IRQ ) + sgl->offset; + + c = *vaddr; + +kunmap_atomic (vaddr,KM_BIO_SRC_IRQ ); +local_irq_restore (flags); }else { con_log(CL_ANN, (KERN_WARNING "megaraid mailbox: invalid sg:%d\n",