diff mbox

[-next] netfilter: nfnetlink: work around wrong endianess with old nft userspace

Message ID 20150828190143.GA5575@salvia
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Pablo Neira Ayuso Aug. 28, 2015, 7:01 p.m. UTC
On Fri, Aug 28, 2015 at 12:17:43AM +0200, Florian Westphal wrote:
> The nfgenmsg res_id is __be16.  Unfortunately nftables batch support uses
> host byte order.
> 
> This adds a compat workaround for old nft userspace.

Would you be also OK with the attached patch? Thanks.

Comments

Florian Westphal Aug. 28, 2015, 7:24 p.m. UTC | #1
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Fri, Aug 28, 2015 at 12:17:43AM +0200, Florian Westphal wrote:
> > The nfgenmsg res_id is __be16.  Unfortunately nftables batch support uses
> > host byte order.
> > 
> > This adds a compat workaround for old nft userspace.
> 
> Would you be also OK with the attached patch? Thanks.

Sure.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

From 97901f6e597987be7c9d9b1f6875004b4713e924 Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Fri, 28 Aug 2015 19:17:46 +0200
Subject: [PATCH] netfilter: nfnetlink: work around wrong endianess in res_id
 field

The convention in nfnetlink is to use network byte order in every header field
as well as in the attribute payload. The initial version of the batching
infrastructure assumes that res_id comes in host byte order though.

The only client of the batching infrastructure is nf_tables, so let's add a
workaround to address this inconsistency. We currently have 11 nfnetlink
subsystems according to NFNL_SUBSYS_COUNT, so we can assume that the subsystem
2560, ie. htons(10), will not be allocated anytime soon, so it can be an alias
of nf_tables from the nfnetlink batching path when interpreting the res_id
field.

Based on original patch from Florian Westphal.

Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nfnetlink.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 0c0e8ec..70277b1 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -444,6 +444,7 @@  done:
 static void nfnetlink_rcv(struct sk_buff *skb)
 {
 	struct nlmsghdr *nlh = nlmsg_hdr(skb);
+	u_int16_t res_id;
 	int msglen;
 
 	if (nlh->nlmsg_len < NLMSG_HDRLEN ||
@@ -468,7 +469,12 @@  static void nfnetlink_rcv(struct sk_buff *skb)
 
 		nfgenmsg = nlmsg_data(nlh);
 		skb_pull(skb, msglen);
-		nfnetlink_rcv_batch(skb, nlh, nfgenmsg->res_id);
+		/* Work around old nft using host byte order */
+		if (nfgenmsg->res_id == NFNL_SUBSYS_NFTABLES)
+			res_id = NFNL_SUBSYS_NFTABLES;
+		else
+			res_id = ntohs(nfgenmsg->res_id);
+		nfnetlink_rcv_batch(skb, nlh, res_id);
 	} else {
 		netlink_rcv_skb(skb, &nfnetlink_rcv_msg);
 	}
-- 
1.7.10.4