net: filter: fix possible memory leak in __sk_prepare_filter()
authorLeon Yu <chianglungyu@gmail.com>
Sun, 1 Jun 2014 05:37:25 +0000 (05:37 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 3 Jun 2014 00:49:45 +0000 (17:49 -0700)
__sk_prepare_filter() was reworked in commit bd4cf0ed3 (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: bd4cf0ed331a ("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>
net/core/filter.c

index 9d79ca0a6e8e93e1bfc6d92c8a154a96ae0681c6..4aec7b93f1a9cd2f7695d2056acff0e9dec6f80a 100644 (file)
@@ -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.