Skip to content

Commit 63331e3

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: fix 'exist' matching on bigendian arches
Maze reports "tcp option fastopen exists" fails to match on OpenWrt 22.03.5, r20134-5f15225c1e (5.10.176) router. "tcp option fastopen exists" translates to: inet [ exthdr load tcpopt 1b @ 34 + 0 present => reg 1 ] [ cmp eq reg 1 0x00000001 ] .. but existing nft userspace generates a 1-byte compare. On LSB (x86), "*reg32 = 1" is identical to nft_reg_store8(reg32, 1), but not on MSB, which will place the 1 last. IOW, on bigendian aches the cmp8 is awalys false. Make sure we store this in a consistent fashion, so existing userspace will also work on MSB (bigendian). Regardless of this patch we can also change nft userspace to generate 'reg32 == 0' and 'reg32 != 0' instead of u8 == 0 // u8 == 1 when adding 'option x missing/exists' expressions as well. Fixes: 3c1fece ("netfilter: nft_exthdr: Allow checking TCP option presence, too") Fixes: b9f9a48 ("netfilter: nft_exthdr: add boolean DCCP option matching") Fixes: 055c4b3 ("netfilter: nft_fib: Support existence check") Reported-by: Maciej Żenczykowski <zenczykowski@gmail.com> Closes: https://lore.kernel.org/netfilter-devel/CAHo-OozyEqHUjL2-ntATzeZOiuftLWZ_HU6TOM_js4qLfDEAJg@mail.gmail.com/ Signed-off-by: Florian Westphal <fw@strlen.de> Acked-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 317eb96 commit 63331e3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

net/netfilter/nft_exthdr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void nft_exthdr_tcp_eval(const struct nft_expr *expr,
214214

215215
offset = i + priv->offset;
216216
if (priv->flags & NFT_EXTHDR_F_PRESENT) {
217-
*dest = 1;
217+
nft_reg_store8(dest, 1);
218218
} else {
219219
if (priv->len % NFT_REG32_SIZE)
220220
dest[priv->len / NFT_REG32_SIZE] = 0;
@@ -461,7 +461,7 @@ static void nft_exthdr_dccp_eval(const struct nft_expr *expr,
461461
type = bufp[0];
462462

463463
if (type == priv->type) {
464-
*dest = 1;
464+
nft_reg_store8(dest, 1);
465465
return;
466466
}
467467

net/netfilter/nft_fib.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,15 @@ void nft_fib_store_result(void *reg, const struct nft_fib *priv,
145145
switch (priv->result) {
146146
case NFT_FIB_RESULT_OIF:
147147
index = dev ? dev->ifindex : 0;
148-
*dreg = (priv->flags & NFTA_FIB_F_PRESENT) ? !!index : index;
148+
if (priv->flags & NFTA_FIB_F_PRESENT)
149+
nft_reg_store8(dreg, !!index);
150+
else
151+
*dreg = index;
152+
149153
break;
150154
case NFT_FIB_RESULT_OIFNAME:
151155
if (priv->flags & NFTA_FIB_F_PRESENT)
152-
*dreg = !!dev;
156+
nft_reg_store8(dreg, !!dev);
153157
else
154158
strscpy_pad(reg, dev ? dev->name : "", IFNAMSIZ);
155159
break;

0 commit comments

Comments
 (0)