lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon,  6 Dec 2021 23:02:07 -0500
From:   Xin Long <lucien.xin@...il.com>
To:     network dev <netdev@...r.kernel.org>
Cc:     Eric Dumazet <edumazet@...gle.com>, davem@...emloft.net,
        kuba@...nel.org,
        Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
        Davide Caratti <dcaratti@...hat.com>,
        Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH net-next 4/5] net: track in6_dev refcnt with obj_cnt

Two types are added into obj_cnt to count in6_dev_hold/get and in6_dev_put,
and all it does is put obj_cnt_track_by_dev() into these two functions.

Here is an example to track the refcnt of a in6_dev which is attached
on a netdev named dummy0:

  # sysctl -w obj_cnt.control="clear" # clear the old result

  # sysctl -w obj_cnt.type=0x30    # enable in6_dev_hold/put track
  # sysctl -w obj_cnt.name=dummy0  # count in6_dev_hold/put(in6_dev)
  # sysctl -w obj_cnt.nr_entries=4 # save 4 frames' call trace

  # ip link add dummy0 type dummy
  # ip link set dummy0 up
  # ip addr add 2020::1/64 dev dummy0
  # ip link set dummy0 down
  # ip link del dummy0

  # sysctl -w obj_cnt.control="scan"  # print the new result
  # dmesg
  OBJ_CNT: obj_cnt_dump: obj: ffff8a1e17906000, type: in6_dev_put, cnt: 1,:
       ipv6_mc_down+0x11e/0x1a0
       addrconf_ifdown+0x53c/0x670
       addrconf_notify+0xb8/0x940
       raw_notifier_call_chain+0x41/0x50
  OBJ_CNT: obj_cnt_dump: obj: ffff8a1e17906000, type: in6_dev_put, cnt: 1,:
       ma_put+0x4f/0xb0
       ipv6_mc_destroy_dev+0x150/0x180
       addrconf_ifdown+0x478/0x670
       addrconf_notify+0xb8/0x940
  ...
  OBJ_CNT: obj_cnt_dump: obj: ffff8a1e17906000, type: in6_dev_hold, cnt: 2,:
       fib6_nh_init+0x6b4/0x8f0
       ip6_route_info_create+0x4f2/0x670
       ip6_route_add+0x18/0x90
       addrconf_prefix_route.isra.50+0x100/0x150
  OBJ_CNT: obj_cnt_dump: obj: ffff8a1e17906000, type: in6_dev_hold, cnt: 2,:
       fib6_nh_init+0x6b4/0x8f0
       ip6_route_info_create+0x4f2/0x670
       addrconf_f6i_alloc+0xe3/0x130
       ipv6_add_addr+0x16a/0x740
  ...

Signed-off-by: Xin Long <lucien.xin@...il.com>
---
 include/linux/obj_cnt.h | 2 ++
 include/net/addrconf.h  | 7 ++++++-
 lib/obj_cnt.c           | 4 +++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/obj_cnt.h b/include/linux/obj_cnt.h
index ae4c12beb876..f014b2e613d9 100644
--- a/include/linux/obj_cnt.h
+++ b/include/linux/obj_cnt.h
@@ -7,6 +7,8 @@ enum {
 	OBJ_CNT_DEV_PUT,
 	OBJ_CNT_DST_HOLD,
 	OBJ_CNT_DST_PUT,
+	OBJ_CNT_IN6_DEV_HOLD,
+	OBJ_CNT_IN6_DEV_PUT,
 	OBJ_CNT_TYPE_MAX
 };
 
diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 78ea3e332688..370a96b57dbd 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -357,8 +357,10 @@ static inline struct inet6_dev *in6_dev_get(const struct net_device *dev)
 
 	rcu_read_lock();
 	idev = rcu_dereference(dev->ip6_ptr);
-	if (idev)
+	if (idev) {
+		obj_cnt_track_by_dev(idev, idev->dev, OBJ_CNT_IN6_DEV_HOLD);
 		refcount_inc(&idev->refcnt);
+	}
 	rcu_read_unlock();
 	return idev;
 }
@@ -374,6 +376,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev);
 
 static inline void in6_dev_put(struct inet6_dev *idev)
 {
+	obj_cnt_track_by_dev(idev, idev->dev, OBJ_CNT_IN6_DEV_PUT);
 	if (refcount_dec_and_test(&idev->refcnt))
 		in6_dev_finish_destroy(idev);
 }
@@ -390,11 +393,13 @@ static inline void in6_dev_put_clear(struct inet6_dev **pidev)
 
 static inline void __in6_dev_put(struct inet6_dev *idev)
 {
+	obj_cnt_track_by_dev(idev, idev->dev, OBJ_CNT_IN6_DEV_PUT);
 	refcount_dec(&idev->refcnt);
 }
 
 static inline void in6_dev_hold(struct inet6_dev *idev)
 {
+	obj_cnt_track_by_dev(idev, idev->dev, OBJ_CNT_IN6_DEV_HOLD);
 	refcount_inc(&idev->refcnt);
 }
 
diff --git a/lib/obj_cnt.c b/lib/obj_cnt.c
index 648adc135080..8756efc005ed 100644
--- a/lib/obj_cnt.c
+++ b/lib/obj_cnt.c
@@ -18,7 +18,9 @@ static char *obj_cnt_str[OBJ_CNT_TYPE_MAX] = {
 	"dev_hold",
 	"dev_put",
 	"dst_hold",
-	"dst_put"
+	"dst_put",
+	"in6_dev_hold",
+	"in6_dev_put"
 };
 
 struct obj_cnt {
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ