diff options
author | Denis V. Lunev <den@openvz.org> | 2007-11-11 01:12:03 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-11-11 01:12:03 -0500 |
commit | 2994c63863ac350c4c8c6a65d8110749c2abb95c (patch) | |
tree | 5509f71222641098683df1b1e0ff7bdfc2758b2c /net/ipv4/fib_rules.c | |
parent | 33d36bb83c5b566c98a441e791736e25dbc35fc3 (diff) |
[INET]: Small possible memory leak in FIB rules
This patch fixes a small memory leak. Default fib rules can be deleted by
the user if the rule does not carry FIB_RULE_PERMANENT flag, f.e. by
ip rule flush
Such a rule will not be freed as the ref-counter has 2 on start and becomes
clearly unreachable after removal.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Acked-by: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/fib_rules.c')
-rw-r--r-- | net/ipv4/fib_rules.c | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index f16839c6a721..a0ada3a8d8dd 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c | |||
@@ -49,33 +49,6 @@ struct fib4_rule | |||
49 | #endif | 49 | #endif |
50 | }; | 50 | }; |
51 | 51 | ||
52 | static struct fib4_rule default_rule = { | ||
53 | .common = { | ||
54 | .refcnt = ATOMIC_INIT(2), | ||
55 | .pref = 0x7FFF, | ||
56 | .table = RT_TABLE_DEFAULT, | ||
57 | .action = FR_ACT_TO_TBL, | ||
58 | }, | ||
59 | }; | ||
60 | |||
61 | static struct fib4_rule main_rule = { | ||
62 | .common = { | ||
63 | .refcnt = ATOMIC_INIT(2), | ||
64 | .pref = 0x7FFE, | ||
65 | .table = RT_TABLE_MAIN, | ||
66 | .action = FR_ACT_TO_TBL, | ||
67 | }, | ||
68 | }; | ||
69 | |||
70 | static struct fib4_rule local_rule = { | ||
71 | .common = { | ||
72 | .refcnt = ATOMIC_INIT(2), | ||
73 | .table = RT_TABLE_LOCAL, | ||
74 | .action = FR_ACT_TO_TBL, | ||
75 | .flags = FIB_RULE_PERMANENT, | ||
76 | }, | ||
77 | }; | ||
78 | |||
79 | #ifdef CONFIG_NET_CLS_ROUTE | 52 | #ifdef CONFIG_NET_CLS_ROUTE |
80 | u32 fib_rules_tclass(struct fib_result *res) | 53 | u32 fib_rules_tclass(struct fib_result *res) |
81 | { | 54 | { |
@@ -319,11 +292,27 @@ static struct fib_rules_ops fib4_rules_ops = { | |||
319 | .owner = THIS_MODULE, | 292 | .owner = THIS_MODULE, |
320 | }; | 293 | }; |
321 | 294 | ||
322 | void __init fib4_rules_init(void) | 295 | static int __init fib_default_rules_init(void) |
323 | { | 296 | { |
324 | list_add_tail(&local_rule.common.list, &fib4_rules_ops.rules_list); | 297 | int err; |
325 | list_add_tail(&main_rule.common.list, &fib4_rules_ops.rules_list); | 298 | |
326 | list_add_tail(&default_rule.common.list, &fib4_rules_ops.rules_list); | 299 | err = fib_default_rule_add(&fib4_rules_ops, 0, |
300 | RT_TABLE_LOCAL, FIB_RULE_PERMANENT); | ||
301 | if (err < 0) | ||
302 | return err; | ||
303 | err = fib_default_rule_add(&fib4_rules_ops, 0x7FFE, | ||
304 | RT_TABLE_MAIN, 0); | ||
305 | if (err < 0) | ||
306 | return err; | ||
307 | err = fib_default_rule_add(&fib4_rules_ops, 0x7FFF, | ||
308 | RT_TABLE_DEFAULT, 0); | ||
309 | if (err < 0) | ||
310 | return err; | ||
311 | return 0; | ||
312 | } | ||
327 | 313 | ||
314 | void __init fib4_rules_init(void) | ||
315 | { | ||
316 | BUG_ON(fib_default_rules_init()); | ||
328 | fib_rules_register(&fib4_rules_ops); | 317 | fib_rules_register(&fib4_rules_ops); |
329 | } | 318 | } |