Commit 06cdb634 authored by Florian Westphal's avatar Florian Westphal Committed by Patrick McHardy

netfilter: nfnetlink_queue: do not free skb on error

Move free responsibility from nf_queue to caller.
This enables more flexible error handling; we can now accept the skb
instead of freeing it.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
parent f1585086
...@@ -181,8 +181,11 @@ int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb, ...@@ -181,8 +181,11 @@ int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
} else if ((verdict & NF_VERDICT_MASK) == NF_QUEUE) { } else if ((verdict & NF_VERDICT_MASK) == NF_QUEUE) {
ret = nf_queue(skb, elem, pf, hook, indev, outdev, okfn, ret = nf_queue(skb, elem, pf, hook, indev, outdev, okfn,
verdict >> NF_VERDICT_BITS); verdict >> NF_VERDICT_BITS);
if (ret == -ECANCELED) if (ret < 0) {
goto next_hook; if (ret == -ECANCELED)
goto next_hook;
kfree_skb(skb);
}
ret = 0; ret = 0;
} }
rcu_read_unlock(); rcu_read_unlock();
......
...@@ -163,9 +163,8 @@ static int __nf_queue(struct sk_buff *skb, ...@@ -163,9 +163,8 @@ static int __nf_queue(struct sk_buff *skb,
/* If it's going away, ignore hook. */ /* If it's going away, ignore hook. */
if (!try_module_get(entry->elem->owner)) { if (!try_module_get(entry->elem->owner)) {
rcu_read_unlock(); status = -ECANCELED;
kfree(entry); goto err_unlock;
return -ECANCELED;
} }
/* Bump dev refs so they don't vanish while packet is out */ /* Bump dev refs so they don't vanish while packet is out */
if (indev) if (indev)
...@@ -198,7 +197,6 @@ static int __nf_queue(struct sk_buff *skb, ...@@ -198,7 +197,6 @@ static int __nf_queue(struct sk_buff *skb,
err_unlock: err_unlock:
rcu_read_unlock(); rcu_read_unlock();
err: err:
kfree_skb(skb);
kfree(entry); kfree(entry);
return status; return status;
} }
...@@ -229,7 +227,6 @@ int nf_queue(struct sk_buff *skb, ...@@ -229,7 +227,6 @@ int nf_queue(struct sk_buff *skb,
} }
segs = skb_gso_segment(skb, 0); segs = skb_gso_segment(skb, 0);
kfree_skb(skb);
/* Does not use PTR_ERR to limit the number of error codes that can be /* Does not use PTR_ERR to limit the number of error codes that can be
* returned by nf_queue. For instance, callers rely on -ECANCELED to mean * returned by nf_queue. For instance, callers rely on -ECANCELED to mean
* 'ignore this hook'. * 'ignore this hook'.
...@@ -253,8 +250,11 @@ int nf_queue(struct sk_buff *skb, ...@@ -253,8 +250,11 @@ int nf_queue(struct sk_buff *skb,
segs = nskb; segs = nskb;
} while (segs); } while (segs);
/* also free orig skb if only some segments were queued */
if (unlikely(err && queued)) if (unlikely(err && queued))
err = 0; err = 0;
if (err == 0)
kfree_skb(skb);
return err; return err;
} }
...@@ -300,8 +300,11 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) ...@@ -300,8 +300,11 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
err = __nf_queue(skb, elem, entry->pf, entry->hook, err = __nf_queue(skb, elem, entry->pf, entry->hook,
entry->indev, entry->outdev, entry->okfn, entry->indev, entry->outdev, entry->okfn,
verdict >> NF_VERDICT_BITS); verdict >> NF_VERDICT_BITS);
if (err == -ECANCELED) if (err < 0) {
goto next_hook; if (err == -ECANCELED)
goto next_hook;
kfree_skb(skb);
}
break; break;
case NF_STOLEN: case NF_STOLEN:
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment