[PATCH] Fix handling of verdicts after NF_QUEUE

Subsystems: netfilter, networking [general], the rest

STALE3229d

4 messages, 2 authors, 2017-12-12 · open the first message on its own page

[PATCH] Fix handling of verdicts after NF_QUEUE

From: Debabrata Banerjee <hidden>
Date: 2017-12-11 23:30:24

A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
and a potential kernel panic via double free of skb's

This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
use switch() to handle verdict cases from nf_hook_slow()"). However that
commit cannot be cleanly cherry-picked to v4.9

Signed-off-by: Debabrata Banerjee <redacted>

---

This fix is only needed for v4.9 stable since v4.10+ does not have the
issue
---
 net/netfilter/core.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 004af030ef1a..d869ea50623e 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -364,6 +364,11 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
 		ret = nf_queue(skb, state, &entry, verdict);
 		if (ret == 1 && entry)
 			goto next_hook;
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
 	}
 	return ret;
 }
-- 
2.15.1

Re: [PATCH] Fix handling of verdicts after NF_QUEUE

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: 2017-12-12 00:23:23

Hi,

Thanks for catching up this, see below.

On Mon, Dec 11, 2017 at 06:30:24PM -0500, Debabrata Banerjee wrote:
quoted hunk
A verdict of NF_STOLEN after NF_QUEUE will cause an incorrect return value
and a potential kernel panic via double free of skb's

This was broken by commit 7034b566a4e7 ("netfilter: fix nf_queue handling")
and subsequently fixed in v4.10 by commit c63cbc460419 ("netfilter:
use switch() to handle verdict cases from nf_hook_slow()"). However that
commit cannot be cleanly cherry-picked to v4.9

Signed-off-by: Debabrata Banerjee <redacted>

---

This fix is only needed for v4.9 stable since v4.10+ does not have the
issue
---
 net/netfilter/core.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 004af030ef1a..d869ea50623e 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -364,6 +364,11 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
 		ret = nf_queue(skb, state, &entry, verdict);
 		if (ret == 1 && entry)
 			goto next_hook;
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
Another possibility (more simple?) would be this:

int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
{
        struct nf_hook_entry *entry;
        unsigned int verdict;
-       int ret = 0;
+       int ret;

        entry = rcu_dereference(state->hook_entries);
next_hook:
+       ret = 0;

Basically, make sure ret is set to zero when jumping to the next_hook
label.

Thanks!

RE: [PATCH] Fix handling of verdicts after NF_QUEUE

From: Banerjee, Debabrata <hidden>
Date: 2017-12-12 00:36:43

From: Pablo Neira Ayuso [mailto:pablo@netfilter.org]
On Mon, Dec 11, 2017 at 06:30:24PM -0500, Debabrata Banerjee wrote:
quoted
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
Another possibility (more simple?) would be this:

int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state) {
        struct nf_hook_entry *entry;
        unsigned int verdict;
-       int ret = 0;
+       int ret;

        entry = rcu_dereference(state->hook_entries);
next_hook:
+       ret = 0;

Basically, make sure ret is set to zero when jumping to the next_hook label.
Many ways to fix it, but I thought including the comment was appropriate.
Happy to change it if we want simpler instead.

-Deb

Re: [PATCH] Fix handling of verdicts after NF_QUEUE

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: 2017-12-12 22:42:29

On Tue, Dec 12, 2017 at 12:36:35AM +0000, Banerjee, Debabrata wrote:
quoted
From: Pablo Neira Ayuso [mailto:pablo@netfilter.org]
On Mon, Dec 11, 2017 at 06:30:24PM -0500, Debabrata Banerjee wrote:
quoted
+	} else {
+		/* Implicit handling for NF_STOLEN, as well as any other
+		 * non conventional verdicts.
+		 */
+		ret = 0;
Another possibility (more simple?) would be this:

int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state) {
        struct nf_hook_entry *entry;
        unsigned int verdict;
-       int ret = 0;
+       int ret;

        entry = rcu_dereference(state->hook_entries);
next_hook:
+       ret = 0;

Basically, make sure ret is set to zero when jumping to the next_hook label.
Many ways to fix it, but I thought including the comment was appropriate.
Happy to change it if we want simpler instead.
OK, let's take this one.

Please, send a patch in git-format-patch, that we can pass to -stable.

Cc netfilter-devel@vger.kernel.org and stable@vger.kernel.org should
be fine, you can also include gregkh@linuxfoundation.org since he
maintains 4.9-stable.

I'll ack this by when you send it.

Thanks!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help