netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: leroy christophe <christophe.leroy@c-s.fr>
To: Pablo Neira Ayuso <pablo@netfilter.org>, arturo.borrero.glez@gmail.com
Cc: netfilter@vger.kernel.org, GUITTON Alex <alex.guitton@c-s.fr>,
	netfilter-devel@vger.kernel.org
Subject: bug : nft_redirect port byteorder issue
Date: Fri, 12 Dec 2014 11:16:29 +0100	[thread overview]
Message-ID: <548AC07D.6080703@c-s.fr> (raw)
In-Reply-To: <20141210182244.GA5622@salvia>

Hi,

table ip nat {
         chain prerouting {
                  type nat hook prerouting priority 0;
                  tcp dport 222 redirect :22
         }
         chain postrouting {
                  type nat hook postrouting priority 0;
         }
}

With the above rules, data[priv->sreg_proto_min].data[0] has value 
0x160000 instead of 0x16 on powerpc (Big Endian byte order)

Due to this, mr.range[0].min.all gets assigned value 0 instead of 22.

Below patch fixes it, but it is maybe not the proper way to fix it, so I 
let it up to you.

Christophe

diff --git a/net/ipv4/netfilter/nft_redir_ipv4.c 
b/net/ipv4/netfilter/nft_redir_ipv4.c
index 643c596..554bb32 100644
--- a/net/ipv4/netfilter/nft_redir_ipv4.c
+++ b/net/ipv4/netfilter/nft_redir_ipv4.c
@@ -28,9 +28,9 @@ static void nft_redir_ipv4_eval(const struct nft_expr 
*expr,
  	memset(&mr, 0, sizeof(mr));
  	if (priv->sreg_proto_min) {
  		mr.range[0].min.all = (__force __be16)
-					data[priv->sreg_proto_min].data[0];
+					*(__be16*)&data[priv->sreg_proto_min].data[0];
  		mr.range[0].max.all = (__force __be16)
-					data[priv->sreg_proto_max].data[0];
+					*(__be16*)&data[priv->sreg_proto_max].data[0];
  		mr.range[0].flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
  	}


       reply	other threads:[~2014-12-12 10:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <54885B08.1010700@c-s.fr>
     [not found] ` <20141210182244.GA5622@salvia>
2014-12-12 10:16   ` leroy christophe [this message]
2014-12-12 10:49     ` bug : nft_redirect port byteorder issue Arturo Borrero Gonzalez
2014-12-12 11:07       ` leroy christophe
2014-12-12 11:55         ` Arturo Borrero Gonzalez
2014-12-12 12:55           ` leroy christophe
2014-12-12 15:25             ` Patrick McHardy
2014-12-12 16:20               ` leroy christophe
2014-12-12 16:40                 ` Patrick McHardy
2014-12-22 11:54     ` Pablo Neira Ayuso
2014-12-22 12:44       ` Patrick McHardy
2014-12-22 13:00         ` Pablo Neira Ayuso

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=548AC07D.6080703@c-s.fr \
    --to=christophe.leroy@c-s.fr \
    --cc=alex.guitton@c-s.fr \
    --cc=arturo.borrero.glez@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=netfilter@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 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).