Skip to contentSkip to conversation

netfilter: ctnetlink: don't permit ct creation with random tuple

PATCH Applied Florian Westphal 2 participants 5 messages Feb 12, 2013

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: ctnetlink: don't permit ct creation with random tuple

Userspace can cause kernel panic by not specifying orig/reply
tuple: kernel will create a tuple with random stack values.

Problem is that tuple.dst.dir will be random, too, which causes nf_ct_tuplehash_to_ctrack() to return garbage.

---
 net/netfilter/nf_conntrack_netlink.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -0
index 7bbfb3d..e592281 100644
@@ -1596,6 +1596,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 		if (nlh->nlmsg_flags & NLM_F_CREATE) {
 			enum ip_conntrack_events events;
 
+			if (!cda[CTA_TUPLE_ORIG] ||
+			    !cda[CTA_TUPLE_REPLY])
+				return -EINVAL;
 			ct = ctnetlink_create_conntrack(net, zone, cda, &otuple,
 							&rtuple, u3);
 			if (IS_ERR(ct))
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 5 lines · Florian Westphal

Userspace can cause kernel panic by not specifying orig/reply
tuple: kernel will create a tuple with random stack values.

Problem is that tuple.dst.dir will be random, too, which causes nf_ct_tuplehash_to_ctrack() to return garbage.

good catch.

Quoted 10 lines
---
 net/netfilter/nf_conntrack_netlink.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
net/netfilter/nf_conntrack_netlink.c +0 -0
index 7bbfb3d..e592281 100644

net/netfilter/nf_conntrack_netlink.c ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, · line 1601

Quoted 6 lines
net/netfilter/nf_conntrack_netlink.c +3 -0
@@ -1596,6 +1596,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 		if (nlh->nlmsg_flags & NLM_F_CREATE) {
 			enum ip_conntrack_events events;
 
+			if (!cda[CTA_TUPLE_ORIG] ||
+			    !cda[CTA_TUPLE_REPLY])
+				return -EINVAL;

I think that needs to be && instead of ||.

No need to resend the patch, I'll fix it and apply.

Thanks Florian.

Quoted 10 lines
net/netfilter/nf_conntrack_netlink.c +0 -0
 			ct = ctnetlink_create_conntrack(net, zone, cda, &otuple,
 							&rtuple, u3);
 			if (IS_ERR(ct))
Signature · 6 lines
1.7.8.6

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#2 lore raw
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal

Userspace can cause kernel panic by not specifying orig/reply
tuple: kernel will create a tuple with random stack values.

Problem is that tuple.dst.dir will be random, too, which causes nf_ct_tuplehash_to_ctrack() to return garbage.

[..]

Quoted 8 lines
Quoted 8 lines
net/netfilter/nf_conntrack_netlink.c +0 -0
index 7bbfb3d..e592281 100644
@@ -1596,6 +1596,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 		if (nlh->nlmsg_flags & NLM_F_CREATE) {
 			enum ip_conntrack_events events;
 
Quoted 5 lines

net/netfilter/nf_conntrack_netlink.c ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, · line 1601

Quoted 3 lines
net/netfilter/nf_conntrack_netlink.c +3 -0
+			if (!cda[CTA_TUPLE_ORIG] ||
+			    !cda[CTA_TUPLE_REPLY])
+				return -EINVAL;

I think that needs to be && instead of ||.

Uh, maybe I'm too low on caffeine, but when a new conntrack is to be created, shouldn't userspace have to specify _both_ ORIG and REPLY?

#3 lore raw
Quoted 24 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal

Userspace can cause kernel panic by not specifying orig/reply
tuple: kernel will create a tuple with random stack values.

Problem is that tuple.dst.dir will be random, too, which causes nf_ct_tuplehash_to_ctrack() to return garbage.

[..]

Quoted 8 lines
Quoted 8 lines
net/netfilter/nf_conntrack_netlink.c +0 -0
index 7bbfb3d..e592281 100644
@@ -1596,6 +1596,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 		if (nlh->nlmsg_flags & NLM_F_CREATE) {
 			enum ip_conntrack_events events;
 
Quoted 5 lines

net/netfilter/nf_conntrack_netlink.c ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, · line 1601

Quoted 3 lines
net/netfilter/nf_conntrack_netlink.c +3 -0
+			if (!cda[CTA_TUPLE_ORIG] ||
+			    !cda[CTA_TUPLE_REPLY])
+				return -EINVAL;

I think that needs to be && instead of ||.

Quoted 3 lines

Uh, maybe I'm too low on caffeine, but when a new conntrack is to be created, shouldn't userspace have to specify _both_ ORIG and REPLY?

You're right, it's me who is low on caffeine. Sorry.

maintainer Applied
#4 lore raw
In reply to Florian Westphal
Quoted 5 lines · Florian Westphal

Userspace can cause kernel panic by not specifying orig/reply
tuple: kernel will create a tuple with random stack values.

Problem is that tuple.dst.dir will be random, too, which causes nf_ct_tuplehash_to_ctrack() to return garbage.

Applied, thanks Florian.