From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387933; b=svwHAknrrbQBxmrECeGrXKPyvVaK/EIYshybo/mkNLWXfDKnjI23TQnV7IoXfTVQqcZ3 SfSXpzGZHFrGNuiENQr8BVt5jOpitEok4rqC6Y3dh6z5nHwBk85admXEs9avCuMiwcJH/ FyXvd0Prdt814c8fiV87rIygHx5nvOWDja/1Qc8fHTXk8ngOvvwhUMHrRhuTVR0Wacf14 BCwoHIgT5D6JZCFRW9Y0hX3bxPEEbGwZg8gY576gw4+Jnjl0RE0W1uQxbMOBEiOY15YQb sVUhIP34TwD6KXuF9m+jkV/GLfx71xBY8TStb7Zk6JDsH41iZviTPWbyJVYgQcL24Hw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387933; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=QpY+a0NDT69HCC5FfHgaKCjwPOB0QFK/qMc4MIz4jVU=; b=f7LNVczspoXlZFSoTbOx2PweYfC4GxobVsMQmU9b0vBqjCQeuUzW0dMWyOJn2NE1fcln YWgiCpw1Ga/iwCM58ATe//1nS0N6YN6+HI4d2xwZSsK2L1yMmvjWAgOayFuz1+R+yL+fk hZMkDGNt8B4CqNYMsCBN5ML25FSl8PYeTPh8gSOLSLpn6uLxJQ4sqCGWXu+fhNtuehIsj EFhZM8G44+0BWLOTVJZRE92ZxvhyFR2OmPNeUgNB7Uf7/gsiL0sVEzM89yvKG7it+yZ2G yuVi9HDm15b0ZTTIsawJ4m8A1SRgQiI3HgssLHEAwN7JqXWojVIKM+94yVNPnd/3GuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yF2pHSND; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E006606A32C; Fri, 4 Dec 2026 12:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yF2pHSND Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F7B51F00931; Fri, 4 Dec 2026 12:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387932; bh=QpY+a0NDT69HCC5FfHgaKCjwPOB0QFK/qMc4MIz4jVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yF2pHSNDkpxyhhEUtZanbYDvdyT9SelPJJRqd548425D75TkYN+oiYwS3Q9NmOsKq Zl6Iyaj9H/bEUFY0lyBtzcRhOgyR1Du2pyDH+psWv8GlOBumN11+GRmFFeZUXWcm/o TG10LW5S00y3bRMiqSeaH7ShIgltj9zc7g4lJ4tk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0418/1059] bpf, cpumap: Hold the device of frames in the queue Date: Fri, 4 Dec 2026 18:59:09 +0900 Message-ID: <20261204100655.164046843@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit f99351272933ba2e1221484a5e53b7a5d2c035f0 ] A frame that is redirected to another CPU waits in the queue of the cpumap entry with a plain pointer to the device it came from, and an skb from generic XDP with skb->dev. Nothing keeps that device. Closing and unregistering it waits for its NAPI and for RCU, but not for the kthread of the entry. If the kthread is late by more than that, since its CPU is busy with something of a higher priority, it builds skbs for a device that has been freed and hands them to the stack: BUG: KASAN: use-after-free in dev_gro_receive+0x1f51/0x2b30 Read of size 8 at addr ffff88800a7340b0 by task cpumap/1/map:1/54 Take a reference to the device for each entry of the queue. The kthread cannot drop it at the end of the batch, since its GRO node may keep the skb for longer. Let it note the devices and drop the references behind a full GRO flush, which it does whenever the queue is empty, and from now on also when it has noted about 2048 of them. A device whose frames are stuck in a queue is now unregistered only when the kthread has got to them. RTNL is not held meanwhile, but if the device goes with its network namespace, the cleanup of all namespaces waits. Fixes: 1c601d829ab0 ("bpf: cpumap xdp_buff to skb conversion and allocation") Fixes: 11941f8a8536 ("bpf: cpumap: Implement generic cpumap") Signed-off-by: Josef Bacik Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261017230950.802052-8-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/cpumap.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index 806a7c1b364b6..64691f757f2a9 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -142,9 +142,11 @@ static void __cpu_map_ring_cleanup(struct ptr_ring *ring) WARN_ON_ONCE(1); if (unlikely(__ptr_test_bit(0, &ptr))) { __ptr_clear_bit(0, &ptr); + dev_put(((struct sk_buff *)ptr)->dev); kfree_skb(ptr); continue; } + dev_put(((struct xdp_frame *)ptr)->dev_rx); xdp_return_frame(ptr); } } @@ -324,6 +326,8 @@ static int cpu_map_kthread_run(void *data) void *frames[CPUMAP_BATCH]; void *skbs[CPUMAP_BATCH]; LIST_HEAD(list); + struct net_device *held[CPUMAP_BATCH]; + int nr_held = 0; /* Release CPU reschedule checks */ if (__ptr_ring_empty(rcpu->queue)) { @@ -356,10 +360,12 @@ static int cpu_map_kthread_run(void *data) struct sk_buff *skb = f; __ptr_clear_bit(0, &skb); + held[nr_held++] = skb->dev; list_add_tail(&skb->list, &list); continue; } + held[nr_held++] = ((struct xdp_frame *)f)->dev_rx; frames[xdp_n++] = f; page = virt_to_page(f); @@ -396,6 +402,8 @@ static int cpu_map_kthread_run(void *data) list_add_tail(&skb->list, &list); } netif_receive_skb_list(&list); + while (nr_held) + dev_put(held[--nr_held]); /* Feedback loop via tracepoint */ trace_xdp_cpumap_kthread(rcpu->map_id, n, kmem_alloc_drops, @@ -722,12 +730,14 @@ static void bq_flush_to_queue(struct xdp_bulk_queue *bq) for (i = 0; i < bq->count; i++) { struct xdp_frame *xdpf = bq->q[i]; - int err; - err = __ptr_ring_produce(q, xdpf); - if (err) { + if (__ptr_ring_full(q)) { drops++; xdp_return_frame_rx_napi(xdpf); + } else { + /* The device cannot go before the flush, from now on it can */ + dev_hold(xdpf->dev_rx); + __ptr_ring_produce(q, xdpf); } processed++; } @@ -783,11 +793,15 @@ int cpu_map_generic_redirect(struct bpf_cpu_map_entry *rcpu, __skb_pull(skb, skb->mac_len); skb_set_redirected(skb, false); + dev_hold(skb->dev); __ptr_set_bit(0, &skb); ret = ptr_ring_produce(rcpu->queue, skb); - if (ret < 0) + if (ret < 0) { + __ptr_clear_bit(0, &skb); + dev_put(skb->dev); goto trace; + } wake_up_process(rcpu->kthread); trace: -- 2.53.0