From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) (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 869B114F112 for ; Sat, 27 Jun 2026 05:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782537438; cv=none; b=tjqkASbIsq3Bz0MWLUotqDM0xzpnMLRR16S74pT4NRjask/Yfu123X/0WTnuOqoCzxKnPlfiA79BTn1/gX5tOp7xPifR/QONP7AOoBl3ABUSlgy9gMB9jec+tjkKeahSh0lqWXTgmOxgf6rK6EVtqqzVUzeGQiGbZpVg5IbnqBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782537438; c=relaxed/simple; bh=3ORVG5L+0VzE4gvqv1s7IJzn9znLHmAvRqb7Xy96E7c=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=rPoKHQSp2wUpOzX+W0pchOqRUqT+OydHG6SzCv42rzGdXcT3ulvB/iluGrdukGiuxepHEGXGXY3YyK5p8ChNQSfOTmFP7H3rO+Foy10tKQyKM9BTxg/X5raY96kM5GnFspzoVahvmB0iI9BkDxL0k9UuPkVgmVgEA1pe/EpFvRE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.160.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-44852cb1f4eso409496fac.2 for ; Fri, 26 Jun 2026 22:17:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782537435; x=1783142235; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+qIIi2RieciP2zHCDdrIhn1CZv3WvfcDb9c7VSqDJ7Q=; b=EeKIGcgIQHS4PeZRkc2TDGc32zS3oXw+vUDuhfocdks0tzCNF3Yd/dVhtOtiYdN0T1 b0K9VA5zLtmJCWJMa3bYh7fJgffSYcp7004swexKKx6WQS1DybHzeMIyu0YxK+h/DmQf TPSRjCEPMBKDcBUdmm5/JqKHfaY9UVOwqAdjTbLLFjPyjACxSEB//UYJXoUs8WafH6RS 7c5nhlYxsAUVSUvNJ2OA5cMBCtggCT9DJWLydTtfTLdVnpXwDoQr/5YGjYlvqMfeN4/g C1HGsasHNdWmQLs8n35kVHy+M8A/ipKIlmA6pZ5i4EwZMLw4TmOPP8Ij+tGVzu4a5k77 P1MA== X-Gm-Message-State: AOJu0YyYl/Jcn/o95aV0UfLa+Wccg2LGhmeM6HIQSRmah5O8yMSFiHfm 9T7+NKuHqKZ3o+9XtGAW1KNss7cSymAbpHPxZVZ4n/zg52p0iuaE2PnFiEHoBxPLGc9vWZIKTka KCiSqNrNNmqcce6YjihT0DTAas4VBpVmaOwI93W/4sY7AZqpYc7j8rE+9OEE= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6808:1185:b0:48a:7b94:26e2 with SMTP id 5614622812f47-4921593f572mr8078165b6e.7.1782537435551; Fri, 26 Jun 2026 22:17:15 -0700 (PDT) Date: Fri, 26 Jun 2026 22:17:15 -0700 In-Reply-To: <6a32e8e7.9e4c924b.10726f.0023.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a3f5cdb.854d4ab9.360e1d.0001.GAE@google.com> Subject: Forwarded: [PATCH v3] netdevsim: fix use-after-free of ethtool debugfs data From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH v3] netdevsim: fix use-after-free of ethtool debugfs data Author: hrushirajg23@gmail.com From: Hrushiraj Gandhi #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git main debugfs files created by nsim_ethtool_init() store raw pointers directly into the netdevsim struct, which lives in the net_device private data kmalloc slab. If the ethtool subdirectory outlives the netdevsim struct, a concurrent reader can trigger a slab-use-after-free by passing debugfs_file_get() (which only checks dentry lifetime) and then dereferencing the freed data pointer in e.g. debugfs_u32_get(). In __nsim_dev_port_del(), nsim_destroy() is called before nsim_dev_port_debugfs_exit(). nsim_destroy() ends with free_netdev(), while nsim_dev_port_debugfs_exit() removes the port's debugfs directory afterwards. This means the slab is freed before the ethtool debugfs files that point into it are removed. The same window exists on nsim_create()'s error path: nsim_ethtool_init() creates debugfs files under ddir with pointers into ns before nsim_init_netdevsim()/nsim_init_netdevsim_vf(), which can fail. The err_free_netdev label then calls free_netdev() while those ethtool debugfs entries are still live. All other features that create per-port debugfs files (pp_hold, queue_reset, vlan) already remove their own entries explicitly in nsim_destroy() before free_netdev(). ethtool is the only one that does not. Fix this by saving the ethtool dentry in struct nsim_ethtool and calling debugfs_remove_recursive() on it before free_netdev() in both nsim_destroy() and the nsim_create() error path. The port ddir teardown is left to nsim_dev_port_debugfs_exit() as before. Reported-by: syzbot+6c25f4750230faf70be9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6c25f4750230faf70be9 Fixes: e05b2d141fef ("netdevsim: move netdev creation/destruction to dev probe") Signed-off-by: Hrushiraj Gandhi --- v3: - Instead of removing the entire port ddir before free_netdev(), save and remove only the ethtool dentry. All other features (pp_hold, queue_reset, vlan) already clean up after themselves; ethtool is the only exception. This aligns ethtool with how the other features behave, as suggested by Jakub Kicinski. v2: - Also fix the same use-after-free window on the error path of nsim_create() as suggested by Simon Horman. - Shorten the code comment in nsim_destroy() to be more concise. --- drivers/net/netdevsim/ethtool.c | 1 + drivers/net/netdevsim/netdev.c | 9 +++++++++ drivers/net/netdevsim/netdevsim.h | 1 + 3 files changed, 11 insertions(+) diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c index 9350ba48eb81..a465f3220a7c 100644 --- a/drivers/net/netdevsim/ethtool.c +++ b/drivers/net/netdevsim/ethtool.c @@ -252,6 +252,7 @@ void nsim_ethtool_init(struct netdevsim *ns) ns->ethtool.channels = ns->nsim_bus_dev->num_queues; ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir); + ns->ethtool.ddir = ethtool; debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err); debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err); diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 27e5f109f933..09d86a591fac 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -1165,6 +1165,7 @@ struct netdevsim *nsim_create(struct nsim_dev *nsim_dev, return ns; err_free_netdev: + debugfs_remove_recursive(ns->ethtool.ddir); free_netdev(dev); return ERR_PTR(err); } @@ -1214,6 +1215,14 @@ void nsim_destroy(struct netdevsim *ns) ns->page = NULL; } + /* + * Remove the ethtool debugfs directory before free_netdev() releases + * the netdevsim struct to prevent use-after-free in concurrent readers. + * Other per-port debugfs files are already removed above, and the port + * ddir itself is cleaned up by nsim_dev_port_debugfs_exit(). + */ + debugfs_remove_recursive(ns->ethtool.ddir); + free_netdev(dev); } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 4c9cc96dcec3..c08a01af31e9 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -95,6 +95,7 @@ struct nsim_ethtool { struct ethtool_coalesce coalesce; struct ethtool_ringparam ring; struct ethtool_fecparam fec; + struct dentry *ddir; }; struct nsim_rq { -- 2.47.3