mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 01:10:04 +00:00
netfilter: nf_queue: fix possible use-after-free
commitc387307024
upstream. Eric Dumazet says: The sock_hold() side seems suspect, because there is no guarantee that sk_refcnt is not already 0. On failure, we cannot queue the packet and need to indicate an error. The packet will be dropped by the caller. v2: split skb prefetch hunk into separate change Fixes:271b72c7fa
("udp: RCU handling for Unicast packets.") Reported-by: Eric Dumazet <eric.dumazet@gmail.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
e208bedb74
commit
ef97921ccd
3 changed files with 20 additions and 6 deletions
|
@ -32,7 +32,7 @@ void nf_register_queue_handler(struct net *net, const struct nf_queue_handler *q
|
||||||
void nf_unregister_queue_handler(struct net *net);
|
void nf_unregister_queue_handler(struct net *net);
|
||||||
void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
|
void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
|
||||||
|
|
||||||
void nf_queue_entry_get_refs(struct nf_queue_entry *entry);
|
bool nf_queue_entry_get_refs(struct nf_queue_entry *entry);
|
||||||
void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
|
void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
|
||||||
|
|
||||||
static inline void init_hashrandom(u32 *jhash_initval)
|
static inline void init_hashrandom(u32 *jhash_initval)
|
||||||
|
|
|
@ -80,10 +80,13 @@ void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
|
||||||
EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs);
|
EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs);
|
||||||
|
|
||||||
/* Bump dev refs so they don't vanish while packet is out */
|
/* Bump dev refs so they don't vanish while packet is out */
|
||||||
void nf_queue_entry_get_refs(struct nf_queue_entry *entry)
|
bool nf_queue_entry_get_refs(struct nf_queue_entry *entry)
|
||||||
{
|
{
|
||||||
struct nf_hook_state *state = &entry->state;
|
struct nf_hook_state *state = &entry->state;
|
||||||
|
|
||||||
|
if (state->sk && !refcount_inc_not_zero(&state->sk->sk_refcnt))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (state->in)
|
if (state->in)
|
||||||
dev_hold(state->in);
|
dev_hold(state->in);
|
||||||
if (state->out)
|
if (state->out)
|
||||||
|
@ -102,6 +105,7 @@ void nf_queue_entry_get_refs(struct nf_queue_entry *entry)
|
||||||
dev_hold(physdev);
|
dev_hold(physdev);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nf_queue_entry_get_refs);
|
EXPORT_SYMBOL_GPL(nf_queue_entry_get_refs);
|
||||||
|
|
||||||
|
@ -159,7 +163,11 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
|
||||||
.size = sizeof(*entry) + afinfo->route_key_size,
|
.size = sizeof(*entry) + afinfo->route_key_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
nf_queue_entry_get_refs(entry);
|
if (!nf_queue_entry_get_refs(entry)) {
|
||||||
|
kfree(entry);
|
||||||
|
return -ENOTCONN;
|
||||||
|
}
|
||||||
|
|
||||||
afinfo->saveroute(skb, entry);
|
afinfo->saveroute(skb, entry);
|
||||||
status = qh->outfn(entry, queuenum);
|
status = qh->outfn(entry, queuenum);
|
||||||
|
|
||||||
|
|
|
@ -693,9 +693,15 @@ static struct nf_queue_entry *
|
||||||
nf_queue_entry_dup(struct nf_queue_entry *e)
|
nf_queue_entry_dup(struct nf_queue_entry *e)
|
||||||
{
|
{
|
||||||
struct nf_queue_entry *entry = kmemdup(e, e->size, GFP_ATOMIC);
|
struct nf_queue_entry *entry = kmemdup(e, e->size, GFP_ATOMIC);
|
||||||
if (entry)
|
|
||||||
nf_queue_entry_get_refs(entry);
|
if (!entry)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (nf_queue_entry_get_refs(entry))
|
||||||
return entry;
|
return entry;
|
||||||
|
|
||||||
|
kfree(entry);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
||||||
|
|
Loading…
Reference in a new issue