From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (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 B92652E7362 for ; Thu, 18 Jun 2026 12:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781786078; cv=none; b=a2WcBdGpKUi/2KQcYSxOkwJasaT6d+RZ1YPtHC44ZEScLH/uMRsUJYXZfUgbsbrHGyExhB951Up8FhokFjlHd17He8Pg7r3zKkf9XDfcL1tAJl+iuxeXOMR7nTJPF/XDQXrqxl9IrdsoJ0Od1UXHQJizkVhzzctRiXAyKT1O5Bw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781786078; c=relaxed/simple; bh=AaMY6FrPN2ldVSxFBXrHwSFYGzCN8GoVznO3DldGxKg=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=smMzpvxLZYEH9djZPGOy+t6nKiqoIrUSqXHik0BlKJScA8bkcKPKnQQZa9twt9JYJ9bFarM+ykxnek25n203G85GAZ5c7Bi58pHbi++g+CWxlmYK/rtsW6mBU0H3S+BoPoL8i0a6Clv+Ax4K5V6H1nPaD2GvfmHg408gU16Vgfc= 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.167.199 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-oi1-f199.google.com with SMTP id 5614622812f47-4863abb79b0so3681288b6e.1 for ; Thu, 18 Jun 2026 05:34:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781786075; x=1782390875; 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=Xgtw1j74HWZrXNL3dsj1vrnXnP3r3UKYLi2eYlpNvpg=; b=kpbrx1Lm8ttc92kACAJRGPWXfxLem+QL2OUDj9saxizxXYSw1tbt9uulNtiKkwCJYY kM25IvYoaS6MKr4vHA5GvDGGTUeoJp8VwCGFAHetHS6xBJl7gDedWfArGQcE6NLsI05+ BxKHXV2C1odmElnetQ5Vd4XIoKTht/x0g09bmwWYMtqcpRG/Se1y9lYP0aakBMZBpbzy 24xZb2O9eJMp2jlbSR/wmmWLEJwm7iMj+PypAj9GPMqBobxcoKTa1CDaTEMG5bXFHsE7 6gmO94qehwM6TlrumYRSJCmGyS1GQaty8WhLhReb7xm5GHFy0+afwqdxVbLAT71Sa2n9 qxqQ== X-Gm-Message-State: AOJu0YxUQ1PzlxFpgLYlFTj7qRLkaDQVpFZQxJaIdyAaA4hdHuFfLGxa 0jCUTs1PSES7wo3xu338ZfZSpL0UuAxkQzZBjb2goVplPwl6NQCO4UA+FzQktBoUon8f37ckzgz nHhJ68SlmE8IP6g6v2ZLsGfWsrtdJJEFcFvqTd3VRnzv0jVbFWBEVO8JMyOY= 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:1b2a:b0:487:4f7b:53ca with SMTP id 5614622812f47-489562237damr2220669b6e.26.1781786075570; Thu, 18 Jun 2026 05:34:35 -0700 (PDT) Date: Thu, 18 Jun 2026 05:34:35 -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: <6a33e5db.537e895e.3cc275.0000.GAE@google.com> Subject: Forwarded: [PATCH] netdevsim: fix use-after-free in __nsim_dev_port_del 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] netdevsim: fix use-after-free in __nsim_dev_port_del Author: hrushirajg23@gmail.com #syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master debugfs files created under a port's ddir (ethtool/get_err, ethtool/set_err, ring params, bpf_offloaded_id, udp_ports/inject_error, etc.) store raw pointers directly into the netdevsim struct, which lives in the net_device private data kmalloc slab. If these files outlive 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 debugfs_u32_get(). In __nsim_dev_port_del(), nsim_destroy() is called before nsim_dev_port_debugfs_exit(). However, nsim_destroy() calls free_netdev() at its end, while nsim_dev_port_debugfs_exit() removes the port's debugfs directory. This means the slab is freed before the debugfs files are removed. Fix by calling debugfs_remove_recursive(ns->nsim_dev_port->ddir) in nsim_destroy() right before free_netdev(). This ensures all per-port debugfs files are destroyed synchronously before the backing memory is freed. The subsequent call to nsim_dev_port_debugfs_exit() in __nsim_dev_port_del() becomes a harmless no-op. 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 --- drivers/net/netdevsim/netdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index a750768912b5..511139d65d69 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -1213,6 +1213,22 @@ void nsim_destroy(struct netdevsim *ns) ns->page = NULL; } + /* + * Remove all per-port debugfs files before free_netdev() releases + * the netdevsim struct. Files like ethtool/get_err, bpf_offloaded_id, + * etc. store raw pointers into ns (netdev_priv data inside the + * net_device slab). A concurrent reader with the file open could pass + * debugfs_file_get() and then dereference freed memory if these files + * outlive free_netdev(). debugfs_remove_recursive() on the parent ddir + * handles this atomically; the subsequent nsim_dev_port_debugfs_exit() + * call in __nsim_dev_port_del() becomes a harmless no-op. + * + * The three explicitly tracked dentries (vlan_dfs, qr_dfs, pp_dfs) + * are children of ddir and are covered by the recursive removal below, + * so their individual debugfs_remove() calls become no-ops too. + */ + debugfs_remove_recursive(ns->nsim_dev_port->ddir); + free_netdev(dev); } -- 2.47.3