]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - kernel/bpf/cgroup.c
bpf/cgroup: fix a verification error for a CGROUP_DEVICE type prog
[mirror_ubuntu-bionic-kernel.git] / kernel / bpf / cgroup.c
index b789ab78d28f0d85d4d2338a49bc3c41f5eeae38..c1c0b60d3f2f2e0e5a695b578d8bd181163b96e8 100644 (file)
@@ -568,6 +568,8 @@ static bool cgroup_dev_is_valid_access(int off, int size,
                                       enum bpf_access_type type,
                                       struct bpf_insn_access_aux *info)
 {
+       const int size_default = sizeof(__u32);
+
        if (type == BPF_WRITE)
                return false;
 
@@ -576,8 +578,17 @@ static bool cgroup_dev_is_valid_access(int off, int size,
        /* The verifier guarantees that size > 0. */
        if (off % size != 0)
                return false;
-       if (size != sizeof(__u32))
-               return false;
+
+       switch (off) {
+       case bpf_ctx_range(struct bpf_cgroup_dev_ctx, access_type):
+               bpf_ctx_record_field_size(info, size_default);
+               if (!bpf_ctx_narrow_access_ok(off, size, size_default))
+                       return false;
+               break;
+       default:
+               if (size != size_default)
+                       return false;
+       }
 
        return true;
 }