diff mbox

[net] netfilter: ipt_rpfilter: remove the nh_scope test in rpfilter_lookup_reverse

Message ID e4382c194620c20c80991d4a32618266da4c71df.1444136587.git.lucien.xin@gmail.com
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Xin Long Oct. 6, 2015, 1:03 p.m. UTC
--accept-local  option works for res.type == RTN_LOCAL, which should be from
the local table, but there, the fib_info's nh->nh_scope = RT_SCOPE_NOWHERE
( > RT_SCOPE_HOST). in fib_create_info().

	if (cfg->fc_scope == RT_SCOPE_HOST) {
		struct fib_nh *nh = fi->fib_nh;

		/* Local address is added. */
		if (nhs != 1 || nh->nh_gw)
			goto err_inval;
		nh->nh_scope = RT_SCOPE_NOWHERE;   <===
		nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif);
		err = -ENODEV;
		if (!nh->nh_dev)
			goto failure;

but in our rpfilter_lookup_reverse():

	if (dev_match || flags & XT_RPFILTER_LOOSE)
		return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;

if nh->nh_scope > RT_SCOPE_HOST, it will fail. --accept-local option will never
be passed.

it seems the test is bogus and can be removed to fix this issue.

	if (dev_match || flags & XT_RPFILTER_LOOSE)
		return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;

ipv6 does not have this issue.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/ipv4/netfilter/ipt_rpfilter.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Florian Westphal Oct. 6, 2015, 1:10 p.m. UTC | #1
Xin Long <lucien.xin@gmail.com> wrote:
> --accept-local  option works for res.type == RTN_LOCAL, which should be from
> the local table, but there, the fib_info's nh->nh_scope = RT_SCOPE_NOWHERE
> ( > RT_SCOPE_HOST). in fib_create_info().
> 
> 	if (cfg->fc_scope == RT_SCOPE_HOST) {
 
> but in our rpfilter_lookup_reverse():
> 
> 	if (dev_match || flags & XT_RPFILTER_LOOSE)
> 		return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;
> 
> if nh->nh_scope > RT_SCOPE_HOST, it will fail. --accept-local option will never
> be passed.
> 
> it seems the test is bogus and can be removed to fix this issue.

Yes, you might want to consider submitting a followup patch that cleans
up the ipv4 route handling against net-next tree.

Acked-by: Florian Westphal <fw@strlen.de>
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso Oct. 12, 2015, 3:15 p.m. UTC | #2
On Tue, Oct 06, 2015 at 03:10:22PM +0200, Florian Westphal wrote:
> Xin Long <lucien.xin@gmail.com> wrote:
> > --accept-local  option works for res.type == RTN_LOCAL, which should be from
> > the local table, but there, the fib_info's nh->nh_scope = RT_SCOPE_NOWHERE
> > ( > RT_SCOPE_HOST). in fib_create_info().
> > 
> > 	if (cfg->fc_scope == RT_SCOPE_HOST) {
>  
> > but in our rpfilter_lookup_reverse():
> > 
> > 	if (dev_match || flags & XT_RPFILTER_LOOSE)
> > 		return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;
> > 
> > if nh->nh_scope > RT_SCOPE_HOST, it will fail. --accept-local option will never
> > be passed.
> > 
> > it seems the test is bogus and can be removed to fix this issue.
> 
> Yes, you might want to consider submitting a followup patch that cleans
> up the ipv4 route handling against net-next tree.
> 
> Acked-by: Florian Westphal <fw@strlen.de>

Applied to nf, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c
index 8618fd1..c4ffc9d 100644
--- a/net/ipv4/netfilter/ipt_rpfilter.c
+++ b/net/ipv4/netfilter/ipt_rpfilter.c
@@ -61,9 +61,7 @@  static bool rpfilter_lookup_reverse(struct flowi4 *fl4,
 	if (FIB_RES_DEV(res) == dev)
 		dev_match = true;
 #endif
-	if (dev_match || flags & XT_RPFILTER_LOOSE)
-		return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;
-	return dev_match;
+	return dev_match || flags & XT_RPFILTER_LOOSE;
 }
 
 static bool rpfilter_is_local(const struct sk_buff *skb)