]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
octeontx2-pf: avoid double free of pool->stack on AQ init failure
authorDawei Feng <dawei.feng@seu.edu.cn>
Fri, 15 May 2026 15:18:26 +0000 (23:18 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 20 May 2026 00:49:49 +0000 (17:49 -0700)
otx2_pool_aq_init() frees pool->stack when mailbox sync or retry
allocation fails, but leaves the pointer unchanged. Later,
otx2_sq_aura_pool_init() unwinds the partial setup through
otx2_aura_pool_free(), which frees pool->stack again. The CN20K-specific
cn20k_pool_aq_init() implementation has the same bug in
its corresponding error path.

Set pool->stack to NULL immediately after the local free so the shared
cleanup path does not free the same stack again while cleaning up
partially initialized pool state.

The bug was first flagged by an experimental analysis tool we are
developing for kernel memory-management bugs while analyzing
v6.13-rc1. The tool is still under development and is not yet publicly
available. Manual inspection confirms that the bug is still present in
v7.1-rc3.

Runtime validation was not performed because reproducing this path
requires OcteonTX2/CN20K hardware.

Fixes: caa2da34fd25 ("octeontx2-pf: Initialize and config queues")
Fixes: d322fbd17203 ("octeontx2-pf: Initialize cn20k specific aura and pool contexts")
Cc: stable@vger.kernel.org
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Signed-off-by: Dawei Feng <dawei.feng@seu.edu.cn>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260515151826.1005397-1-dawei.feng@seu.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/octeontx2/nic/cn20k.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c

index a5a8f455871748b434ac65906cffd062451d1fd2..dbf1731966082eb832ca423409b471e765a17827 100644 (file)
@@ -619,11 +619,13 @@ static int cn20k_pool_aq_init(struct otx2_nic *pfvf, u16 pool_id,
                err = otx2_sync_mbox_msg(&pfvf->mbox);
                if (err) {
                        qmem_free(pfvf->dev, pool->stack);
+                       pool->stack = NULL;
                        return err;
                }
                aq = otx2_mbox_alloc_msg_npa_cn20k_aq_enq(&pfvf->mbox);
                if (!aq) {
                        qmem_free(pfvf->dev, pool->stack);
+                       pool->stack = NULL;
                        return -ENOMEM;
                }
        }
index 971fcab1c2483b4e3d55bcdaf30a697fe6a2e56a..3d253132a17f0e579aca6b603e7c930443e2569f 100644 (file)
@@ -1482,11 +1482,13 @@ int otx2_pool_aq_init(struct otx2_nic *pfvf, u16 pool_id,
                err = otx2_sync_mbox_msg(&pfvf->mbox);
                if (err) {
                        qmem_free(pfvf->dev, pool->stack);
+                       pool->stack = NULL;
                        return err;
                }
                aq = otx2_mbox_alloc_msg_npa_aq_enq(&pfvf->mbox);
                if (!aq) {
                        qmem_free(pfvf->dev, pool->stack);
+                       pool->stack = NULL;
                        return -ENOMEM;
                }
        }