[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250428104434.5d4fab73@device-130.home>
Date: Mon, 28 Apr 2025 10:44:34 +0200
From: Maxime Chevallier <maxime.chevallier@...tlin.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: davem@...emloft.net, Andrew Lunn <andrew@...n.ch>, Eric Dumazet
<edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>, Heiner Kallweit
<hkallweit1@...il.com>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, thomas.petazzoni@...tlin.com,
linux-arm-kernel@...ts.infradead.org, Christophe Leroy
<christophe.leroy@...roup.eu>, Herve Codina <herve.codina@...tlin.com>,
Florian Fainelli <f.fainelli@...il.com>, Russell King
<linux@...linux.org.uk>, Vladimir Oltean <vladimir.oltean@....com>,
Köry Maincent <kory.maincent@...tlin.com>, Oleksij Rempel
<o.rempel@...gutronix.de>, Simon Horman <horms@...nel.org>, Romain Gantois
<romain.gantois@...tlin.com>, Piergiorgio Beruto
<piergiorgio.beruto@...il.com>
Subject: Re: [PATCH net-next v7 1/3] net: ethtool: Introduce per-PHY DUMP
operations
On Fri, 25 Apr 2025 17:10:44 -0700
Jakub Kicinski <kuba@...nel.org> wrote:
> On Fri, 25 Apr 2025 09:01:53 +0200 Maxime Chevallier wrote:
> > > > +/* perphy ->dumpit() handler for GET requests. */
> > > > +static int ethnl_perphy_dumpit(struct sk_buff *skb,
> > > > + struct netlink_callback *cb)
> > > > +{
> > > > + struct ethnl_perphy_dump_ctx *ctx = ethnl_perphy_dump_context(cb);
> > > > + struct ethnl_dump_ctx *ethnl_ctx = &ctx->ethnl_ctx;
> > > > + int ret = 0;
> > > > +
> > > > + if (ethnl_ctx->req_info->dev) {
> > > > + ret = ethnl_perphy_dump_one_dev(skb, ethnl_ctx->req_info->dev,
> > > > + ctx, genl_info_dump(cb));
> > > > + if (ret < 0 && ret != -EOPNOTSUPP && likely(skb->len))
> > > > + ret = skb->len;
> > > > +
> > > > + netdev_put(ethnl_ctx->req_info->dev,
> > > > + ðnl_ctx->req_info->dev_tracker);
> > >
> > > You have to release this in .done
> > > dumpit gets called multiple times until we run out of objects to dump.
> > > OTOH user may close the socket without finishing the dump operation.
> > > So all .dumpit implementations must be "balanced". The only state we
> > > should touch in them is the dump context to know where to pick up from
> > > next time.
> >
> > Thanks for poiting it out.
> >
> > Now that you say that, I guess that I should also move the reftracker
> > I'm using for the netdev_hold in ethnl_perphy_dump_one_dev() call to
> > struct ethnl_perphy_dump_ctx ? That way we make sure the netdev doesn't
> > go away in-between the multiple .dumpit() calls then...
> >
> > Is that correct ?
>
> Probably not. That'd allow an unprivileged user space program to take
> a ref on a netdev, and never call recv() to make progress on the dump.
>
> The possibility that the netdev may disappear half way thru is inherent
> to the netlink dump model. We will pick back up within that netdev
> based on its ifindex, no need to hold it.
OK I'm good with that then ! Thanks for the explanations, makes a lot
of sense. I'll followup with a new version soon :)
Maxime
Powered by blists - more mailing lists