From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E71A53A257E for ; Sun, 19 Jul 2026 15:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784473372; cv=none; b=cqEFzZCg31rYgkiC+AC+OtcHW14NZufqZOuoSo3loLFBwkyY9XybAsq2ax3wCgH+DRtz/3v7oGLYZ0Sg5ec9G3RuT3O4M0gv/rioF/DqtXP0cyAwZ0z+pQALXHKSoVURaCq+DqUmYYKhjYVFJ1qTI7EbMN4wYGkjb8df4siLLVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784473372; c=relaxed/simple; bh=eSbibO+xhCniUvMt1FIWRWvPjNpLGZrzkTdVYCwi9r4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EtQDTMocKGJjFSi5cx9T/SNMZaLWfZTHsCqmNsdY0honH+qiwAjtz6k4FsNMGPUjIEM5PUnAhZydzxXK2EWPHEyQj2OxvzWjPmLilKljUpiuRy5/3bikhDuDJFDpBvBIwo/44hhbwuwbrUvSjh6dClo2V82fe5OUNyygeny/HzQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oPeb39/v; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oPeb39/v" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2cf49dc28ccso2620415ad.0 for ; Sun, 19 Jul 2026 08:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784473370; x=1785078170; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Min+DEzQsYXU48SJanwQaH6Js4T7CtgnWZ/eBINWIyc=; b=oPeb39/vmuPz8ATR95oqeqhHqYa1efqgj0nqND11IBU3Eqj528lhyFAl2josHR/GFJ 1nYLhq8wo2VAFgnbKVPdA4wK7Cvo6/rhi+CFR3b4wEfiFwZk1ylJTNktjDsKX08Mo7fx Z5CT7XcMF1aaCc4XBOjUCeoNukSqjUskkuJW8H5WVaylpHazwKrITG6tjwkrHW3YJ6Py QuYmB+5egu7V3jdIxrPWKR+slyLDYWyiKwX5HBLfI5+uQOikVsjOPrcEdp2urtfXF4RT PdCQKKfD4yrxzzFWbX1YgpaZKkoz3sAyMM0UDqbtWPgAoANvG3a7ovsCU8wqxQ2HNUWA ZzPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784473370; x=1785078170; h=content-transfer-encoding:mime-version: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=Min+DEzQsYXU48SJanwQaH6Js4T7CtgnWZ/eBINWIyc=; b=fglmadpUBnrJUK8vi0r1vBUusobyi4XstcAQZlRAfXttTNF3EqRnTlWrmiflhbaK7x a3gfmQ3MjGz/oEhJzdWGMwobfzBOjYoSsscpizOX7vGKnIFu/ThIUF7b3/+4Nyl0+BqK PzV0XmSwnDtCHwKtxkZzou+//cdn7kgGi4PLlEpPo8GP0unGvUUjSCXqsRhwH3IlH8m/ 8DBdNCEY1uAr0mGnntXCYJz5VTEbeXa7V/Lm9zxcEbP+1Eig0u8g3q9NCiCP0Q/p0XaR FE1WigwxSeqMJkcLHgozvowwSKbB3Vx3X9pdCAdixRXRs0bvwcIt6brCnK/+qUOiTisG rynA== X-Forwarded-Encrypted: i=1; AHgh+RpFmAwEmKDoV3q/JZ8mHrpQg+fTnJGJzVXl9GFKzawxny0eOr4ygwedPjut+lAznvcib0/tWFYxF19JNJs=@vger.kernel.org X-Gm-Message-State: AOJu0YyxIsBMykUjhOKWE5Yz+Mah909r/d/cvqAGjOw/mGKNbDxeQMDD wz8fHTfX2j/xlbUn4EmbGjp1OSRX7lRiBOz5KlB4X3z+TAiqhDq53ia3 X-Gm-Gg: AfdE7cnKL2NFYCNZk05LePd1nP/xVCAZIx3+jwUmxFRKYmvQMcUgYvWl/8hJReIOegO p9HrS6fT8c6PlZzv7cwJKrTStrtomRV8aFtGgnLBeSrQpqgt6wKtQrhYJYWhp7Y+vfc0XIcTEVa hqGVHnFu6Wfs2Os/QXLKNQBH/RiqL17KvEcemAMZL0BFi53aPkPU4fgASDrXelBD3RtiwgBiG7F VF3/FZj4uxtfZNup0Kl5HQNcZ0AT+4hMXvvoY0un8d4Ov3dI88sRhPBHzTHY0T8MwJwrpogFKZi nJeMVSsnA17jEcEa914n9MppxQ+swz40M4ETvxd8NamHTdOzFFx6yljNdqz8uNkJeqQ5ahK0gag hTlKf+8emVqTEZXfQvD7o3ojXPuLdv0i9YsIpbcb5yJT+bkwEMMywAF3VKLhE0p5vW1AD6pWZer b+fIU9/FpRyXGuqiA27LhJ8XgLDKvDg8u2/G95KlzuxnT6D3dEL6CkJNwOmE4= X-Received: by 2002:a17:902:ccd1:b0:2ca:d344:7743 with SMTP id d9443c01a7336-2cf34a05d6cmr90369635ad.7.1784473369952; Sun, 19 Jul 2026 08:02:49 -0700 (PDT) Received: from localhost.localdomain ([14.218.106.255]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf346d9b00sm42198945ad.53.2026.07.19.08.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 08:02:49 -0700 (PDT) From: Chengfeng Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Thorsten Blum , Andrew Morton , Andy Shevchenko , Randy Dunlap , Chengfeng Ye , Robert Olsson , Stephen Hemminger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] net: pktgen: fix proc entry use-after-free Date: Sun, 19 Jul 2026 22:57:40 +0800 Message-ID: <20260719145740.2888967-1-nicoyip.dev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pktgen_change_name() replaces pkt_dev->entry while holding t->if_lock. pktgen_remove_device() removes the same entry before _rem_dev_from_if_list() takes that lock. This allows the following interleaving: CPU 0 (NETDEV_CHANGENAME) CPU 1 (kpktgend) if_lock(t) proc_remove(pkt_dev->entry) proc_remove(pkt_dev->entry) pkt_dev->entry = proc_create_data(...) if_unlock(t) The kthread can pass the stale proc_dir_entry to proc_remove() after the rename path has freed it. A reproducer with a widened race window reports: BUG: KASAN: slab-use-after-free in proc_remove+0x78/0x80 Read of size 8 at addr ffff8881478fea70 by task kpktgend_0/67 Call Trace: proc_remove+0x78/0x80 pktgen_remove_device.isra.0+0x11c/0x4c0 pktgen_thread_worker+0x1214/0x6bc0 kthread+0x2c6/0x3b0 Allocated by task 95: __proc_create+0x204/0x790 proc_create_data+0x72/0xe0 pktgen_thread_write+0xd61/0x1510 Freed by task 28: kmem_cache_free+0xcb/0x3d0 proc_free_inode+0x5b/0x80 rcu_core+0x50a/0x1850 The buggy address belongs to the object at ffff8881478fea00 which belongs to the cache proc_dir_entry of size 192 Move proc_remove() into the if_lock-protected list removal helper. Keep it before list_del_rcu() to preserve the ordering required by add_device(). The rename path must then finish replacing the entry before removal, or it observes that the device is no longer on the list. Fixes: 39df232f1a9b ("[PKTGEN]: fix device name handling") Cc: stable@vger.kernel.org Signed-off-by: Chengfeng Ye --- net/core/pktgen.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 8e185b318288..ee64f3012321 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -3972,6 +3972,7 @@ static void _rem_dev_from_if_list(struct pktgen_thread *t, struct pktgen_dev *p; if_lock(t); + proc_remove(pkt_dev->entry); list_for_each_safe(q, n, &t->if_list) { p = list_entry(q, struct pktgen_dev, list); if (p == pkt_dev) @@ -4001,9 +4002,6 @@ static int pktgen_remove_device(struct pktgen_thread *t, * list to determine if interface already exist, avoid race * with proc_create_data() */ - proc_remove(pkt_dev->entry); - - /* And update the thread if_list */ _rem_dev_from_if_list(t, pkt_dev); #ifdef CONFIG_XFRM -- 2.43.0