diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 3126911f5042..fc1b337aec8f 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -117,7 +117,8 @@ nf_hook_entries_grow(const struct nf_hook_entries *old, orig_ops = nf_hook_entries_get_hook_ops(old); for (i = 0; i < old_entries; i++) { - if (orig_ops[i] != &dummy_ops) + if (!__kernel_text_address(orig_ops[i]) && + orig_ops[i] != &dummy_ops) alloc_entries++; /* Restrict BPF hook type to force a unique priority, not @@ -146,7 +147,8 @@ nf_hook_entries_grow(const struct nf_hook_entries *old, i = 0; nhooks = 0; while (i < old_entries) { - if (orig_ops[i] == &dummy_ops) { + if (__kernel_text_address(orig_ops[i]) || + orig_ops[i] == &dummy_ops) { ++i; continue; } @@ -263,10 +265,12 @@ static void *__nf_hook_entries_try_shrink(struct nf_hook_entries *old, new_ops = nf_hook_entries_get_hook_ops(new); for (i = 0, j = 0; i < old->num_hook_entries; i++) { - if (orig_ops[i] == &dummy_ops) + if (IS_ERR_OR_NULL(orig_ops[i]) || orig_ops[i] == &dummy_ops) continue; new->hooks[j] = old->hooks[i]; new_ops[j] = (void *)orig_ops[i]; + printk("new ents: %p, new uo h: %p, new ops: %p, %s\n", + new, new->hooks[j], new_ops[j], __func__); j++; } hooks_validate(new); @@ -479,6 +483,7 @@ static bool nf_remove_net_hook(struct nf_hook_entries *old, continue; WRITE_ONCE(old->hooks[i].hook, accept_all); WRITE_ONCE(orig_ops[i], (void *)&dummy_ops); + printk("ents: %p, deled ops: %p, i: %d, %s\n", old, orig_ops[i], i, __func__); return true; }