[PATCH iwl-next 01/15] libie: wipe copied small send buffers on release
From: Stan Iliev
Date: Tue Nov 17 2026 - 09:56:52 EST
libie_ctlq_xn_send() copies the messages that fit in LIBIE_CP_TX_COPYBREAK
bytes into a DMA buffer of their transaction, which is reused for later
messages but never cleared. The messages can hold secrets, e.g. the PSP
TX keys that idpf inserts into the SADB of the device.
Wipe the copy once the message was sent, when its send queue entry is
cleaned, and when it couldn't be sent. The transaction can be reused as
soon as that entry is cleared, see libie_ctlq_xn_pop_free(): order the
wipe before it with smp_wmb(), paired with smp_acquire__after_ctrl_dep()
after the check of the entry, so that the wipe can't overwrite the next
message on weakly ordered architectures.
Signed-off-by: Stan Iliev <stani@xxxxxxxxxx>
---
drivers/net/ethernet/intel/libie/controlq.c | 28 ++++++++++++++++++---
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/libie/controlq.c b/drivers/net/ethernet/intel/libie/controlq.c
index 6214fc036ce5..c31d3c9e792a 100644
--- a/drivers/net/ethernet/intel/libie/controlq.c
+++ b/drivers/net/ethernet/intel/libie/controlq.c
@@ -694,9 +694,16 @@ libie_ctlq_xn_pop_free(struct libie_ctlq_xn_manager *xnm)
* address is dirty in any way, reuse is already safe.
*/
if (xn->tx_msg &&
- data_race(xn->tx_msg->send_mem.pa) == xn->small_dma_mem.pa)
+ /* READ_ONCE() for the control dependency below */
+ data_race(READ_ONCE(xn->tx_msg->send_mem.pa)) ==
+ xn->small_dma_mem.pa)
continue;
+ /* The small buffer is wiped before the message is cleared,
+ * pairs with the smp_wmb() of libie_ctlq_xn_rel_tx_buf()
+ */
+ smp_acquire__after_ctrl_dep();
+
clear_bit(free_idx, xnm->free_xns_bm);
return xn;
@@ -998,6 +1005,8 @@ int libie_ctlq_xn_process_send(struct libie_ctlq_xn_send_params *params,
if (!libie_ctlq_send_desc_avail(ctlq)) {
if (!libie_cp_can_send_onstack(buf_len))
libie_cp_unmap_dma_mem(dev, dma_mem);
+ else
+ memzero_explicit(dma_mem->va, buf_len);
return -EBUSY;
}
@@ -1132,10 +1141,21 @@ static void libie_ctlq_xn_rel_tx_buf(const void *ctx,
{
const struct libie_ctlq_xn_rel_tx_ctx *rel_ctx = ctx;
- if (!libie_cp_can_send_onstack(dma_mem->size)) {
- libie_cp_unmap_dma_mem(rel_ctx->dev, dma_mem);
- rel_ctx->rel_tx_buf(dma_mem->va);
+ /* Small messages are copied into the buffer of their transaction,
+ * which is reused: wipe the copy, the message may hold secrets, e.g.
+ * crypto keys
+ */
+ if (libie_cp_can_send_onstack(dma_mem->size)) {
+ memzero_explicit(dma_mem->va, dma_mem->size);
+ /* libie_ctlq_send_clean() clears the message next, which lets
+ * libie_ctlq_xn_pop_free() reuse the buffer
+ */
+ smp_wmb();
+ return;
}
+
+ libie_cp_unmap_dma_mem(rel_ctx->dev, dma_mem);
+ rel_ctx->rel_tx_buf(dma_mem->va);
}
/**
--
2.56.0.679.gc527c65306-goog