All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Pablo Neira Ayuso' <pablo@netfilter.org>,
	"netfilter-devel@vger.kernel.org"
	<netfilter-devel@vger.kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: RE: [PATCH 05/10] netfilter: nf_tables: fix mismatch in big-endian system
Date: Thu, 16 Mar 2017 10:58:04 +0000	[thread overview]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6DCFFB26B2@AcuExch.aculab.com> (raw)
In-Reply-To: <1489597272-30347-6-git-send-email-pablo@netfilter.org>

From: Pablo Neira Ayuso
> Sent: 15 March 2017 17:01
> From: Liping Zhang <zlpnobody@gmail.com>
> 
> Currently, there are two different methods to store an u16 integer to
> the u32 data register. For example:
>   u32 *dest = &regs->data[priv->dreg];
>   1. *dest = 0; *(u16 *) dest = val_u16;
>   2. *dest = val_u16;
> 
> For method 1, the u16 value will be stored like this, either in
> big-endian or little-endian system:
>   0          15           31
>   +-+-+-+-+-+-+-+-+-+-+-+-+
>   |   Value   |     0     |
>   +-+-+-+-+-+-+-+-+-+-+-+-+
> 
> For method 2, in little-endian system, the u16 value will be the same
> as listed above. But in big-endian system, the u16 value will be stored
> like this:
>   0          15           31
>   +-+-+-+-+-+-+-+-+-+-+-+-+
>   |     0     |   Value   |
>   +-+-+-+-+-+-+-+-+-+-+-+-+
> 
> So later we use "memcmp(&regs->data[priv->sreg], data, 2);" to do
> compare in nft_cmp, nft_lookup expr ..., method 2 will get the wrong
> result in big-endian system, as 0~15 bits will always be zero.
> 
> For the similar reason, when loading an u16 value from the u32 data
> register, we should use "*(u16 *) sreg;" instead of "(u16)*sreg;",
> the 2nd method will get the wrong value in the big-endian system.
...

That seems to be papering over some of the obvious cracks.

The fact that the entire 32bits are zeroed makes me suspect that
in some places values are written as 8 bits and read later as 32.
The only way that can work on BE is if the values are always written
as 32 bit ones (assignment style 2).

OTOH using memcmp(,,2) relies on the data being in the lower addressed
bytes.

If the data does need to be in the lower addressed bytes I'd suggest
using a union rather than all the casts.

	David

  reply	other threads:[~2017-03-16 10:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 17:01 [PATCH 00/10] Netfilter fixes for net Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 01/10] netfilter: don't track fragmented packets Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 02/10] netfilter: nf_nat_sctp: fix ICMP packet to be dropped accidently Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 03/10] netfilter: nf_tables: set pktinfo->thoff at AH header if found Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 04/10] netfilter: nft_set_bitmap: fetch the element key based on the set->klen Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 05/10] netfilter: nf_tables: fix mismatch in big-endian system Pablo Neira Ayuso
2017-03-16 10:58   ` David Laight [this message]
2017-03-17  4:31     ` Liping Zhang
2017-03-15 17:01 ` [PATCH 06/10] netfilter: bridge: honor frag_max_size when refragmenting Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 07/10] netfilter: Force fake conntrack entry to be at least 8 bytes aligned Pablo Neira Ayuso
2017-03-16  9:55   ` David Laight
2017-03-15 17:01 ` [PATCH 08/10] netfilter: nft_set_bitmap: keep a list of dummy elements Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 09/10] Revert "netfilter: nf_tables: add flush field to struct nft_set_iter" Pablo Neira Ayuso
2017-03-15 17:01 ` [PATCH 10/10] netfilter: nft_ct: do cleanup work when NFTA_CT_DIRECTION is invalid Pablo Neira Ayuso
2017-03-15 22:13 ` [PATCH 00/10] Netfilter fixes for net David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=063D6719AE5E284EB5DD2968C1650D6DCFFB26B2@AcuExch.aculab.com \
    --to=david.laight@aculab.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.