Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_tables: nft_exthdr: the presence return value should be little-endian

On big-endian machine, the returned register data when the exthdr is
present is not being compared correctly because little-endian is
assumed. The function nft_cmp_fast_mask(), called by nft_cmp_fast_eval()
and nft_cmp_fast_init(), calls cpu_to_le32().

The following dump also shows that little endian is assumed:

$ nft --debug=netlink add rule ip recordroute forward ip option rr exists counter
ip
[ exthdr load ipv4 1b @ 7 + 0 present => reg 1 ]
[ cmp eq reg 1 0x01000000 ]
[ counter pkts 0 bytes 0 ]

Lastly, debug print in nft_cmp_fast_init() and nft_cmp_fast_eval() when
RR option exists in the packet shows that the comparison fails because
the assumption:

nft_cmp_fast_init:189 priv->sreg=4 desc.len=8 mask=0xff000000 data.data[0]=0x10003e0
nft_cmp_fast_eval:57 regs->data[priv->sreg=4]=0x1 mask=0xff000000 priv->data=0x1000000

v2: use nft_reg_store8() instead (Florian Westphal). Also to avoid the
warnings reported by kernel test robot.

Fixes: dbb5281a1f84 ("netfilter: nf_tables: add support for matching IPv4 options")
Fixes: c078ca3b0c5b ("netfilter: nft_exthdr: Add support for existence check")
Signed-off-by: Stephen Suryaputra <ssuryaextr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Stephen Suryaputra and committed by
Pablo Neira Ayuso
b4283366 7c7ab580

+2 -2
+2 -2
net/netfilter/nft_exthdr.c
··· 44 44 45 45 err = ipv6_find_hdr(pkt->skb, &offset, priv->type, NULL, NULL); 46 46 if (priv->flags & NFT_EXTHDR_F_PRESENT) { 47 - *dest = (err >= 0); 47 + nft_reg_store8(dest, err >= 0); 48 48 return; 49 49 } else if (err < 0) { 50 50 goto err; ··· 141 141 142 142 err = ipv4_find_option(nft_net(pkt), skb, &offset, priv->type); 143 143 if (priv->flags & NFT_EXTHDR_F_PRESENT) { 144 - *dest = (err >= 0); 144 + nft_reg_store8(dest, err >= 0); 145 145 return; 146 146 } else if (err < 0) { 147 147 goto err;