Re: [RFC v2 bpf-next 2/5] bpf: return EOPNOTSUPP when map lookup isn't supported
On Fri, Oct 05, 2018 at 09:16:04AM +0900, Prashant Bhole wrote: > > > On 10/5/2018 9:10 AM, Alexei Starovoitov wrote: > > On Tue, Oct 02, 2018 at 02:35:16PM +0900, Prashant Bhole wrote: > > > 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 > > > --- > > > kernel/bpf/arraymap.c | 2 +- > > > kernel/bpf/sockmap.c | 2 +- > > > kernel/bpf/stackmap.c | 2 +- > > > kernel/bpf/xskmap.c | 2 +- > > > 4 files changed, 4 insertions(+), 4 deletions(-) > > > > > > diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c > > > index dded84cbe814..24583da9ffd1 100644 > > > --- a/kernel/bpf/arraymap.c > > > +++ b/kernel/bpf/arraymap.c > > > @@ -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); > > > > last time we discussed that the verifier should make sure that > > lookup is not called from bpf program for these map types. > > I'd like to see test cases in test_verifier.c for these map types > > to make sure we don't introduce crashes. > > Hi Alexei, > Patch 05/05 adds such tests in test_verifier.c. Please review those changes. ahh. missed it. sorry about that. looking...
Re: [RFC v2 bpf-next 2/5] bpf: return EOPNOTSUPP when map lookup isn't supported
On Tue, Oct 02, 2018 at 02:35:16PM +0900, Prashant Bhole wrote: > 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 > --- > kernel/bpf/arraymap.c | 2 +- > kernel/bpf/sockmap.c | 2 +- > kernel/bpf/stackmap.c | 2 +- > kernel/bpf/xskmap.c | 2 +- > 4 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c > index dded84cbe814..24583da9ffd1 100644 > --- a/kernel/bpf/arraymap.c > +++ b/kernel/bpf/arraymap.c > @@ -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); last time we discussed that the verifier should make sure that lookup is not called from bpf program for these map types. I'd like to see test cases in test_verifier.c for these map types to make sure we don't introduce crashes.
Re: [RFC v2 bpf-next 2/5] bpf: return EOPNOTSUPP when map lookup isn't supported
On 10/5/2018 9:10 AM, Alexei Starovoitov wrote: On Tue, Oct 02, 2018 at 02:35:16PM +0900, Prashant Bhole wrote: 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 --- kernel/bpf/arraymap.c | 2 +- kernel/bpf/sockmap.c | 2 +- kernel/bpf/stackmap.c | 2 +- kernel/bpf/xskmap.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index dded84cbe814..24583da9ffd1 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -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); last time we discussed that the verifier should make sure that lookup is not called from bpf program for these map types. I'd like to see test cases in test_verifier.c for these map types to make sure we don't introduce crashes. Hi Alexei, Patch 05/05 adds such tests in test_verifier.c. Please review those changes. Thank you. -Prashant
[RFC v2 bpf-next 2/5] bpf: return EOPNOTSUPP when map lookup isn't supported
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 --- kernel/bpf/arraymap.c | 2 +- kernel/bpf/sockmap.c | 2 +- kernel/bpf/stackmap.c | 2 +- kernel/bpf/xskmap.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index dded84cbe814..24583da9ffd1 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -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 */ diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index d37a1a0a6e1e..5d0677d808ae 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -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, diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 8061a439ef18..b2ade10f7ec3 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -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 */ diff --git a/kernel/bpf/xskmap.c b/kernel/bpf/xskmap.c index 9f8463afda9c..ef0b7b6ef8a5 100644 --- a/kernel/bpf/xskmap.c +++ b/kernel/bpf/xskmap.c @@ -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, -- 2.17.1