Message ID | 20230404045029.82870-5-alexei.starovoitov@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 91571a515d1bcdc280bb46423bb697ea7eb42ff3 |
Delegated to: | BPF |
Headers | show |
Series | bpf: Follow up to RCU enforcement in the verifier. | expand |
On Mon, Apr 03, 2023 at 09:50:25PM -0700, Alexei Starovoitov wrote: > From: Alexei Starovoitov <ast@kernel.org> > > bpf_[sk|inode|task|cgrp]_storage_[get|delete]() and bpf_get_socket_cookie() helpers > perform run-time check that sk|inode|task|cgrp pointer != NULL. > Teach verifier about this fact and allow bpf programs to pass > PTR_TO_BTF_ID | PTR_MAYBE_NULL into such helpers. > It will be used in the subsequent patch that will do > bpf_sk_storage_get(.., skb->sk, ...); > Even when 'skb' pointer is trusted the 'sk' pointer may be NULL. > > Signed-off-by: Alexei Starovoitov <ast@kernel.org> > --- > kernel/bpf/bpf_cgrp_storage.c | 4 ++-- > kernel/bpf/bpf_inode_storage.c | 4 ++-- > kernel/bpf/bpf_task_storage.c | 8 ++++---- > net/core/bpf_sk_storage.c | 4 ++-- > net/core/filter.c | 2 +- > 5 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/kernel/bpf/bpf_cgrp_storage.c b/kernel/bpf/bpf_cgrp_storage.c > index d17d5b694668..d44fe8dd9732 100644 > --- a/kernel/bpf/bpf_cgrp_storage.c > +++ b/kernel/bpf/bpf_cgrp_storage.c > @@ -224,7 +224,7 @@ const struct bpf_func_proto bpf_cgrp_storage_get_proto = { > .gpl_only = false, > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &bpf_cgroup_btf_id[0], > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > .arg4_type = ARG_ANYTHING, > @@ -235,6 +235,6 @@ const struct bpf_func_proto bpf_cgrp_storage_delete_proto = { > .gpl_only = false, > .ret_type = RET_INTEGER, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &bpf_cgroup_btf_id[0], > }; > diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c > index e17ad581b9be..a4d93df78c75 100644 > --- a/kernel/bpf/bpf_inode_storage.c > +++ b/kernel/bpf/bpf_inode_storage.c > @@ -229,7 +229,7 @@ const struct bpf_func_proto bpf_inode_storage_get_proto = { > .gpl_only = false, > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &bpf_inode_storage_btf_ids[0], > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > .arg4_type = ARG_ANYTHING, > @@ -240,6 +240,6 @@ const struct bpf_func_proto bpf_inode_storage_delete_proto = { > .gpl_only = false, > .ret_type = RET_INTEGER, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &bpf_inode_storage_btf_ids[0], > }; > diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c > index d1af0c8f9ce4..adf6dfe0ba68 100644 > --- a/kernel/bpf/bpf_task_storage.c > +++ b/kernel/bpf/bpf_task_storage.c > @@ -338,7 +338,7 @@ const struct bpf_func_proto bpf_task_storage_get_recur_proto = { > .gpl_only = false, > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > .arg4_type = ARG_ANYTHING, > @@ -349,7 +349,7 @@ const struct bpf_func_proto bpf_task_storage_get_proto = { > .gpl_only = false, > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > .arg4_type = ARG_ANYTHING, > @@ -360,7 +360,7 @@ const struct bpf_func_proto bpf_task_storage_delete_recur_proto = { > .gpl_only = false, > .ret_type = RET_INTEGER, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > }; > > @@ -369,6 +369,6 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = { > .gpl_only = false, > .ret_type = RET_INTEGER, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > }; > diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c > index 085025c7130a..d4172534dfa8 100644 > --- a/net/core/bpf_sk_storage.c > +++ b/net/core/bpf_sk_storage.c > @@ -412,7 +412,7 @@ const struct bpf_func_proto bpf_sk_storage_get_tracing_proto = { > .gpl_only = false, > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > .arg4_type = ARG_ANYTHING, > @@ -424,7 +424,7 @@ const struct bpf_func_proto bpf_sk_storage_delete_tracing_proto = { > .gpl_only = false, > .ret_type = RET_INTEGER, > .arg1_type = ARG_CONST_MAP_PTR, > - .arg2_type = ARG_PTR_TO_BTF_ID, > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], > .allowed = bpf_sk_storage_tracing_allowed, > }; Should we also add PTR_MAYBE_NULL to the ARG_PTR_TO_BTF_ID_SOCK_COMMON arg in bpf_sk_storage_get_proto and bpf_sk_storage_delete_proto? > diff --git a/net/core/filter.c b/net/core/filter.c > index 1f2abf0f60e6..727c5269867d 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -4998,7 +4998,7 @@ const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = { > .func = bpf_get_socket_ptr_cookie, > .gpl_only = false, > .ret_type = RET_INTEGER, > - .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON, > + .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON | PTR_MAYBE_NULL, > }; > > BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx) > -- > 2.34.1 >
On Tue, Apr 4, 2023 at 7:46 AM David Vernet <void@manifault.com> wrote: > > On Mon, Apr 03, 2023 at 09:50:25PM -0700, Alexei Starovoitov wrote: > > From: Alexei Starovoitov <ast@kernel.org> > > > > bpf_[sk|inode|task|cgrp]_storage_[get|delete]() and bpf_get_socket_cookie() helpers > > perform run-time check that sk|inode|task|cgrp pointer != NULL. > > Teach verifier about this fact and allow bpf programs to pass > > PTR_TO_BTF_ID | PTR_MAYBE_NULL into such helpers. > > It will be used in the subsequent patch that will do > > bpf_sk_storage_get(.., skb->sk, ...); > > Even when 'skb' pointer is trusted the 'sk' pointer may be NULL. > > > > Signed-off-by: Alexei Starovoitov <ast@kernel.org> > > --- > > kernel/bpf/bpf_cgrp_storage.c | 4 ++-- > > kernel/bpf/bpf_inode_storage.c | 4 ++-- > > kernel/bpf/bpf_task_storage.c | 8 ++++---- > > net/core/bpf_sk_storage.c | 4 ++-- > > net/core/filter.c | 2 +- > > 5 files changed, 11 insertions(+), 11 deletions(-) > > > > diff --git a/kernel/bpf/bpf_cgrp_storage.c b/kernel/bpf/bpf_cgrp_storage.c > > index d17d5b694668..d44fe8dd9732 100644 > > --- a/kernel/bpf/bpf_cgrp_storage.c > > +++ b/kernel/bpf/bpf_cgrp_storage.c > > @@ -224,7 +224,7 @@ const struct bpf_func_proto bpf_cgrp_storage_get_proto = { > > .gpl_only = false, > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &bpf_cgroup_btf_id[0], > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > .arg4_type = ARG_ANYTHING, > > @@ -235,6 +235,6 @@ const struct bpf_func_proto bpf_cgrp_storage_delete_proto = { > > .gpl_only = false, > > .ret_type = RET_INTEGER, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &bpf_cgroup_btf_id[0], > > }; > > diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c > > index e17ad581b9be..a4d93df78c75 100644 > > --- a/kernel/bpf/bpf_inode_storage.c > > +++ b/kernel/bpf/bpf_inode_storage.c > > @@ -229,7 +229,7 @@ const struct bpf_func_proto bpf_inode_storage_get_proto = { > > .gpl_only = false, > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &bpf_inode_storage_btf_ids[0], > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > .arg4_type = ARG_ANYTHING, > > @@ -240,6 +240,6 @@ const struct bpf_func_proto bpf_inode_storage_delete_proto = { > > .gpl_only = false, > > .ret_type = RET_INTEGER, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &bpf_inode_storage_btf_ids[0], > > }; > > diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c > > index d1af0c8f9ce4..adf6dfe0ba68 100644 > > --- a/kernel/bpf/bpf_task_storage.c > > +++ b/kernel/bpf/bpf_task_storage.c > > @@ -338,7 +338,7 @@ const struct bpf_func_proto bpf_task_storage_get_recur_proto = { > > .gpl_only = false, > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > .arg4_type = ARG_ANYTHING, > > @@ -349,7 +349,7 @@ const struct bpf_func_proto bpf_task_storage_get_proto = { > > .gpl_only = false, > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > .arg4_type = ARG_ANYTHING, > > @@ -360,7 +360,7 @@ const struct bpf_func_proto bpf_task_storage_delete_recur_proto = { > > .gpl_only = false, > > .ret_type = RET_INTEGER, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > }; > > > > @@ -369,6 +369,6 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = { > > .gpl_only = false, > > .ret_type = RET_INTEGER, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > }; > > diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c > > index 085025c7130a..d4172534dfa8 100644 > > --- a/net/core/bpf_sk_storage.c > > +++ b/net/core/bpf_sk_storage.c > > @@ -412,7 +412,7 @@ const struct bpf_func_proto bpf_sk_storage_get_tracing_proto = { > > .gpl_only = false, > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > .arg4_type = ARG_ANYTHING, > > @@ -424,7 +424,7 @@ const struct bpf_func_proto bpf_sk_storage_delete_tracing_proto = { > > .gpl_only = false, > > .ret_type = RET_INTEGER, > > .arg1_type = ARG_CONST_MAP_PTR, > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], > > .allowed = bpf_sk_storage_tracing_allowed, > > }; > > Should we also add PTR_MAYBE_NULL to the ARG_PTR_TO_BTF_ID_SOCK_COMMON > arg in bpf_sk_storage_get_proto and bpf_sk_storage_delete_proto? It makes sense. I'd like to do it in the follow up though. I haven't seen networking progs passing null-able pointer into these helpers. Only tracing progs do. I need to craft a test case, etc. While this set is good to go imo.
On Tue, Apr 04, 2023 at 01:17:25PM -0700, Alexei Starovoitov wrote: > On Tue, Apr 4, 2023 at 7:46 AM David Vernet <void@manifault.com> wrote: > > > > On Mon, Apr 03, 2023 at 09:50:25PM -0700, Alexei Starovoitov wrote: > > > From: Alexei Starovoitov <ast@kernel.org> > > > > > > bpf_[sk|inode|task|cgrp]_storage_[get|delete]() and bpf_get_socket_cookie() helpers > > > perform run-time check that sk|inode|task|cgrp pointer != NULL. > > > Teach verifier about this fact and allow bpf programs to pass > > > PTR_TO_BTF_ID | PTR_MAYBE_NULL into such helpers. > > > It will be used in the subsequent patch that will do > > > bpf_sk_storage_get(.., skb->sk, ...); > > > Even when 'skb' pointer is trusted the 'sk' pointer may be NULL. > > > > > > Signed-off-by: Alexei Starovoitov <ast@kernel.org> > > > --- > > > kernel/bpf/bpf_cgrp_storage.c | 4 ++-- > > > kernel/bpf/bpf_inode_storage.c | 4 ++-- > > > kernel/bpf/bpf_task_storage.c | 8 ++++---- > > > net/core/bpf_sk_storage.c | 4 ++-- > > > net/core/filter.c | 2 +- > > > 5 files changed, 11 insertions(+), 11 deletions(-) > > > > > > diff --git a/kernel/bpf/bpf_cgrp_storage.c b/kernel/bpf/bpf_cgrp_storage.c > > > index d17d5b694668..d44fe8dd9732 100644 > > > --- a/kernel/bpf/bpf_cgrp_storage.c > > > +++ b/kernel/bpf/bpf_cgrp_storage.c > > > @@ -224,7 +224,7 @@ const struct bpf_func_proto bpf_cgrp_storage_get_proto = { > > > .gpl_only = false, > > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &bpf_cgroup_btf_id[0], > > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg4_type = ARG_ANYTHING, > > > @@ -235,6 +235,6 @@ const struct bpf_func_proto bpf_cgrp_storage_delete_proto = { > > > .gpl_only = false, > > > .ret_type = RET_INTEGER, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &bpf_cgroup_btf_id[0], > > > }; > > > diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c > > > index e17ad581b9be..a4d93df78c75 100644 > > > --- a/kernel/bpf/bpf_inode_storage.c > > > +++ b/kernel/bpf/bpf_inode_storage.c > > > @@ -229,7 +229,7 @@ const struct bpf_func_proto bpf_inode_storage_get_proto = { > > > .gpl_only = false, > > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &bpf_inode_storage_btf_ids[0], > > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg4_type = ARG_ANYTHING, > > > @@ -240,6 +240,6 @@ const struct bpf_func_proto bpf_inode_storage_delete_proto = { > > > .gpl_only = false, > > > .ret_type = RET_INTEGER, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &bpf_inode_storage_btf_ids[0], > > > }; > > > diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c > > > index d1af0c8f9ce4..adf6dfe0ba68 100644 > > > --- a/kernel/bpf/bpf_task_storage.c > > > +++ b/kernel/bpf/bpf_task_storage.c > > > @@ -338,7 +338,7 @@ const struct bpf_func_proto bpf_task_storage_get_recur_proto = { > > > .gpl_only = false, > > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg4_type = ARG_ANYTHING, > > > @@ -349,7 +349,7 @@ const struct bpf_func_proto bpf_task_storage_get_proto = { > > > .gpl_only = false, > > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg4_type = ARG_ANYTHING, > > > @@ -360,7 +360,7 @@ const struct bpf_func_proto bpf_task_storage_delete_recur_proto = { > > > .gpl_only = false, > > > .ret_type = RET_INTEGER, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > > }; > > > > > > @@ -369,6 +369,6 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = { > > > .gpl_only = false, > > > .ret_type = RET_INTEGER, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], > > > }; > > > diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c > > > index 085025c7130a..d4172534dfa8 100644 > > > --- a/net/core/bpf_sk_storage.c > > > +++ b/net/core/bpf_sk_storage.c > > > @@ -412,7 +412,7 @@ const struct bpf_func_proto bpf_sk_storage_get_tracing_proto = { > > > .gpl_only = false, > > > .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], > > > .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, > > > .arg4_type = ARG_ANYTHING, > > > @@ -424,7 +424,7 @@ const struct bpf_func_proto bpf_sk_storage_delete_tracing_proto = { > > > .gpl_only = false, > > > .ret_type = RET_INTEGER, > > > .arg1_type = ARG_CONST_MAP_PTR, > > > - .arg2_type = ARG_PTR_TO_BTF_ID, > > > + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, > > > .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], > > > .allowed = bpf_sk_storage_tracing_allowed, > > > }; > > > > Should we also add PTR_MAYBE_NULL to the ARG_PTR_TO_BTF_ID_SOCK_COMMON > > arg in bpf_sk_storage_get_proto and bpf_sk_storage_delete_proto? > > It makes sense. I'd like to do it in the follow up though. > I haven't seen networking progs passing null-able pointer into these helpers. > Only tracing progs do. > I need to craft a test case, etc. Sounds good > While this set is good to go imo. Agreed, the series LGTM.
On 4/3/23 9:50 PM, Alexei Starovoitov wrote: > diff --git a/net/core/filter.c b/net/core/filter.c > index 1f2abf0f60e6..727c5269867d 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -4998,7 +4998,7 @@ const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = { > .func = bpf_get_socket_ptr_cookie, > .gpl_only = false, > .ret_type = RET_INTEGER, > - .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON, > + .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON | PTR_MAYBE_NULL, I think the bpf_skc_to_* helpers (eg. bpf_skc_to_tcp_sock) also need similar change. They are available to tracing also. It can be a follow-up. The patch set lgtm.
On Tue, Apr 4, 2023 at 5:10 PM Martin KaFai Lau <martin.lau@linux.dev> wrote: > > On 4/3/23 9:50 PM, Alexei Starovoitov wrote: > > diff --git a/net/core/filter.c b/net/core/filter.c > > index 1f2abf0f60e6..727c5269867d 100644 > > --- a/net/core/filter.c > > +++ b/net/core/filter.c > > @@ -4998,7 +4998,7 @@ const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = { > > .func = bpf_get_socket_ptr_cookie, > > .gpl_only = false, > > .ret_type = RET_INTEGER, > > - .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON, > > + .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON | PTR_MAYBE_NULL, > > I think the bpf_skc_to_* helpers (eg. bpf_skc_to_tcp_sock) also need similar > change. They are available to tracing also. It can be a follow-up. The patch set > lgtm. Ok. I'll take a look.
diff --git a/kernel/bpf/bpf_cgrp_storage.c b/kernel/bpf/bpf_cgrp_storage.c index d17d5b694668..d44fe8dd9732 100644 --- a/kernel/bpf/bpf_cgrp_storage.c +++ b/kernel/bpf/bpf_cgrp_storage.c @@ -224,7 +224,7 @@ const struct bpf_func_proto bpf_cgrp_storage_get_proto = { .gpl_only = false, .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &bpf_cgroup_btf_id[0], .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, .arg4_type = ARG_ANYTHING, @@ -235,6 +235,6 @@ const struct bpf_func_proto bpf_cgrp_storage_delete_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &bpf_cgroup_btf_id[0], }; diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c index e17ad581b9be..a4d93df78c75 100644 --- a/kernel/bpf/bpf_inode_storage.c +++ b/kernel/bpf/bpf_inode_storage.c @@ -229,7 +229,7 @@ const struct bpf_func_proto bpf_inode_storage_get_proto = { .gpl_only = false, .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &bpf_inode_storage_btf_ids[0], .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, .arg4_type = ARG_ANYTHING, @@ -240,6 +240,6 @@ const struct bpf_func_proto bpf_inode_storage_delete_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &bpf_inode_storage_btf_ids[0], }; diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c index d1af0c8f9ce4..adf6dfe0ba68 100644 --- a/kernel/bpf/bpf_task_storage.c +++ b/kernel/bpf/bpf_task_storage.c @@ -338,7 +338,7 @@ const struct bpf_func_proto bpf_task_storage_get_recur_proto = { .gpl_only = false, .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, .arg4_type = ARG_ANYTHING, @@ -349,7 +349,7 @@ const struct bpf_func_proto bpf_task_storage_get_proto = { .gpl_only = false, .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, .arg4_type = ARG_ANYTHING, @@ -360,7 +360,7 @@ const struct bpf_func_proto bpf_task_storage_delete_recur_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], }; @@ -369,6 +369,6 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], }; diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c index 085025c7130a..d4172534dfa8 100644 --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -412,7 +412,7 @@ const struct bpf_func_proto bpf_sk_storage_get_tracing_proto = { .gpl_only = false, .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, .arg4_type = ARG_ANYTHING, @@ -424,7 +424,7 @@ const struct bpf_func_proto bpf_sk_storage_delete_tracing_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1_type = ARG_CONST_MAP_PTR, - .arg2_type = ARG_PTR_TO_BTF_ID, + .arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL, .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], .allowed = bpf_sk_storage_tracing_allowed, }; diff --git a/net/core/filter.c b/net/core/filter.c index 1f2abf0f60e6..727c5269867d 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4998,7 +4998,7 @@ const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = { .func = bpf_get_socket_ptr_cookie, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON, + .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON | PTR_MAYBE_NULL, }; BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)