summaryrefslogtreecommitdiffstats
path: root/lib/ref_tracker.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2022-02-04 23:42:35 +0100
committerDavid S. Miller <davem@davemloft.net>2022-02-05 16:22:44 +0100
commite3ececfe668facd87d920b608349a32607060e66 (patch)
tree99cee105c8bf97b641e5d1121e8a778c0c5149d3 /lib/ref_tracker.c
parentMerge branch 'ipv6-mc_forwarding-changes' (diff)
downloadlinux-e3ececfe668facd87d920b608349a32607060e66.tar.xz
linux-e3ececfe668facd87d920b608349a32607060e66.zip
ref_tracker: implement use-after-free detection
Whenever ref_tracker_dir_init() is called, mark the struct ref_tracker_dir as dead. Test the dead status from ref_tracker_alloc() and ref_tracker_free() This should detect buggy dev_put()/dev_hold() happening too late in netdevice dismantle process. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/ref_tracker.c')
-rw-r--r--lib/ref_tracker.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index a6789c0c626b..32ff6bd497f8 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -20,6 +20,7 @@ void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
unsigned long flags;
bool leak = false;
+ dir->dead = true;
spin_lock_irqsave(&dir->lock, flags);
list_for_each_entry_safe(tracker, n, &dir->quarantine, head) {
list_del(&tracker->head);
@@ -72,6 +73,8 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir,
gfp_t gfp_mask = gfp;
unsigned long flags;
+ WARN_ON_ONCE(dir->dead);
+
if (gfp & __GFP_DIRECT_RECLAIM)
gfp_mask |= __GFP_NOFAIL;
*trackerp = tracker = kzalloc(sizeof(*tracker), gfp_mask);
@@ -100,6 +103,8 @@ int ref_tracker_free(struct ref_tracker_dir *dir,
unsigned int nr_entries;
unsigned long flags;
+ WARN_ON_ONCE(dir->dead);
+
if (!tracker) {
refcount_dec(&dir->untracked);
return -EEXIST;