Skip to content

Commit a78cae2

Browse files
kuba-mooborkmann
authored andcommitted
xdp: Move the rxq_info.mem clearing to unreg_mem_model()
xdp_rxq_info_unreg() implicitly calls xdp_rxq_info_unreg_mem_model(). This may well be confusing to the driver authors, and lead to double free if they call xdp_rxq_info_unreg_mem_model() before xdp_rxq_info_unreg() (when mem model type == MEM_TYPE_PAGE_POOL). In fact error path of mvpp2_rxq_init() seems to currently do exactly that. The double free will result in refcount underflow in page_pool_destroy(). Make the interface a little more programmer friendly by clearing type and id so that xdp_rxq_info_unreg_mem_model() can be called multiple times. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent ccff81e commit a78cae2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/core/xdp.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ static void mem_allocator_disconnect(void *allocator)
113113
void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq)
114114
{
115115
struct xdp_mem_allocator *xa;
116+
int type = xdp_rxq->mem.type;
116117
int id = xdp_rxq->mem.id;
117118

119+
/* Reset mem info to defaults */
120+
xdp_rxq->mem.id = 0;
121+
xdp_rxq->mem.type = 0;
122+
118123
if (xdp_rxq->reg_state != REG_STATE_REGISTERED) {
119124
WARN(1, "Missing register, driver bug");
120125
return;
@@ -123,7 +128,7 @@ void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq)
123128
if (id == 0)
124129
return;
125130

126-
if (xdp_rxq->mem.type == MEM_TYPE_PAGE_POOL) {
131+
if (type == MEM_TYPE_PAGE_POOL) {
127132
rcu_read_lock();
128133
xa = rhashtable_lookup(mem_id_ht, &id, mem_id_rht_params);
129134
page_pool_destroy(xa->page_pool);
@@ -144,10 +149,6 @@ void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq)
144149

145150
xdp_rxq->reg_state = REG_STATE_UNREGISTERED;
146151
xdp_rxq->dev = NULL;
147-
148-
/* Reset mem info to defaults */
149-
xdp_rxq->mem.id = 0;
150-
xdp_rxq->mem.type = 0;
151152
}
152153
EXPORT_SYMBOL_GPL(xdp_rxq_info_unreg);
153154

0 commit comments

Comments
 (0)