From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Liping Zhang <zlpnobody@163.com>
Cc: netfilter-devel@vger.kernel.org, Liping Zhang <zlpnobody@gmail.com>
Subject: Re: [PATCH nf] netfilter: nf_tables: fix missmatch in big-endian system
Date: Mon, 13 Mar 2017 13:31:16 +0100 [thread overview]
Message-ID: <20170313123116.GA6513@salvia> (raw)
In-Reply-To: <1488984858-29290-1-git-send-email-zlpnobody@163.com>
On Wed, Mar 08, 2017 at 10:54:18PM +0800, Liping Zhang wrote:
> 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 = ®s->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(®s->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.
>
> So introduce some wrapper functions to store/load an u8 or u16
> integer to/from the u32 data register, and use them in the right
> place.
Applied, thanks.
prev parent reply other threads:[~2017-03-13 12:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 14:54 [PATCH nf] netfilter: nf_tables: fix missmatch in big-endian system Liping Zhang
2017-03-09 10:36 ` Arturo Borrero Gonzalez
2017-03-09 12:46 ` Liping Zhang
2017-03-09 15:29 ` Arturo Borrero Gonzalez
2017-03-13 12:31 ` Pablo Neira Ayuso [this message]
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=20170313123116.GA6513@salvia \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=zlpnobody@163.com \
--cc=zlpnobody@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).