Message ID | 20200925095630.49207-2-lmb@cloudflare.com |
---|---|
State | Superseded |
Headers | show |
Series | [bpf-next,1/4] bpf: sockmap: enable map_update_elem from bpf_iter | expand |
Hi Lorenz, I love your patch! Yet something to improve: [auto build test ERROR on bpf-next/master] url: https://github.com/0day-ci/linux/commits/Lorenz-Bauer/Sockmap-copying/20200925-175852 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: arm-randconfig-r023-20200925 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c32e69b2ce7abfb151a87ba363ac9e25abf7d417) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi # https://github.com/0day-ci/linux/commit/8021d25b95546c5e69261c6083c6eed8909caffd git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Lorenz-Bauer/Sockmap-copying/20200925-175852 git checkout 8021d25b95546c5e69261c6083c6eed8909caffd # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): >> kernel/bpf/verifier.c:3941:16: error: use of undeclared identifier 'ARG_PTR_TO_BTF_ID_SOCK_COMMON'; did you mean 'ARG_PTR_TO_SOCK_COMMON'? *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ARG_PTR_TO_SOCK_COMMON include/linux/bpf.h:286:2: note: 'ARG_PTR_TO_SOCK_COMMON' declared here ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */ ^ 1 error generated. vim +3941 kernel/bpf/verifier.c 3926 3927 static int resolve_map_arg_type(struct bpf_verifier_env *env, 3928 const struct bpf_call_arg_meta *meta, 3929 enum bpf_arg_type *arg_type) 3930 { 3931 if (!meta->map_ptr) { 3932 /* kernel subsystem misconfigured verifier */ 3933 verbose(env, "invalid map_ptr to access map->type\n"); 3934 return -EACCES; 3935 } 3936 3937 switch (meta->map_ptr->map_type) { 3938 case BPF_MAP_TYPE_SOCKMAP: 3939 case BPF_MAP_TYPE_SOCKHASH: 3940 if (*arg_type == ARG_PTR_TO_MAP_VALUE) { > 3941 *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON; 3942 } else { 3943 verbose(env, "invalid arg_type for sockmap/sockhash\n"); 3944 return -EINVAL; 3945 } 3946 break; 3947 3948 default: 3949 break; 3950 } 3951 return 0; 3952 } 3953 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
On Fri, Sep 25, 2020 at 10:56:27AM +0100, Lorenz Bauer wrote: [ ... ] > diff --git a/net/core/sock_map.c b/net/core/sock_map.c > index e1f05e3fa1d0..497e7df466d4 100644 > --- a/net/core/sock_map.c > +++ b/net/core/sock_map.c > @@ -610,6 +610,9 @@ static int sock_map_update_elem(struct bpf_map *map, void *key, > struct sock *sk = (struct sock *)value; > int ret; > > + if (unlikely(!sk)) sk_fullsock(sk) test is also needed. > + return -EINVAL; > + > if (!sock_map_sk_is_suitable(sk)) sk->sk_type is used in sock_map_sk_is_suitable(). sk_type is not in sock_common.
On Fri, 25 Sep 2020 at 22:54, Martin KaFai Lau <kafai@fb.com> wrote: > > > + if (unlikely(!sk)) > sk_fullsock(sk) test is also needed. > > > + return -EINVAL; > > > + > > if (!sock_map_sk_is_suitable(sk)) > sk->sk_type is used in sock_map_sk_is_suitable(). > sk_type is not in sock_common. Oh my, thanks!
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d4ba29fb17a6..5bd0239da8b6 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3943,7 +3943,7 @@ static int resolve_map_arg_type(struct bpf_verifier_env *env, case BPF_MAP_TYPE_SOCKMAP: case BPF_MAP_TYPE_SOCKHASH: if (*arg_type == ARG_PTR_TO_MAP_VALUE) { - *arg_type = ARG_PTR_TO_SOCKET; + *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON; } else { verbose(env, "invalid arg_type for sockmap/sockhash\n"); return -EINVAL; diff --git a/net/core/sock_map.c b/net/core/sock_map.c index e1f05e3fa1d0..497e7df466d4 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -610,6 +610,9 @@ static int sock_map_update_elem(struct bpf_map *map, void *key, struct sock *sk = (struct sock *)value; int ret; + if (unlikely(!sk)) + return -EINVAL; + if (!sock_map_sk_is_suitable(sk)) return -EOPNOTSUPP;
Allow passing a pointer to a BTF struct sock_common* when updating a sockmap or sockhash. Since BTF pointers can fault and therefore be NULL at runtime we need to add an additional !sk check to sock_map_update_elem. Doing this allows calling map_update_elem on sockmap from bpf_iter context, which uses BTF pointers. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> --- kernel/bpf/verifier.c | 2 +- net/core/sock_map.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)