blob: 248582c188c65f0f172e5d377d3934b05327ff30 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001From e6b367c0c2668341c47242d099f4d2048ae575ef Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Alin=20N=C4=83stac?= <alin.nastac@gmail.com>
3Date: Thu, 22 Oct 2015 16:41:03 +0200
4Subject: [PATCH 09/10] ebtables: Allow RETURN target rules in user defined
5 chains
6
7During loop checking ebtables marks entries with '1 << NF_BR_NUMHOOKS' if
8they're called from a base chain rather than a user defined chain.
9
10This can be used by ebtables targets that can encode a special return
11value to bail out if e.g. RETURN is used from a base chain.
12
13Unfortunately, this is broken, since the '1 << NF_BR_NUMHOOKS' is also
14copied to called user-defined-chains (i.e., a user defined chain can no
15longer be distinguished from a base chain):
16
17root@OpenWrt:~# ebtables -N foo
18root@OpenWrt:~# ebtables -A OUTPUT -j foo
19root@OpenWrt:~# ebtables -A foo -j mark --mark-or 3 --mark-target RETURN
20--mark-target RETURN not allowed on base chain.
21
22This works if -A OUTPUT -j foo is omitted, but will still appear
23if we try to call foo from OUTPUT afterwards.
24
25After this patch we still reject
26'-A OUTPUT -j mark .. --mark-target RETURN'.
27
28Signed-off-by: Florian Westphal <fw@strlen.de>
29---
30 libebtc.c | 2 +-
31 1 file changed, 1 insertion(+), 1 deletion(-)
32
33diff --git a/libebtc.c b/libebtc.c
34index 17ba8f2..74830ec 100644
35--- a/libebtc.c
36+++ b/libebtc.c
37@@ -1102,7 +1102,7 @@ void ebt_check_for_loops(struct ebt_u_replace *replace)
38 /* check if we've dealt with this chain already */
39 if (entries2->hook_mask & (1<<i))
40 goto letscontinue;
41- entries2->hook_mask |= entries->hook_mask;
42+ entries2->hook_mask |= entries->hook_mask & ~(1 << NF_BR_NUMHOOKS);
43 /* Jump to the chain, make sure we know how to get back */
44 stack[sp].chain_nr = chain_nr;
45 stack[sp].n = j;
46--
472.12.1
48