netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH -next] netfilter: nfnetlink: work around wrong endianess with old nft userspace
Date: Fri, 28 Aug 2015 00:17:43 +0200	[thread overview]
Message-ID: <1440713863-18469-1-git-send-email-fw@strlen.de> (raw)

The nfgenmsg res_id is __be16.  Unfortunately nftables batch support uses
host byte order.

This adds a compat workaround for old nft userspace.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/nfnetlink.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 0c0e8ec..2e255ad 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -276,18 +276,24 @@ enum {
 };
 
 static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
-				u_int16_t subsys_id)
+				__be16 __subsys_id)
 {
 	struct sk_buff *oskb = skb;
 	struct net *net = sock_net(skb->sk);
 	const struct nfnetlink_subsystem *ss;
 	const struct nfnl_callback *nc;
 	static LIST_HEAD(err_list);
+	u16 subsys_id = ntohs(__subsys_id);
 	u32 status;
 	int err;
 
-	if (subsys_id >= NFNL_SUBSYS_COUNT)
-		return netlink_ack(skb, nlh, -EINVAL);
+	if (subsys_id >= NFNL_SUBSYS_COUNT) {
+		/* Work around old nft using host byte order */
+		if (NFNL_SUBSYS_NFTABLES != (__force __u16) __subsys_id)
+			return netlink_ack(skb, nlh, -EINVAL);
+
+		subsys_id = (__force __u16) __subsys_id;
+	}
 replay:
 	status = 0;
 
-- 
2.0.5


             reply	other threads:[~2015-08-27 23:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27 22:17 Florian Westphal [this message]
2015-08-28 19:01 ` [PATCH -next] netfilter: nfnetlink: work around wrong endianess with old nft userspace Pablo Neira Ayuso
2015-08-28 19:24   ` Florian Westphal

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=1440713863-18469-1-git-send-email-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.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).