[PATCH 3.16 22/55] net: filter: fix possible use after free

From: Greg Kroah-Hartman
Date: Sun Oct 12 2014 - 22:47:01 EST


3.16-stable review patch. If anyone has any objections, please let me know.

------------------

From: Eric Dumazet <edumazet@xxxxxxxxxx>

[ No appicable upstream commit, this bug has been subsequently been
fixed as a side effect of other changes. ]

If kmemdup() fails, we free fp->orig_prog and return -ENOMEM

sk_attach_filter()
-> sk_filter_uncharge(sk, fp)
-> sk_filter_release(fp)
-> call_rcu(&fp->rcu, sk_filter_release_rcu)
-> sk_filter_release_rcu()
-> sk_release_orig_filter()
fprog = fp->orig_prog; // not NULL, but points to freed memory
kfree(fprog->filter); // use after free, potential corruption
kfree(fprog); // double free or corruption

Note: This was fixed in 3.17+ with commit 278571baca2a
("net: filter: simplify socket charging")

Found by AddressSanitizer

Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
Fixes: a3ea269b8bcdb ("net: filter: keep original BPF program around")
Acked-by: Alexei Starovoitov <ast@xxxxxxxxxxxx>
Acked-by: Daniel Borkmann <dborkman@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
net/core/filter.c | 1 +
1 file changed, 1 insertion(+)

--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1318,6 +1318,7 @@ static int sk_store_orig_filter(struct s
fkprog->filter = kmemdup(fp->insns, fsize, GFP_KERNEL);
if (!fkprog->filter) {
kfree(fp->orig_prog);
+ fp->orig_prog = NULL;
return -ENOMEM;
}



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/