From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34B0B606A31A for ; Mon, 30 Nov 2026 20:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bj3kRSxs Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 95D57402D5; Mon, 30 Nov 2026 21:52:32 +0100 (CET) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by mails.dpdk.org (Postfix) with ESMTPS id 325D3402BE for ; Mon, 30 Nov 2026 21:52:31 +0100 (CET) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-9215934a14cso90179426d6.0 for ; Mon, 30 Nov 2026 12:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796071950; x=1796676750; darn=dpdk.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Slm8ZmlJFCL0J9zChF9Zg10RJcEKznTA4K80QxMn+9Q=; b=bj3kRSxsG3uNsViMWNwSzCSzy/SktzjLy/8ZJpxsmzbSaOnPlkIa53rskizORsU+gu lvyytGGG0qmXIdpTsUmu8Fqc+Ry0DC+uXZVhq6PIjVRlysFJMfHSKlex7f2DRt7Z0rbu 2SE+E9v4nLlqGFbpyEopFBwO1vi+3iyu4LZcH8KOdoihKxi5Go4LNvktEHt6LTT++szd P1z78ZyJKgAIMubOBBVtfOMc9dTlihk4tW/3BGrMGlzbXOC/sxoO5Ac9JhnEa5djHN89 k+NKDicpJamYOTQzDFvkPAe+eIGvQS091pUKWIPhear9Yfl/P8dpQz2iLFHVTBU2bone tuQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796071950; x=1796676750; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Slm8ZmlJFCL0J9zChF9Zg10RJcEKznTA4K80QxMn+9Q=; b=EqlGfhDDzAee92KGYOjjFe9FwZ8XBe4nmukZbzcneodGU0ZlklCVg68yyfXYB2pwO3 vwAwXkFgGkLWUhi6BU6I4eFVZYxYfv5v04YtZiHN18PpdGFXHbsjL12ez1QGG7mrl5ZF AwZuZKdbnOrJxOOe1ZW86CF7xeA/Hl5QYH+I89edmL2iB9oHNDzm3yp2/lGGk8Km7QPi KdB8C8J4oDB6LMNXdj3DG1/bqR1PU+6qB0ROGdeUTceJqnYoAY8tH8/s7/TaFLiK4fDj z/A7YnrIcMbrqYLSUixYh+KJuZ2ahsaeoYpSHnqCRiuPkMRgg19+n3VUNtmsDm/7CeK2 wfhg== X-Gm-Message-State: APuU4Z9b1SWFVHooRMFJiYF+hsVfKlics9p8YT1IA9A07RjybES4Kz8s tPvjHa8VvMNXsUuffWRYro9yov30xkC4zJekjIlnsfTCyA68yc3qeyLAvPes+pJ0 X-Gm-Gg: AZFdTZc5Eg1Ry73ORzhAaC14QocEpZ+qgNlqnBBKLEatisMwl10PvPNtbhKtQh//o2d iZC+0Yllrzvtmkiw+ffRwZhz2aJGRmjLzXW9U/Mg+oKo1kps9OXJORiR5PxMHJtAhehXW8cI9KL GKcjKg/wYLnZiprkbkvEAlXuUe04CUq5SJ+4+cyuUDSTnXx8l519y8BzJmPAhVzWTm/lAw3+xuV AlnB1WltWSFBrIfUJti9iH1bZFZLsTJcNdcpkNAJjfJRAFTL00A8cZ544KdfGoRMI/nM/9xVIKP f9AuwtlNn/eHmqVSjG8VHCLJRoX2MgSIBFfaCHdedgyUw7da2dMTRA3mFloP3c/Rhkd7thpqgUV N+mehLcxRvG1A1lqtaEUOOTehM2WkqkJT5CneKfJqlg1265vZCBrsq+ZAIgbVhN1seIykUPT59I 4yJcUeAoP/MYcZp637gmPeMAS5NSNVnhyYGMiiKnhvwr+SFqHc4tNxyZHQ7/SqS9E9i43Mm17L8 MnZcmlLXpFuDpFIG17DvE1gxo5OJQvLBb07wmVWp9sXzzHyJdHBXLni8DyqP3Nk44ZCkk7gOrKi dntYxn19ni2WvK8mhFFkIplIA87xXh0E867PTXJVWFMRh3j8Usnxd79JlJ46Yw+oKSrg05UmH1n D4y+0hZLj0PLXdK/z9jZFgQon3INGO7Gyl9S9OxmyPnIN9bLKE3Qjfini1d+fu92ywPcOeCSS7D Fa X-Received: by 2002:a05:6214:19ee:b0:917:9507:79a3 with SMTP id 6a1803df08f44-92134a3700fmr649757796d6.10.1796071949837; Mon, 30 Nov 2026 12:52:29 -0800 (PST) Received: from bos-lhvwah.bos01.corp.akamai.com (g2001-4878-8037-0700-526b-8dff-fef6-cfbf.deploy.static.akamaitechnologies.com. [2001:4878:8037:700:526b:8dff:fef6:cfbf]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921349b3a0csm304029476d6.14.2026.11.30.12.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 12:52:28 -0800 (PST) From: Robert Sanford To: dev@dpdk.org Cc: andrew.rybchenko@oktetlabs.ru, mb@smartsharesystems.com, olivier.matz@6wind.com, thomas@monjalon.net, Robert Sanford , stable@dpdk.org Subject: [PATCH v5 1/3] mempool: fix race between list walk and free Date: Mon, 30 Nov 2026 15:51:50 -0500 Message-Id: <20261130205152.7107-2-rsanford2@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130205152.7107-1-rsanford2@gmail.com> References: <20261112154342.1484709-1-rsanford2@gmail.com> <20261130205152.7107-1-rsanford2@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Robert Sanford rte_mempool_walk(), rte_mempool_lookup() and rte_mempool_list_dump() traverse the mempool list holding only the mempool list lock. rte_mempool_create_empty() inserts into the list holding both the mempool list lock and the tailq lock, but rte_mempool_free() unlinks and frees the list entry holding only the tailq lock. So a mempool can be unlinked and freed, together with its list entry, while another thread is walking the list. The walker then reads freed memory. Since freed heap memory is zeroed, the walk callback is passed a NULL mempool, or rte_mempool_lookup() compares the name of one, and the process crashes. Take the mempool list lock in rte_mempool_free() as well, in the same order as rte_mempool_create_empty(). As a result, a rte_mempool_walk() callback must not free a mempool, as it already could not create one. Document this. Fixes: a3791ff0a3f8 ("mempool: introduce a function to free a pool") Cc: stable@dpdk.org Signed-off-by: Robert Sanford Reviewed-by: Morten Brørup --- lib/mempool/rte_mempool.c | 8 ++++++++ lib/mempool/rte_mempool.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index 069aabaa70..d9f339a3c2 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -729,6 +729,13 @@ rte_mempool_free(struct rte_mempool *mp) return; mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list); + /* + * Take the mempool list lock as well, like rte_mempool_create_empty(), + * so that the entry is not unlinked and freed while + * rte_mempool_walk(), rte_mempool_lookup() or rte_mempool_list_dump() + * is traversing the list. + */ + rte_mcfg_mempool_write_lock(); rte_mcfg_tailq_write_lock(); /* find out tailq entry */ TAILQ_FOREACH(te, mempool_list, next) { @@ -741,6 +748,7 @@ rte_mempool_free(struct rte_mempool *mp) rte_free(te); } rte_mcfg_tailq_write_unlock(); + rte_mcfg_mempool_write_unlock(); mempool_event_callback_invoke(RTE_MEMPOOL_EVENT_DESTROY, mp); rte_mempool_trace_free(mp); diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h index fa2b9f00d5..5de7678a7a 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -1941,6 +1941,9 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, /** * Walk list of all memory pools * + * The mempool list is locked while the iterator function runs, so the + * iterator function must not create or free a mempool. + * * @param func * Iterator function * @param arg -- 2.34.1