]> Git Repo - linux.git/commitdiff
bpf, cgroup: Fix optlen WARN_ON_ONCE toctou
authorLoris Reiff <[email protected]>
Fri, 22 Jan 2021 16:42:31 +0000 (17:42 +0100)
committerDaniel Borkmann <[email protected]>
Fri, 22 Jan 2021 22:11:34 +0000 (23:11 +0100)
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 <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Reviewed-by: Stanislav Fomichev <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
kernel/bpf/cgroup.c

index 96555a8a2c545435aee44fd2fe4bbc37532357c5..6ec8f02f463b645fc333fd2d118f0123ded861c9 100644 (file)
@@ -1442,6 +1442,11 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
                        goto out;
                }
 
+               if (ctx.optlen < 0) {
+                       ret = -EFAULT;
+                       goto out;
+               }
+
                if (copy_from_user(ctx.optval, optval,
                                   min(ctx.optlen, max_optlen)) != 0) {
                        ret = -EFAULT;
This page took 0.061252 seconds and 4 git commands to generate.