* [PATCH net-next v2] ipv6: fib6_rules should return exact return value
@ 2013-08-01 6:54 Hannes Frederic Sowa
2013-08-01 7:26 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Hannes Frederic Sowa @ 2013-08-01 6:54 UTC (permalink / raw)
To: netdev; +Cc: stefan.tomanek, yoshfuji
With the addition of the suppress operation
(7764a45a8f1fe74d4f7d301eaca2e558e7e2831a ("fib_rules: add .suppress
operation") we rely on accurate error reporting of the fib_rules.actions.
fib6_rule_action always returned -EAGAIN in case we could not find a
matching route and 0 if a rule was matched. This also included a match
for blackhole or prohibited rule actions which could get suppressed by
the new logic.
So adapt fib6_rule_action to always return the correct error code as
its counterpart fib4_rule_action does. This also fixes a possiblity of
nullptr-deref where we don't find a table, thus rt == NULL. Because
the condition rt != ip6_null_entry still holdes it seems we could later
get a nullptr bug on dereference rt->dst.
v2:
a) Fixed a brain fart in the commit msg (the rule => a table, etc). No
changes to the patch.
Cc: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
net/ipv6/fib6_rules.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index e64e6a5..554a4fb 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -55,26 +55,33 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
struct fib6_table *table;
struct net *net = rule->fr_net;
pol_lookup_t lookup = arg->lookup_ptr;
+ int err = 0;
switch (rule->action) {
case FR_ACT_TO_TBL:
break;
case FR_ACT_UNREACHABLE:
+ err = -ENETUNREACH;
rt = net->ipv6.ip6_null_entry;
goto discard_pkt;
default:
case FR_ACT_BLACKHOLE:
+ err = -EINVAL;
rt = net->ipv6.ip6_blk_hole_entry;
goto discard_pkt;
case FR_ACT_PROHIBIT:
+ err = -EACCES;
rt = net->ipv6.ip6_prohibit_entry;
goto discard_pkt;
}
table = fib6_get_table(net, rule->table);
- if (table)
- rt = lookup(net, table, flp6, flags);
+ if (!table) {
+ err = -EAGAIN;
+ goto out;
+ }
+ rt = lookup(net, table, flp6, flags);
if (rt != net->ipv6.ip6_null_entry) {
struct fib6_rule *r = (struct fib6_rule *)rule;
@@ -101,6 +108,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
}
again:
ip6_rt_put(rt);
+ err = -EAGAIN;
rt = NULL;
goto out;
@@ -108,7 +116,7 @@ discard_pkt:
dst_hold(&rt->dst);
out:
arg->result = rt;
- return rt == NULL ? -EAGAIN : 0;
+ return err;
}
static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next v2] ipv6: fib6_rules should return exact return value
2013-08-01 6:54 [PATCH net-next v2] ipv6: fib6_rules should return exact return value Hannes Frederic Sowa
@ 2013-08-01 7:26 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2013-08-01 7:26 UTC (permalink / raw)
To: hannes; +Cc: netdev, stefan.tomanek, yoshfuji
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date: Thu, 1 Aug 2013 08:54:47 +0200
> With the addition of the suppress operation
> (7764a45a8f1fe74d4f7d301eaca2e558e7e2831a ("fib_rules: add .suppress
> operation") we rely on accurate error reporting of the fib_rules.actions.
>
> fib6_rule_action always returned -EAGAIN in case we could not find a
> matching route and 0 if a rule was matched. This also included a match
> for blackhole or prohibited rule actions which could get suppressed by
> the new logic.
>
> So adapt fib6_rule_action to always return the correct error code as
> its counterpart fib4_rule_action does. This also fixes a possiblity of
> nullptr-deref where we don't find a table, thus rt == NULL. Because
> the condition rt != ip6_null_entry still holdes it seems we could later
> get a nullptr bug on dereference rt->dst.
>
> v2:
> a) Fixed a brain fart in the commit msg (the rule => a table, etc). No
> changes to the patch.
>
> Cc: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
> Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Looks good, applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-08-01 7:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-01 6:54 [PATCH net-next v2] ipv6: fib6_rules should return exact return value Hannes Frederic Sowa
2013-08-01 7:26 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).