From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 4F76D33EAEC for ; Tue, 14 Jul 2026 05:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784007303; cv=none; b=jCEj1PHIiK4jm+DalMchXSznzkKELi7jhQ9/FzY0FOYNa9irOcggqqyv5PFEDXSTsPqJkfRELzorIohLJWfofwndAF0LJwyA6529GA+GnoQNqb5p/Q/t5+9Wmzodwatl2QilgaVLgBZq5t/lz4ez3JWxSrdsPfVlK3ygLKW9chI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784007303; c=relaxed/simple; bh=o7ILli8856vsZPe8jN2xevd4Pp9Qm+S5O2msJvUkIqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pt0VdjDnOMIV8qw3ygqziOadXIRs8GKvBzd7j03o+SdLLY6wuiGiL7yJimS+n12qSb1pGTWgNkukDhalGouc6HCMDKIEGwVapVI4BbInvLWHWEplfvbmo2oGEhpHrNfgU5GaMq7Av44gfDGWLBHvjKlPARPXH0oxYrp4Rl5ZKwI= 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=QC+zXmls; arc=none smtp.client-ip=209.85.215.169 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="QC+zXmls" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-ca88130e09aso2610044a12.3 for ; Mon, 13 Jul 2026 22:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784007302; x=1784612102; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SGDV5fSUPAH2Dhpl1lbzAcq8czvypnTHYvjt3Vuz+wI=; b=QC+zXmlsih4OWAc2PoSjrZ0nwe0w0rmUhTQw42kvJZKAhmGNeXYX/JpS8yXes77u5F 1qcuNxG2nId/h4CuViCb9tr5owlgjYy/Gg1ntdUb09lz59ir0qJtQCizy1NGbi27DPKy 501NL201g260rxIglyA4LlprUyL2dSdy/ndfeebmOu29fE++kLLgsTupd76W6ViVLfMC rt+J7h03f9vEgYc8pOCqnIJd8JUQZi4mxUk6pxaQ8kt6ONS7qFUf1ayEuXJ9VUp8d5pN j1zSFX0kM8/mpn29FiOHoNmkmMonHVjFvgcxekW6gb1D1CBd/0DIo3t/ck3bJNBvtkBX z7hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784007302; x=1784612102; h=content-transfer-encoding:mime-version:references:in-reply-to :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=SGDV5fSUPAH2Dhpl1lbzAcq8czvypnTHYvjt3Vuz+wI=; b=XHphCcVOQ/41k0r4ylYLR8AU4DYbu72sfoKM3sBKWqu+Ld6XDJWYPof2dYQFiszddW 2jiP99PcK0oio7O/g5zmm1upBz0m8fudYmnqNZ6N3/0olMlFA/fJ/qgPrQ+CPCSgmvjU 0aJn1/iULMtMtwF1e5KmpGkLfZvRxCTS852jlqM/sA2Ldn7Z9LBWuFOsFtnZ/1ik3LSL KTyLNGSt8SU8LVVQyn5GxbPwwcz/x9zZjRkMa981nb8Ho3gXzUNNBXUp1a7Jc2PrOEQu TTKRZIZ9/I6zQCDw97iDQn29KBTAerKGOzfDrvPPTLuCMaZ8OPsZdSzaCsTgm4JIO7il KMcw== X-Forwarded-Encrypted: i=1; AHgh+RotSEisogeM3OyE3Y++dwVAjV6EibrrF/HOVwDtfZYpUvDEODrd9fvGYM1GP6pTAVyd0aySAkMCE0d3zjc=@vger.kernel.org X-Gm-Message-State: AOJu0YznM3VUQdOoa+ugSphrdJur08rgO67n3M1SOMZOsxb5lDuzlyi9 FM7ehXvbpqAF4yVfKw/lNLTuMFGeYZ3cb14lu1SLSrdbDSxKij/UB5K+ X-Gm-Gg: AfdE7clcZJ5Acv3i2WhOVl2bQ04dN+2OUOuwi3Kx/kuOmi8uyMNKHyC4K7ED86K3x71 x5SuZwTIceKmrrU/tlsuqijUW5xbhfi+SRtaSauQSYsASLUt//mrBYVcmY00pY5RmHGactflU2i 0S61ML5PqA6m/q1/3//5CQaORnXTC50p7XEGbw2W+typYZGoYqwJF3p+vnCG2Y9/0Ujc5xo8Ifs VqppzmSUaGPUPiRl47f7jZ41P9c59b9tGAcZpVTzUm7xdrcHLc2Hem5y9CATYlw9jfFrwt61ggf 031FsPlyrSvRVX0hKsbuzcySxv0oJ5UkafhkClQO9SHoH4xlZGZuQSlEgm6uezEZOkAYRMui/qs g5wPisDYy1Z7gYznnwPXav79vOgwkhsfH9mhhtPIk+WUBHayyu24razuWr4kdn/PQclMSrIvQZK tqccLGeuWCSIJ4nnujcYlJ X-Received: by 2002:a05:6a20:7284:b0:3c0:9c18:d5ab with SMTP id adf61e73a8af0-3c3572a51f1mr1055366637.72.1784007301547; Mon, 13 Jul 2026 22:35:01 -0700 (PDT) Received: from i386.168.1.127 ([2402:a00:163:2ce9:6882:91b7:8e79:7958]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13b659d8da9sm131882715c88.14.2026.07.13.22.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 22:35:01 -0700 (PDT) From: Hrushiraj Gandhi To: linux-rockchip@lists.infradead.org Cc: heiko@sntech.de, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Hrushiraj Gandhi , syzbot+6c25f4750230faf70be9@syzkaller.appspotmail.com Subject: [PATCH v3 1/3] netdevsim: fix use-after-free of ethtool debugfs data Date: Tue, 14 Jul 2026 11:04:39 +0530 Message-ID: <20260714053442.265587-3-hrushirajg23@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260714053442.265587-1-hrushirajg23@gmail.com> References: <20260714053442.265587-1-hrushirajg23@gmail.com> 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 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