Skip to content

Commit

Permalink
bpf: return EOPNOTSUPP when map lookup isn't supported
Browse files Browse the repository at this point in the history
Return ERR_PTR(-EOPNOTSUPP) from map_lookup_elem() methods of below
map types:
- BPF_MAP_TYPE_PROG_ARRAY
- BPF_MAP_TYPE_STACK_TRACE
- BPF_MAP_TYPE_XSKMAP
- BPF_MAP_TYPE_SOCKMAP/BPF_MAP_TYPE_SOCKHASH

Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Prashant Bhole authored and Alexei Starovoitov committed Oct 10, 2018
1 parent 509db28 commit 3b4a63f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kernel/bpf/arraymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ static void fd_array_map_free(struct bpf_map *map)

static void *fd_array_map_lookup_elem(struct bpf_map *map, void *key)
{
return NULL;
return ERR_PTR(-EOPNOTSUPP);
}

/* only called from syscall */
Expand Down
2 changes: 1 addition & 1 deletion kernel/bpf/sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ int sockmap_get_from_fd(const union bpf_attr *attr, int type,

static void *sock_map_lookup(struct bpf_map *map, void *key)
{
return NULL;
return ERR_PTR(-EOPNOTSUPP);
}

static int sock_map_update_elem(struct bpf_map *map,
Expand Down
2 changes: 1 addition & 1 deletion kernel/bpf/stackmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ const struct bpf_func_proto bpf_get_stack_proto = {
/* Called from eBPF program */
static void *stack_map_lookup_elem(struct bpf_map *map, void *key)
{
return NULL;
return ERR_PTR(-EOPNOTSUPP);
}

/* Called from syscall */
Expand Down
2 changes: 1 addition & 1 deletion kernel/bpf/xskmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void __xsk_map_flush(struct bpf_map *map)

static void *xsk_map_lookup_elem(struct bpf_map *map, void *key)
{
return NULL;
return ERR_PTR(-EOPNOTSUPP);
}

static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,
Expand Down

0 comments on commit 3b4a63f

Please sign in to comment.