diff options
author | Stanislav Fomichev <sdf@google.com> | 2021-01-12 19:28:29 +0300 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2021-01-12 23:05:07 +0300 |
commit | 4be34f3d0731b38a1b24566b37fbb39500aaf3a2 (patch) | |
tree | 56edf55becb44f23194f3f528a3ba1d7ebc2c359 | |
parent | 2f94ac19184665263b7a285ae88abe19dedf9c1b (diff) | |
download | linux-4be34f3d0731b38a1b24566b37fbb39500aaf3a2.tar.xz |
bpf: Don't leak memory in bpf getsockopt when optlen == 0
optlen == 0 indicates that the kernel should ignore BPF buffer
and use the original one from the user. We, however, forget
to free the temporary buffer that we've allocated for BPF.
Fixes: d8fe449a9c51 ("bpf: Don't return EINVAL from {get,set}sockopt when optlen > PAGE_SIZE")
Reported-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20210112162829.775079-1-sdf@google.com
-rw-r--r-- | kernel/bpf/cgroup.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 6ec088a96302..96555a8a2c54 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1391,12 +1391,13 @@ int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level, if (ctx.optlen != 0) { *optlen = ctx.optlen; *kernel_optval = ctx.optval; + /* export and don't free sockopt buf */ + return 0; } } out: - if (ret) - sockopt_free_buf(&ctx); + sockopt_free_buf(&ctx); return ret; } |