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 1/2] netfilter: nft_set_bitmap: fetch the element key based on the set->klen
Date: Mon, 13 Mar 2017 13:29:19 +0100 [thread overview]
Message-ID: <20170313122919.GA6165@salvia> (raw)
In-Reply-To: <1488729773-48343-1-git-send-email-zlpnobody@163.com>
On Mon, Mar 06, 2017 at 12:02:52AM +0800, Liping Zhang wrote:
> From: Liping Zhang <zlpnobody@gmail.com>
>
> Currently we just assume the element key as a u32 integer, regardless of
> the set key length.
>
> This is incorrect, for example, the tcp port number is only 16 bits.
> So when we use the nft_payload expr to get the tcp dport and store
> it to dreg, the dport will be stored at 0~15 bits, and 16~31 bits
> will be padded with zero.
>
> So the reg->data[dreg] will be looked like as below:
> 0 15 31
> +-+-+-+-+-+-+-+-+-+-+-+-+
> | tcp dport | 0 |
> +-+-+-+-+-+-+-+-+-+-+-+-+
> But for these big-endian systems, if we treate this register as a u32
> integer, the element key will be larger than 65535, so the following
> lookup in bitmap set will cause out of bound access.
>
> Another issue is that if we add element with comments in bitmap
> set(although the comments will be ignored eventually), the element will
> vanish strangely. Because we treate the element key as a u32 integer, so
> the comments will become the part of the element key, then the element
> key will also be larger than 65535 and out of bound access will happen:
> # nft add element t s { 1 comment test }
>
> Since set->klen is 1 or 2, it's fine to treate the element key as a u8 or
> u16 integer.
Applied this one, thanks Liping.
I just sent a couple of a patch to fix element comments with bitmaps,
this is also implicitly fixing the leak that you aimed to fix with 2/2.
prev parent reply other threads:[~2017-03-13 12:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-05 16:02 [PATCH nf 1/2] netfilter: nft_set_bitmap: fetch the element key based on the set->klen Liping Zhang
2017-03-05 16:02 ` [PATCH nf 2/2] netfilter: nft_set_bitmap: fix memory leak Liping Zhang
2017-03-06 12:01 ` [PATCH nf 1/2] netfilter: nft_set_bitmap: fetch the element key based on the set->klen Pablo Neira Ayuso
2017-03-06 14:27 ` Liping Zhang
2017-03-06 16:42 ` Pablo Neira Ayuso
2017-03-07 4:37 ` Liping Zhang
2017-03-13 12:29 ` 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=20170313122919.GA6165@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).