Skip to content

Commit 85704cb

Browse files
koct9idavem330
authored andcommitted
net/core/neighbour: tell kmemleak about hash tables
This fixes false-positive kmemleak reports about leaked neighbour entries: unreferenced object 0xffff8885c6e4d0a8 (size 1024): comm "softirq", pid 0, jiffies 4294922664 (age 167640.804s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 20 2c f3 83 ff ff ff ff ........ ,...... 08 c0 ef 5f 84 88 ff ff 01 8c 7d 02 01 00 00 00 ..._......}..... backtrace: [<00000000748509fe>] ip6_finish_output2+0x887/0x1e40 [<0000000036d7a0d8>] ip6_output+0x1ba/0x600 [<0000000027ea7dba>] ip6_send_skb+0x92/0x2f0 [<00000000d6e2111d>] udp_v6_send_skb.isra.24+0x680/0x15e0 [<000000000668a8be>] udpv6_sendmsg+0x18c9/0x27a0 [<000000004bd5fa90>] sock_sendmsg+0xb3/0xf0 [<000000008227b29f>] ___sys_sendmsg+0x745/0x8f0 [<000000008698009d>] __sys_sendmsg+0xde/0x170 [<00000000889dacf1>] do_syscall_64+0x9b/0x400 [<0000000081cdb353>] entry_SYSCALL_64_after_hwframe+0x49/0xbe [<000000005767ed39>] 0xffffffffffffffff Signed-off-by: Konstantin Khlebnikov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fd21c89 commit 85704cb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/core/neighbour.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1919

2020
#include <linux/slab.h>
21+
#include <linux/kmemleak.h>
2122
#include <linux/types.h>
2223
#include <linux/kernel.h>
2324
#include <linux/module.h>
@@ -443,12 +444,14 @@ static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift)
443444
ret = kmalloc(sizeof(*ret), GFP_ATOMIC);
444445
if (!ret)
445446
return NULL;
446-
if (size <= PAGE_SIZE)
447+
if (size <= PAGE_SIZE) {
447448
buckets = kzalloc(size, GFP_ATOMIC);
448-
else
449+
} else {
449450
buckets = (struct neighbour __rcu **)
450451
__get_free_pages(GFP_ATOMIC | __GFP_ZERO,
451452
get_order(size));
453+
kmemleak_alloc(buckets, size, 0, GFP_ATOMIC);
454+
}
452455
if (!buckets) {
453456
kfree(ret);
454457
return NULL;
@@ -468,10 +471,12 @@ static void neigh_hash_free_rcu(struct rcu_head *head)
468471
size_t size = (1 << nht->hash_shift) * sizeof(struct neighbour *);
469472
struct neighbour __rcu **buckets = nht->hash_buckets;
470473

471-
if (size <= PAGE_SIZE)
474+
if (size <= PAGE_SIZE) {
472475
kfree(buckets);
473-
else
476+
} else {
477+
kmemleak_free(buckets);
474478
free_pages((unsigned long)buckets, get_order(size));
479+
}
475480
kfree(nht);
476481
}
477482

0 commit comments

Comments
 (0)