]> git.baikalelectronics.ru Git - kernel.git/commit
xsk: Fix generic transmit when completion queue reservation fails
authorCiara Loftus <ciara.loftus@intel.com>
Tue, 14 Jun 2022 07:07:46 +0000 (07:07 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 14 Jun 2022 14:49:29 +0000 (16:49 +0200)
commit489551be5e6541d49881a1149eed7782d8357ee7
treee98dfe787658883e7e142f79530831538379c321
parentafa80dff159988a86495f1316f0572edacad5935
xsk: Fix generic transmit when completion queue reservation fails

Two points of potential failure in the generic transmit function are:

  1. completion queue (cq) reservation failure.
  2. skb allocation failure

Originally the cq reservation was performed first, followed by the skb
allocation. Commit 74bed4e284d7 ("xdp: fix possible cq entry leak")
reversed the order because at the time there was no mechanism available
to undo the cq reservation which could have led to possible cq entry leaks
in the event of skb allocation failure. However if the skb allocation is
performed first and the cq reservation then fails, the xsk skb destructor
is called which blindly adds the skb address to the already full cq leading
to undefined behavior.

This commit restores the original order (cq reservation followed by skb
allocation) and uses the xskq_prod_cancel helper to undo the cq reserve
in event of skb allocation failure.

Fixes: 74bed4e284d7 ("xdp: fix possible cq entry leak")
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20220614070746.8871-1-ciara.loftus@intel.com
net/xdp/xsk.c