Skip to contentSkip to conversation

netfilter: nf_queue: fix NF_STOLEN skb leak redux

PATCH In review Florian Westphal 3 participants 4 messages Aug 11, 2011 – Aug 12, 2011

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_queue: fix NF_STOLEN skb leak redux

A userspace listener may send (bogus) NF_STOLEN verdict, which causes skb leak.

This problem was previously fixed via 64507fdbc29c3a622180378210ecea8659b14e40 (netfilter:
nf_queue: fix NF_STOLEN skb leak) but this had to be reverted because NF_STOLEN can also be returned by a netfilter hook when iterating the rules in nf_reinject.

This is complementary to commit fad54440438a7c231a6ae347738423cbabc936d9 (netfilter: avoid double free in nf_reinject).

Cc Julian Anastasov <[email protected]>
Cc Eric Dumazet <[email protected]>

---
One alternative would be to change ip(6)queue and nfqueue to fail with -EINVAL if userspace gives NF_STOLEN verdict. Thoughts?

net/netfilter/nf_queue.c +4 -0
index 5b466cd..dd2d014 100644
@@ -267,6 +267,10 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	const struct nf_afinfo *afinfo;
 	int err;
 
+	/* NF_STOLEN from userspace makes no sense, we must free packet */
+	if (WARN_ONCE(verdict == NF_STOLEN, "bogus verdict NF_STOLEN\n"))
+		verdict = NF_DROP;
+
 	rcu_read_lock();
 
 	nf_queue_entry_release_refs(entry);
Signature · 1 line
1.7.3.4
#1 lore raw

Hello,

Quoted 25 lines · Florian Westphal

A userspace listener may send (bogus) NF_STOLEN verdict, which causes skb leak.

This problem was previously fixed via 64507fdbc29c3a622180378210ecea8659b14e40 (netfilter:
nf_queue: fix NF_STOLEN skb leak) but this had to be reverted because NF_STOLEN can also be returned by a netfilter hook when iterating the rules in nf_reinject.

This is complementary to commit fad54440438a7c231a6ae347738423cbabc936d9 (netfilter: avoid double free in nf_reinject).

Cc Julian Anastasov <[email protected]>
Cc Eric Dumazet <[email protected]>

---
One alternative would be to change ip(6)queue and nfqueue to fail with -EINVAL if userspace gives NF_STOLEN verdict. Thoughts?

net/netfilter/nf_queue.c +0 -0
index 5b466cd..dd2d014 100644

net/netfilter/nf_queue.c void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) · line 273

Quoted 7 lines
net/netfilter/nf_queue.c +4 -0
@@ -267,6 +267,10 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	const struct nf_afinfo *afinfo;
 	int err;
 
+	/* NF_STOLEN from userspace makes no sense, we must free packet */
+	if (WARN_ONCE(verdict == NF_STOLEN, "bogus verdict NF_STOLEN\n"))
+		verdict = NF_DROP;
+

Good catch, thanks! Can you add some prefix to this
message such as KERN_WARNING "nf_queue: " ?

net/netfilter/nf_queue.c void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) · line 276

Quoted 3 lines
net/netfilter/nf_queue.c +0 -0
 	rcu_read_lock();
 
 	nf_queue_entry_release_refs(entry);

Regards

--
Julian Anastasov <[email protected]>

#2 lore raw
In reply to Florian Westphal

2011/8/11 Florian Westphal <[email protected]>:

Quoted 12 lines

A userspace listener may send (bogus) NF_STOLEN verdict, which causes skb leak.

This problem was previously fixed via 64507fdbc29c3a622180378210ecea8659b14e40 (netfilter:
nf_queue: fix NF_STOLEN skb leak) but this had to be reverted because NF_STOLEN can also be returned by a netfilter hook when iterating the rules in nf_reinject.

This is complementary to commit fad54440438a7c231a6ae347738423cbabc936d9 (netfilter: avoid double free in nf_reinject).

Quoted 7 lines
Cc Julian Anastasov <[email protected]>
Cc Eric Dumazet <[email protected]>

---
 One alternative would be to change ip(6)queue and nfqueue to fail with -EINVAL if userspace gives NF_STOLEN verdict. Thoughts?

Since userspace is not supposed to pass NF_STOLEN, this would be the correct fix.

Just a hint, no guarantees attached. ;)

Best Regards,
Michał Mirosław
--
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
#3 lore raw
Quoted 21 lines · Micha? Miros?aw

2011/8/11 Florian Westphal <[email protected]>:

Quoted 12 lines

A userspace listener may send (bogus) NF_STOLEN verdict, which causes skb leak.

This problem was previously fixed via 64507fdbc29c3a622180378210ecea8659b14e40 (netfilter:
nf_queue: fix NF_STOLEN skb leak) but this had to be reverted because NF_STOLEN can also be returned by a netfilter hook when iterating the rules in nf_reinject.

This is complementary to commit fad54440438a7c231a6ae347738423cbabc936d9 (netfilter: avoid double free in nf_reinject).

Quoted 7 lines
Cc Julian Anastasov <[email protected]>
Cc Eric Dumazet <[email protected]>

---
 One alternative would be to change ip(6)queue and nfqueue to fail with -EINVAL if userspace gives NF_STOLEN verdict. Thoughts?

Quoted 4 lines

Since userspace is not supposed to pass NF_STOLEN, this would be the correct fix.

Just a hint, no guarantees attached. ;)

Agreed, it makes more sense to reject it.

I'll wait for a few hours before submitting a patch.
--
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