From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 E93BB40D595 for ; Sat, 20 Jun 2026 06:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781938202; cv=none; b=ftSuGKkVttE9SJcPy/ng6SGjqeoA44z3119Vw0hAUpi0OkYgLfW5UqSpHPJEtj9+0SMpOVqIJ/n4UVgkH8Xl5Zktha96MDks+wsPr3loE4GsuT/vFodJAiHTUZlDSZ19VSiXvcsU9NSwCyWQTmTEFIDTxHw3j5//qvR3sz5lRe8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781938202; c=relaxed/simple; bh=4mqGOvPe2ySFz23e6c1nkg/oSG2A1tbfWoG8+d7LdcU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rd9DrzqHDt6Uuhe18kCbHtN1oY6V5QS+/Yzw6EdHNIAuSyLYQjrmDkwVHa93AEGGn1QFgY5GacICpGyYuFNQkRNYkv+ltEALQH+js9bK60n9lxT7U5gPlnaaYePFR0NDpHB5eJrQ8vRHIHQi9FeeIsAbMbRfQYjnjCHxa8zec4c= 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=TPt0cs81; arc=none smtp.client-ip=209.85.210.180 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="TPt0cs81" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-8424b00710aso1875241b3a.0 for ; Fri, 19 Jun 2026 23:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781938199; x=1782542999; 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; bh=Z4gFwDs7h2AgPecnLqQuSzgjfmb3gFWpW8KL8n46kjY=; b=TPt0cs81hgbesRMPuorL23PzGmpnbWyAOkh29ID+mbRuEI1YAYpATp3GhtF/J6DwMg 3EnHD4xZxxHe7eZKIRpMAkgyIlZnpKeR9hfzTfNTfRDv75eNQqjVBaGWD/olye+NahFN 8HW9DawN7P9TUO1xowLkn8pIy28i0aYYGjwsERnpxaoUmVXLcTqQv2tmnuTtZdiqNxcO 7n6q4UeczJmO9lu2zKUpOPNhyYQEdYsGy+XgIVr45umtrVomtf7egUy3OzxcsxrOW1vH 0eXkmUsOtmrrnPqcbGEz5yilsqqsMg478vO9QZu2/aZT2DMwOTiw9CCrD5nKsdRVeL7I Y83Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781938199; x=1782542999; 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; bh=Z4gFwDs7h2AgPecnLqQuSzgjfmb3gFWpW8KL8n46kjY=; b=o1n4s0OPvBp6bkM/v09/7jN/x9CO3QLpy/knKO5g9JrUuUIHdxinUd1SVja6vCgGLe nb51A7jpYPSl6kBTxBfENCtctjnExicQFXTY6J5bAxlrxtWtepIHtkKQDGHPhzuhOpnq 4FGK4KqNkD5Om5pwnLWsrY+7pfI3xvERmhAquj2G6guexcKCwmE7E52WmK9K0B53ZA8z w1zG101L0Z2R+P+LOQrMQRJiiA5idYRnWtJWItWw7DsH3qGHqEGnzJJ47gFToohKcDQ2 cphI5lWeVN11by/7ovHq0LsaKERc+9GAK4peWU4p/4vH2QeOJ/qCSXKNmi28QhS+NURH Ltzg== X-Forwarded-Encrypted: i=1; AFNElJ9pyB9ngPOZwyRdG/p8JnK07fcpJo5CyRXj33VWEqYspxFmI/u6G9/XJtPJr1CFPTjraJlfDV6lKU7oPuE=@vger.kernel.org X-Gm-Message-State: AOJu0YwYvio6tEmZU2HixJNCHhZHKqvb+5BRyG6KUM8NrgQanr+dCmbm vZHC2Kdmrx6Mgp0lKaruKK2WEKEp2TEhBo9ptQNHgmdGVlR/iuFA3rTvQZpY7rAY X-Gm-Gg: AfdE7clCYpHy9zieJHcEdQUlGujzv0g2QusBZZlyMcbivcjUzlwzY86OGdf8y/jqJ6r DuCI/w5sYD3FkvZntoh1lKc8YVNJ7oi6748hm/kYwuE+9pTDROsliMMS1FaDYYh14OrcAwSIfPT N+5KkqJGqzonDUMumVg/RJpcy019hpaQhgSl1rQySKd0cvYVPUvtUlpw/jvWYYl2W6utFBwC+mK iYfVsGWjpK8sLFAqydRdt/ctDz5KAwGBDceWONPFm0zy2mFzowtLNI40RAkspQrWGYE2KLzPaeW DxhqvXtJMi3EJp8+KlaWk4Xs9P/Lyki8JemRdyAYc9d1jYyt37jdk8qxsTu1pN8zxrN7pf1nS+O flA7vvyN+oVGLptrNuWImxBeUK1doNkU2cIzkDHEB2Valam7fHYWu4Z2YUQ3UwGbZDyJ5MBAkML aduLaUbpA3jrWzdR4/1NnVp70+8ROH8Q== X-Received: by 2002:a05:6a00:4654:b0:845:328c:1ec1 with SMTP id d2e1a72fcca58-845507c1d66mr7412645b3a.12.1781938199294; Fri, 19 Jun 2026 23:49:59 -0700 (PDT) Received: from i386.168.1.127 ([2402:a00:163:2ce9:9c6f:e28:3da8:7980]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84564ea22c7sm1197475b3a.44.2026.06.19.23.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 23:49:58 -0700 (PDT) From: Hrushiraj Gandhi To: Jakub Kicinski Cc: Andrew Lunn , "David S . Miller" , Eric Dumazet , Paolo Abeni , Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Hrushiraj Gandhi , syzbot+6c25f4750230faf70be9@syzkaller.appspotmail.com Subject: [PATCH] netdevsim: fix use-after-free in __nsim_dev_port_del Date: Sat, 20 Jun 2026 12:19:37 +0530 Message-ID: <20260620064937.16301-1-hrushirajg23@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 27e5f109f933..08136e7990cb 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -1214,6 +1214,13 @@ void nsim_destroy(struct netdevsim *ns) ns->page = NULL; } + /* + * Remove per-port debugfs files before free_netdev() releases the + * netdevsim struct to prevent use-after-free in concurrent readers. + */ + debugfs_remove_recursive(ns->nsim_dev_port->ddir); + ns->nsim_dev_port->ddir = NULL; + free_netdev(dev); } -- 2.47.3