Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH net] ethtool: tsinfo: avoid holding a netdev reference across dumps
@ 2026-11-30 10:11 Zhao Gongyi
  2026-12-04  9:59 ` Kory Maincent
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Gongyi @ 2026-11-30 10:11 UTC (permalink / raw)
  To: netdev, Andrew Lunn, Jakub Kicinski
  Cc: Zhao Gongyi, David S . Miller, Eric Dumazet, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Kory Maincent, Hui Peng, stable

A syzkaller workload issuing filtered TSINFO dumps reproduced a device
unregister stall on arm64. A reduced six-call syzkaller program also
reproduced the stall. With CONFIG_NET_DEV_REFCNT_TRACKER enabled, the
remaining tracked reference was attributed to ethnl_tsinfo_start():

  unregister_netdevice: waiting for syz_tun to become free. Usage count = 2
  ref_tracker: netdev@0000000068a552dd has 1/1 users at
       netdev_get_by_index+0x54/0x98
       ethnl_parse_header_dev_get+0xb0/0x2d4
       ethnl_tsinfo_start+0x7c/0x164
       genl_start+0x124/0x1a8
       __netlink_dump_start+0x17c/0x2bc

Filtered dumps retain this reference from .start() until .done(), making
device removal depend on dump completion or socket teardown. This does
not require a multi-skb reply: the initial netlink_dump() can fail its
allocation or receive-buffer checks before calling .dumpit(), leaving
the dump active for a later recvmsg() or socket release.

Save the requested ifindex and release the parsed reference in .start().
Look up the device under the ops compat lock for each dump callback,
validating registration and namespace state before accessing it. Return
-ENODEV if the device is no longer available.

On the older arm64 test kernel, replays of the reduced syzkaller
program with this fix reported no crash in a 30-second run and a
six-minute run.

Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Gongyi <zhaogongyi@bytedance.com>
---
Earlier proposal by Hui Peng:
  https://lore.kernel.org/netdev/20260919204803.2811673-1-benquike@gmail.com/
Maintainer feedback:
  https://lore.kernel.org/netdev/20260924090715.029f1550@kernel.org/

This version uses the ops-compat lookup helper to validate the device
under the lock.

Runtime testing used the older arm64 setup tagged
 af32da41b0327b9c6a37856ba82b6760d6c8d10e-mpam-workaround,
rather than the net/main base below. The unpatched failure is from
November 28; the fixed replays are from November 30. Contemporaneous
Image/config hashes are missing for the unpatched run, so these
records do not establish a paired runtime test on the submission base.

Build comparison on the net/main base used arm64 GCC 8.3 / binutils
2.31.1, W=1, and allyesconfig/allmodconfig with CONFIG_WERROR=n.
Clean builds before and after this patch produced identical warning
and error diagnostics in each configuration. tsinfo.o compiled without
diagnostics. All four full builds failed at the same EFI zboot link:
  ld: unknown architecture of input file 'arch/arm64/boot/vmlinuz.o'
      is incompatible with aarch64 output

 net/ethtool/tsinfo.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
index c9b680a9cc3fd080f032e3b38dd6afc4999eed14..5e3939ac4408a4d9523e348846e112a82902c5cc 100644
--- a/net/ethtool/tsinfo.c
+++ b/net/ethtool/tsinfo.c
@@ -297,6 +297,7 @@ struct ethnl_tsinfo_dump_ctx {
 	bool				netdev_dump_done;
 	unsigned long			pos_phyindex;
 	enum hwtstamp_provider_qualifier pos_phcqualifier;
+	int				req_ifindex;
 };
 
 static void *ethnl_tsinfo_prepare_dump(struct sk_buff *skb,
@@ -476,10 +477,12 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 	struct net *net = sock_net(skb->sk);
 	int ret = 0;
 
-	if (ctx->req_info->base.dev) {
-		struct net_device *dev = ctx->req_info->base.dev;
+	if (ctx->req_ifindex) {
+		struct net_device *dev;
 
-		netdev_lock_ops_compat(dev);
+		dev = netdev_get_by_index_lock_ops_compat(net, ctx->req_ifindex);
+		if (!dev)
+			return -ENODEV;
 		ret = ethnl_tsinfo_dump_one_net_topo(skb, dev, cb);
 		netdev_unlock_ops_compat(dev);
 		return ret;
@@ -530,6 +533,12 @@ int ethnl_tsinfo_start(struct netlink_callback *cb)
 		goto err_dev_put;
 	}
 
+	if (req_info->base.dev) {
+		ctx->req_ifindex = req_info->base.dev->ifindex;
+		ethnl_parse_header_dev_put(&req_info->base);
+		req_info->base.dev = NULL;
+	}
+
 	ctx->req_info = req_info;
 	ctx->reply_data = reply_data;
 	ctx->pos_ifindex = 0;

base-commit: e2fb9368a41662bc54624f9be87ea8989b109306

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] ethtool: tsinfo: avoid holding a netdev reference across dumps
  2026-11-30 10:11 [PATCH net] ethtool: tsinfo: avoid holding a netdev reference across dumps Zhao Gongyi
@ 2026-12-04  9:59 ` Kory Maincent
  0 siblings, 0 replies; 2+ messages in thread
From: Kory Maincent @ 2026-12-04  9:59 UTC (permalink / raw)
  To: Zhao Gongyi, netdev, Andrew Lunn, Jakub Kicinski
  Cc: David S . Miller, Eric Dumazet, Paolo Abeni, Willem de Bruijn,
	Simon Horman, Hui Peng, stable



On 11/30/26 11:11, Zhao Gongyi wrote:
> A syzkaller workload issuing filtered TSINFO dumps reproduced a device
> unregister stall on arm64. A reduced six-call syzkaller program also
> reproduced the stall. With CONFIG_NET_DEV_REFCNT_TRACKER enabled, the
> remaining tracked reference was attributed to ethnl_tsinfo_start():
> 
>    unregister_netdevice: waiting for syz_tun to become free. Usage count = 2
>    ref_tracker: netdev@0000000068a552dd has 1/1 users at
>         netdev_get_by_index+0x54/0x98
>         ethnl_parse_header_dev_get+0xb0/0x2d4
>         ethnl_tsinfo_start+0x7c/0x164
>         genl_start+0x124/0x1a8
>         __netlink_dump_start+0x17c/0x2bc
> 
> Filtered dumps retain this reference from .start() until .done(), making
> device removal depend on dump completion or socket teardown. This does
> not require a multi-skb reply: the initial netlink_dump() can fail its
> allocation or receive-buffer checks before calling .dumpit(), leaving
> the dump active for a later recvmsg() or socket release.
> 
> Save the requested ifindex and release the parsed reference in .start().
> Look up the device under the ops compat lock for each dump callback,
> validating registration and namespace state before accessing it. Return
> -ENODEV if the device is no longer available.
> 
> On the older arm64 test kernel, replays of the reduced syzkaller
> program with this fix reported no crash in a 30-second run and a
> six-minute run.

Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>

Thank you!
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 10:11 [PATCH net] ethtool: tsinfo: avoid holding a netdev reference across dumps Zhao Gongyi
2026-12-04  9:59 ` Kory Maincent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox