Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: unregister nf hooks, matches and targets in the reverse order

Since we register nf hooks, matches and targets in order, we'd better
unregister them in the reverse order.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>

authored by

Changli Gao and committed by
Patrick McHardy
f68c5301 e55df53d

+6 -12
+2 -4
net/netfilter/core.c
··· 105 105 106 106 void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n) 107 107 { 108 - unsigned int i; 109 - 110 - for (i = 0; i < n; i++) 111 - nf_unregister_hook(&reg[i]); 108 + while (n-- > 0) 109 + nf_unregister_hook(&reg[n]); 112 110 } 113 111 EXPORT_SYMBOL(nf_unregister_hooks); 114 112
+4 -8
net/netfilter/x_tables.c
··· 116 116 void 117 117 xt_unregister_targets(struct xt_target *target, unsigned int n) 118 118 { 119 - unsigned int i; 120 - 121 - for (i = 0; i < n; i++) 122 - xt_unregister_target(&target[i]); 119 + while (n-- > 0) 120 + xt_unregister_target(&target[n]); 123 121 } 124 122 EXPORT_SYMBOL(xt_unregister_targets); 125 123 ··· 172 174 void 173 175 xt_unregister_matches(struct xt_match *match, unsigned int n) 174 176 { 175 - unsigned int i; 176 - 177 - for (i = 0; i < n; i++) 178 - xt_unregister_match(&match[i]); 177 + while (n-- > 0) 178 + xt_unregister_match(&match[n]); 179 179 } 180 180 EXPORT_SYMBOL(xt_unregister_matches); 181 181