mbox series

[net-next,0/3] net: device tracking improvements

Message ID 20220204183630.2376998-1-eric.dumazet@gmail.com (mailing list archive)
Headers show
Series net: device tracking improvements | expand

Message

Eric Dumazet Feb. 4, 2022, 6:36 p.m. UTC
From: Eric Dumazet <edumazet@google.com>

Main goal of this series is to be able to detect the following case
which apparently is still haunting us.

dev_hold_track(dev, tracker_1, GFP_ATOMIC);
    dev_hold(dev);
    dev_put(dev);
    dev_put(dev);              // Should complain loudly here.
dev_put_track(dev, tracker_1); // instead of here (as before this series)

Eric Dumazet (3):
  ref_tracker: implement use-after-free detection
  ref_tracker: add a count of untracked references
  net: refine dev_put()/dev_hold() debugging

 include/linux/netdevice.h   | 69 ++++++++++++++++++++++++-------------
 include/linux/ref_tracker.h |  4 +++
 lib/ref_tracker.c           | 17 ++++++++-
 net/core/dev.c              |  2 +-
 4 files changed, 67 insertions(+), 25 deletions(-)

Comments

Eric Dumazet Feb. 4, 2022, 9:51 p.m. UTC | #1
On Fri, Feb 4, 2022 at 10:36 AM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> From: Eric Dumazet <edumazet@google.com>
>
> Main goal of this series is to be able to detect the following case
> which apparently is still haunting us.
>
> dev_hold_track(dev, tracker_1, GFP_ATOMIC);
>     dev_hold(dev);
>     dev_put(dev);
>     dev_put(dev);              // Should complain loudly here.
> dev_put_track(dev, tracker_1); // instead of here (as before this series)


Please do not merge.

I have missed some warnings in my tests, it seems I need to refine
things a bit more.
Eric Dumazet Feb. 4, 2022, 10:24 p.m. UTC | #2
On Fri, Feb 4, 2022 at 1:51 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Fri, Feb 4, 2022 at 10:36 AM Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >
> > From: Eric Dumazet <edumazet@google.com>
> >
> > Main goal of this series is to be able to detect the following case
> > which apparently is still haunting us.
> >
> > dev_hold_track(dev, tracker_1, GFP_ATOMIC);
> >     dev_hold(dev);
> >     dev_put(dev);
> >     dev_put(dev);              // Should complain loudly here.
> > dev_put_track(dev, tracker_1); // instead of here (as before this series)
>
>
> Please do not merge.
>
> I have missed some warnings in my tests, it seems I need to refine
> things a bit more.

I had to add the following on top of the last patch, I will send a V2 soon.

diff --git a/net/core/link_watch.c b/net/core/link_watch.c
index b0f5344d1185be66d05cd1dc50cffc5ccfe883ef..95098d1a49bdf4cbc3ddeb4d345e4276f974a208
100644
--- a/net/core/link_watch.c
+++ b/net/core/link_watch.c
@@ -166,10 +166,10 @@ static void linkwatch_do_dev(struct net_device *dev)

                netdev_state_change(dev);
        }
-       /* Note: our callers are responsible for
-        * calling netdev_tracker_free().
+       /* Note: our callers are responsible for calling netdev_tracker_free().
+        * This is the reason we use __dev_put() instead of dev_put().
         */
-       dev_put(dev);
+       __dev_put(dev);
 }

 static void __linkwatch_run_queue(int urgent_only)