Skip to content

Commit adb4599

Browse files
WeiFang-NXPkuba-moo
authored andcommitted
net: enetc: fix DMA write to freed memory in enetc_msg_free_mbx()
The teardown sequence in enetc_msg_psi_free() frees the DMA buffer before clearing the device's DMA address registers. If a VF sends a message or a pending DMA transfer completes within this window, the hardware will perform a DMA write into the kernel memory that has already been returned to the allocator. The result is silent memory corruption that can affect arbitrary kernel data structures. Therefore, clear the DMA address registers before the DMA buffer is freed. Fixes: beb74ac ("enetc: Add vf to pf messaging support") Signed-off-by: Wei Fang <wei.fang@nxp.com> Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com> Link: https://patch.msgid.link/20260520064421.91569-7-wei.fang@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f262f5d commit adb4599

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/net/ethernet/freescale/enetc/enetc_msg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ static void enetc_msg_free_mbx(struct enetc_si *si, int idx)
9696
struct enetc_hw *hw = &si->hw;
9797
struct enetc_msg_swbd *msg;
9898

99+
enetc_wr(hw, ENETC_PSIVMSGRCVAR0(idx), 0);
100+
enetc_wr(hw, ENETC_PSIVMSGRCVAR1(idx), 0);
101+
99102
msg = &pf->rxmsg[idx];
100103
dma_free_coherent(&si->pdev->dev, msg->size, msg->vaddr, msg->dma);
101104
memset(msg, 0, sizeof(*msg));
102-
103-
enetc_wr(hw, ENETC_PSIVMSGRCVAR0(idx), 0);
104-
enetc_wr(hw, ENETC_PSIVMSGRCVAR1(idx), 0);
105105
}
106106

107107
int enetc_msg_psi_init(struct enetc_pf *pf)

0 commit comments

Comments
 (0)