On 12/09/2023 11:51, Zachary Leaf wrote:
[...]
+static int check_attr(int cmd, void *vattr) +{
- switch (cmd) {
- case BPF_MAP_CREATE:
return CHECK_ATTR(BPF_MAP_CREATE);
- case BPF_MAP_LOOKUP_ELEM:
return CHECK_ATTR(BPF_MAP_LOOKUP_ELEM);
- case BPF_MAP_GET_NEXT_KEY:
return CHECK_ATTR(BPF_MAP_GET_NEXT_KEY);
- case BPF_MAP_FREEZE:
return CHECK_ATTR(BPF_MAP_FREEZE);
- case BPF_PROG_LOAD:
return CHECK_ATTR(BPF_PROG_LOAD);
- case BPF_OBJ_PIN:
return CHECK_ATTR(BPF_OBJ);
- case BPF_OBJ_GET:
return CHECK_ATTR(BPF_OBJ);
- case BPF_PROG_ATTACH:
return CHECK_ATTR(BPF_PROG_ATTACH);
- case BPF_PROG_DETACH:
return CHECK_ATTR(BPF_PROG_DETACH);
- case BPF_PROG_QUERY:
return CHECK_ATTR(BPF_PROG_QUERY);
- case BPF_PROG_TEST_RUN:
return CHECK_ATTR(BPF_PROG_TEST_RUN);
- case BPF_PROG_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_MAP_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_BTF_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_PROG_GET_FD_BY_ID:
return CHECK_ATTR(BPF_PROG_GET_FD_BY_ID);
- case BPF_MAP_GET_FD_BY_ID:
return CHECK_ATTR(BPF_MAP_GET_FD_BY_ID);
- case BPF_OBJ_GET_INFO_BY_FD:
return CHECK_ATTR(BPF_OBJ_GET_INFO_BY_FD);
- case BPF_RAW_TRACEPOINT_OPEN:
return CHECK_ATTR(BPF_RAW_TRACEPOINT_OPEN);
- case BPF_BTF_LOAD:
return CHECK_ATTR(BPF_BTF_LOAD);
- case BPF_BTF_GET_FD_BY_ID:
return CHECK_ATTR(BPF_BTF_GET_FD_BY_ID);
- case BPF_TASK_FD_QUERY:
return CHECK_ATTR(BPF_TASK_FD_QUERY);
- case BPF_MAP_LOOKUP_AND_DELETE_ELEM:
return CHECK_ATTR(BPF_MAP_LOOKUP_AND_DELETE_ELEM);
- case BPF_LINK_CREATE:
return CHECK_ATTR(BPF_LINK_CREATE);
- case BPF_LINK_UPDATE:
return CHECK_ATTR(BPF_LINK_UPDATE);
- case BPF_LINK_GET_FD_BY_ID:
return CHECK_ATTR(BPF_LINK_GET_FD_BY_ID);
- case BPF_LINK_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_ENABLE_STATS:
return CHECK_ATTR(BPF_ENABLE_STATS);
- case BPF_ITER_CREATE:
return CHECK_ATTR(BPF_ITER_CREATE);
- case BPF_LINK_DETACH:
return CHECK_ATTR(BPF_LINK_DETACH);
- case BPF_PROG_BIND_MAP:
return CHECK_ATTR(BPF_PROG_BIND_MAP);
- default:
return 0;
- }
Nit: no empty line between curly brackets.
Kevin
+}
static void convert_compat_bpf_attr(union bpf_attr *dest, const union compat_bpf_attr *cattr, int cmd) { @@ -5691,6 +5684,10 @@ static int copy_bpf_attr_from_user(union bpf_attr *attr, int cmd, if (copy_from_bpfptr(select_attr, uattr, *size) != 0) return -EFAULT;
- err = check_attr(cmd, select_attr);
- if (err)
return -EINVAL;
- if (in_compat64_syscall()) convert_compat_bpf_attr(attr, &cattr, cmd);