Skip to content

Commit

Permalink
net: filter: fix possible memory leak in __sk_prepare_filter()
Browse files Browse the repository at this point in the history
__sk_prepare_filter() was reworked in commit bd4cf0e (net: filter:
rework/optimize internal BPF interpreter's instruction set) so that it should
have uncharged memory once things went wrong. However that work isn't complete.
Error is handled only in __sk_migrate_filter() while memory can still leak in
the error path right after sk_chk_filter().

Fixes: bd4cf0e ("net: filter: rework/optimize internal BPF interpreter's instruction set")
Signed-off-by: Leon Yu <chianglungyu@gmail.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Tested-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Leon Yu authored and David S. Miller committed Jun 3, 2014
1 parent 3aab01d commit 418c96a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,8 +1559,13 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
fp->jited = 0;

err = sk_chk_filter(fp->insns, fp->len);
if (err)
if (err) {
if (sk != NULL)
sk_filter_uncharge(sk, fp);
else
kfree(fp);
return ERR_PTR(err);
}

/* Probe if we can JIT compile the filter and if so, do
* the compilation of the filter.
Expand Down

0 comments on commit 418c96a

Please sign in to comment.