All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liping Zhang <zlpnobody@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
	"netfilter-devel@vger.kernel.org"
	<netfilter-devel@vger.kernel.org>,
	"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: Fri, 17 Mar 2017 12:31:53 +0800	[thread overview]
Message-ID: <CAML_gOdW4ur_CgxLF6_DG5N1QHOv+6qjiMXQFCOYEr82EV3O=A@mail.gmail.com> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DCFFB26B2@AcuExch.aculab.com>

Hi David,
2017-03-16 18:58 GMT+08:00 David Laight <David.Laight@aculab.com>:
[...]
>> 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).

In nftables, user can use concatenations to put two or more selectors together.
For example, we can use "nft add rule x y tcp dport . ip saddr 22 . 1.1.1.1"
to match the tcp dest port and ip source addr at the same time.

In such case, tcp dport will be stored to REG0 and ip saddr will be stored to
REG1, so the layout will be like this(from the lowest address):
  PORT(2 bytes) - XXXX(2 bytes) - IPADDR(4 bytes)

Later we will use the statement "memcmp(&reg, &data, 8)" to do compare,
so the XXXX part must be filled with zero to avoid garbage value.

>
> 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-17  4:31 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
2017-03-17  4:31     ` Liping Zhang [this message]
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='CAML_gOdW4ur_CgxLF6_DG5N1QHOv+6qjiMXQFCOYEr82EV3O=A@mail.gmail.com' \
    --to=zlpnobody@gmail.com \
    --cc=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.