media, bpf: Do not copy more entries than user space requested
authorSean Young <sean@mess.org>
Wed, 23 Jun 2021 21:37:54 +0000 (22:37 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 24 Jun 2021 13:16:40 +0000 (15:16 +0200)
The syscall bpf(BPF_PROG_QUERY, &attr) should use the prog_cnt field to
see how many entries user space provided and return ENOSPC if there are
more programs than that. Before this patch, this is not checked and
ENOSPC is never returned.

Note that one lirc device is limited to 64 bpf programs, and user space
I'm aware of -- ir-keytable -- always gives enough space for 64 entries
already. However, we should not copy program ids than are requested.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210623213754.632-1-sean@mess.org
drivers/media/rc/bpf-lirc.c

index 3fe3edd..afae0af 100644 (file)
@@ -326,7 +326,8 @@ int lirc_prog_query(const union bpf_attr *attr, union bpf_attr __user *uattr)
        }
 
        if (attr->query.prog_cnt != 0 && prog_ids && cnt)
-               ret = bpf_prog_array_copy_to_user(progs, prog_ids, cnt);
+               ret = bpf_prog_array_copy_to_user(progs, prog_ids,
+                                                 attr->query.prog_cnt);
 
 unlock:
        mutex_unlock(&ir_raw_handler_lock);