Skip to content

Commit

Permalink
scsi: lpfc: Revise lpfc_prep_embed_io routine with proper endian macr…
Browse files Browse the repository at this point in the history
…o usages

On big endian architectures, it is possible to run into a memory out of
bounds pointer dereference when FCP targets are zoned.

In lpfc_prep_embed_io, the memcpy(ptr, fcp_cmnd, sgl->sge_len) is
referencing a little endian formatted sgl->sge_len value.  So, the memcpy
can cause big endian systems to crash.

Redefine the *sgl ptr as a struct sli4_sge_le to make it clear that we are
referring to a little endian formatted data structure.  And, update the
routine with proper le32_to_cpu macro usages.

Fixes: af20bb7 ("scsi: lpfc: Add support for 32 byte CDBs")
Signed-off-by: Justin Tee <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
Justin Tee authored and martinkpetersen committed Jul 5, 2024
1 parent f65f31a commit 8bc7c61
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions drivers/scsi/lpfc/lpfc_sli.c
Original file line number Diff line number Diff line change
Expand Up @@ -10579,10 +10579,11 @@ lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
{
struct lpfc_iocbq *piocb = &lpfc_cmd->cur_iocbq;
union lpfc_wqe128 *wqe = &lpfc_cmd->cur_iocbq.wqe;
struct sli4_sge *sgl;
struct sli4_sge_le *sgl;
u32 type_size;

/* 128 byte wqe support here */
sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
sgl = (struct sli4_sge_le *)lpfc_cmd->dma_sgl;

if (phba->fcp_embed_io) {
struct fcp_cmnd *fcp_cmnd;
Expand All @@ -10591,9 +10592,9 @@ lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
fcp_cmnd = lpfc_cmd->fcp_cmnd;

/* Word 0-2 - FCP_CMND */
wqe->generic.bde.tus.f.bdeFlags =
BUFF_TYPE_BDE_IMMED;
wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
type_size = le32_to_cpu(sgl->sge_len);
type_size |= ULP_BDE64_TYPE_BDE_IMMED;
wqe->generic.bde.tus.w = type_size;
wqe->generic.bde.addrHigh = 0;
wqe->generic.bde.addrLow = 72; /* Word 18 */

Expand All @@ -10602,13 +10603,13 @@ lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)

/* Word 18-29 FCP CMND Payload */
ptr = &wqe->words[18];
memcpy(ptr, fcp_cmnd, sgl->sge_len);
lpfc_sli_pcimem_bcopy(fcp_cmnd, ptr, le32_to_cpu(sgl->sge_len));
} else {
/* Word 0-2 - Inline BDE */
wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
wqe->generic.bde.addrHigh = sgl->addr_hi;
wqe->generic.bde.addrLow = sgl->addr_lo;
wqe->generic.bde.tus.f.bdeSize = le32_to_cpu(sgl->sge_len);
wqe->generic.bde.addrHigh = le32_to_cpu(sgl->addr_hi);
wqe->generic.bde.addrLow = le32_to_cpu(sgl->addr_lo);

/* Word 10 */
bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
Expand Down

0 comments on commit 8bc7c61

Please sign in to comment.