ACK: [PATCH 1/2] bpf, cgroup: Fix optlen WARN_ON_ONCE toctou
Thadeu Lima de Souza Cascardo
cascardo at canonical.com
Thu Mar 4 11:01:27 UTC 2021
On Tue, Mar 02, 2021 at 11:32:07AM -0700, Tim Gardner wrote:
> From: Loris Reiff <loris.reiff at liblor.ch>
>
> CVE-2021-20194
>
> A toctou issue in `__cgroup_bpf_run_filter_getsockopt` can trigger a
> WARN_ON_ONCE in a check of `copy_from_user`.
>
> `*optlen` is checked to be non-negative in the individual getsockopt
> functions beforehand. Changing `*optlen` in a race to a negative value
> will result in a `copy_from_user(ctx.optval, optval, ctx.optlen)` with
> `ctx.optlen` being a negative integer.
>
> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
> Signed-off-by: Loris Reiff <loris.reiff at liblor.ch>
> Signed-off-by: Daniel Borkmann <daniel at iogearbox.net>
> Reviewed-by: Stanislav Fomichev <sdf at google.com>
> Link: https://lore.kernel.org/bpf/20210122164232.61770-1-loris.reiff@liblor.ch
> (backported from commit bb8b81e396f7afbe7c50d789e2107512274d2a35)
> Signed-off-by: Tim Gardner <tim.gardner at canonical.com>
Backport is fine, achieves the mitigation we want.
On the other hand, d8fe449a9c51a37d844ab607e14e2f5c657d3cf2 is the reason why
this was not a clean cherry-pick. It looks like this would fix a real bug, and
is applied to 5.4, which is what I mostly care about at this moment.
Acked-by: Thadeu Lima de Souza Cascardo <cascardo at canonical.com>
Cascardo.
> ---
> kernel/bpf/cgroup.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 4f1472409ef8..117a283d278e 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -1100,6 +1100,11 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
> goto out;
> }
>
> + if (ctx.optlen < 0) {
> + ret = -EFAULT;
> + goto out;
> + }
> +
> if (ctx.optlen > max_optlen)
> ctx.optlen = max_optlen;
>
> --
> 2.17.1
>
>
> --
> kernel-team mailing list
> kernel-team at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
More information about the kernel-team
mailing list