* Re: [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points
@ 2020-09-26 2:59 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-09-26 2:59 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 21560 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <160106910487.27725.11983967672504271627.stgit@toke.dk>
References: <160106910487.27725.11983967672504271627.stgit@toke.dk>
TO: "Toke Høiland-Jørgensen" <toke@redhat.com>
Hi "Toke,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Toke-H-iland-J-rgensen/bpf-Support-multi-attach-for-freplace-programs/20200926-052738
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago
config: x86_64-randconfig-m001-20200925 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
kernel/bpf/verifier.c:11378 bpf_check_attach_target() error: we previously assumed 'dst_prog' could be null (see line 11250)
vim +/dst_prog +11378 kernel/bpf/verifier.c
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11214
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11215 int bpf_check_attach_target(struct bpf_verifier_log *log,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11216 const struct bpf_prog *prog,
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11217 const struct bpf_prog *dst_prog,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11218 u32 btf_id,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11219 struct bpf_attach_target_info *tgt_info)
38207291604401 Martin KaFai Lau 2019-10-24 11220 {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11221 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11222 const char prefix[] = "btf_trace_";
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11223 int ret = 0, subprog = -1, i;
38207291604401 Martin KaFai Lau 2019-10-24 11224 const struct btf_type *t;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11225 bool conservative = true;
38207291604401 Martin KaFai Lau 2019-10-24 11226 const char *tname;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11227 struct btf *btf;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11228 long addr = 0;
38207291604401 Martin KaFai Lau 2019-10-24 11229
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11230 if (!btf_id) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11231 bpf_log(log, "Tracing programs must provide btf_id\n");
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11232 return -EINVAL;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11233 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11234 btf = dst_prog ? dst_prog->aux->btf : btf_vmlinux;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11235 if (!btf) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11236 bpf_log(log,
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11237 "FENTRY/FEXIT program can only be attached to another program annotated with BTF\n");
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11238 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11239 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11240 t = btf_type_by_id(btf, btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11241 if (!t) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11242 bpf_log(log, "attach_btf_id %u is invalid\n", btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11243 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11244 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11245 tname = btf_name_by_offset(btf, t->name_off);
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11246 if (!tname) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11247 bpf_log(log, "attach_btf_id %u doesn't have a name\n", btf_id);
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11248 return -EINVAL;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11249 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 @11250 if (dst_prog) {
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11251 struct bpf_prog_aux *aux = dst_prog->aux;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11252
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11253 for (i = 0; i < aux->func_info_cnt; i++)
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11254 if (aux->func_info[i].type_id == btf_id) {
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11255 subprog = i;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11256 break;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11257 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11258 if (subprog == -1) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11259 bpf_log(log, "Subprog %s doesn't exist\n", tname);
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11260 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11261 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11262 conservative = aux->func_info_aux[subprog].unreliable;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11263 if (prog_extension) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11264 if (conservative) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11265 bpf_log(log,
be8704ff07d237 Alexei Starovoitov 2020-01-20 11266 "Cannot replace static functions\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11267 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11268 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11269 if (!prog->jit_requested) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11270 bpf_log(log,
be8704ff07d237 Alexei Starovoitov 2020-01-20 11271 "Extension programs should be JITed\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11272 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11273 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11274 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11275 if (!dst_prog->jited) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11276 bpf_log(log, "Can attach to only JITed progs\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11277 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11278 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11279 if (dst_prog->type == prog->type) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11280 /* Cannot fentry/fexit another fentry/fexit program.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11281 * Cannot attach program extension to another extension.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11282 * It's ok to attach fentry/fexit to extension program.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11283 */
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11284 bpf_log(log, "Cannot recursively attach\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11285 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11286 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11287 if (dst_prog->type == BPF_PROG_TYPE_TRACING &&
be8704ff07d237 Alexei Starovoitov 2020-01-20 11288 prog_extension &&
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11289 (dst_prog->expected_attach_type == BPF_TRACE_FENTRY ||
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11290 dst_prog->expected_attach_type == BPF_TRACE_FEXIT)) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11291 /* Program extensions can extend all program types
be8704ff07d237 Alexei Starovoitov 2020-01-20 11292 * except fentry/fexit. The reason is the following.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11293 * The fentry/fexit programs are used for performance
be8704ff07d237 Alexei Starovoitov 2020-01-20 11294 * analysis, stats and can be attached to any program
be8704ff07d237 Alexei Starovoitov 2020-01-20 11295 * type except themselves. When extension program is
be8704ff07d237 Alexei Starovoitov 2020-01-20 11296 * replacing XDP function it is necessary to allow
be8704ff07d237 Alexei Starovoitov 2020-01-20 11297 * performance analysis of all functions. Both original
be8704ff07d237 Alexei Starovoitov 2020-01-20 11298 * XDP program and its program extension. Hence
be8704ff07d237 Alexei Starovoitov 2020-01-20 11299 * attaching fentry/fexit to BPF_PROG_TYPE_EXT is
be8704ff07d237 Alexei Starovoitov 2020-01-20 11300 * allowed. If extending of fentry/fexit was allowed it
be8704ff07d237 Alexei Starovoitov 2020-01-20 11301 * would be possible to create long call chain
be8704ff07d237 Alexei Starovoitov 2020-01-20 11302 * fentry->extension->fentry->extension beyond
be8704ff07d237 Alexei Starovoitov 2020-01-20 11303 * reasonable stack size. Hence extending fentry is not
be8704ff07d237 Alexei Starovoitov 2020-01-20 11304 * allowed.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11305 */
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11306 bpf_log(log, "Cannot extend fentry/fexit\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11307 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11308 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11309 } else {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11310 if (prog_extension) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11311 bpf_log(log, "Cannot replace kernel functions\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11312 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11313 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11314 }
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11315
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11316 switch (prog->expected_attach_type) {
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11317 case BPF_TRACE_RAW_TP:
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11318 if (dst_prog) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11319 bpf_log(log,
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11320 "Only FENTRY/FEXIT progs are attachable to another BPF prog\n");
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11321 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11322 }
38207291604401 Martin KaFai Lau 2019-10-24 11323 if (!btf_type_is_typedef(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11324 bpf_log(log, "attach_btf_id %u is not a typedef\n",
38207291604401 Martin KaFai Lau 2019-10-24 11325 btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11326 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11327 }
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11328 if (strncmp(prefix, tname, sizeof(prefix) - 1)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11329 bpf_log(log, "attach_btf_id %u points to wrong type name %s\n",
38207291604401 Martin KaFai Lau 2019-10-24 11330 btf_id, tname);
38207291604401 Martin KaFai Lau 2019-10-24 11331 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11332 }
38207291604401 Martin KaFai Lau 2019-10-24 11333 tname += sizeof(prefix) - 1;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11334 t = btf_type_by_id(btf, t->type);
38207291604401 Martin KaFai Lau 2019-10-24 11335 if (!btf_type_is_ptr(t))
38207291604401 Martin KaFai Lau 2019-10-24 11336 /* should never happen in valid vmlinux build */
38207291604401 Martin KaFai Lau 2019-10-24 11337 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11338 t = btf_type_by_id(btf, t->type);
38207291604401 Martin KaFai Lau 2019-10-24 11339 if (!btf_type_is_func_proto(t))
38207291604401 Martin KaFai Lau 2019-10-24 11340 /* should never happen in valid vmlinux build */
38207291604401 Martin KaFai Lau 2019-10-24 11341 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11342
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11343 break;
15d83c4d7cef5c Yonghong Song 2020-05-09 11344 case BPF_TRACE_ITER:
15d83c4d7cef5c Yonghong Song 2020-05-09 11345 if (!btf_type_is_func(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11346 bpf_log(log, "attach_btf_id %u is not a function\n",
15d83c4d7cef5c Yonghong Song 2020-05-09 11347 btf_id);
15d83c4d7cef5c Yonghong Song 2020-05-09 11348 return -EINVAL;
15d83c4d7cef5c Yonghong Song 2020-05-09 11349 }
15d83c4d7cef5c Yonghong Song 2020-05-09 11350 t = btf_type_by_id(btf, t->type);
15d83c4d7cef5c Yonghong Song 2020-05-09 11351 if (!btf_type_is_func_proto(t))
15d83c4d7cef5c Yonghong Song 2020-05-09 11352 return -EINVAL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11353 ret = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11354 if (ret)
15d83c4d7cef5c Yonghong Song 2020-05-09 11355 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11356 break;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11357 default:
be8704ff07d237 Alexei Starovoitov 2020-01-20 11358 if (!prog_extension)
be8704ff07d237 Alexei Starovoitov 2020-01-20 11359 return -EINVAL;
df561f6688fef7 Gustavo A. R. Silva 2020-08-23 11360 fallthrough;
ae24082331d9bb KP Singh 2020-03-04 11361 case BPF_MODIFY_RETURN:
9e4e01dfd3254c KP Singh 2020-03-29 11362 case BPF_LSM_MAC:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11363 case BPF_TRACE_FENTRY:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11364 case BPF_TRACE_FEXIT:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11365 if (!btf_type_is_func(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11366 bpf_log(log, "attach_btf_id %u is not a function\n",
fec56f5890d93f Alexei Starovoitov 2019-11-14 11367 btf_id);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11368 return -EINVAL;
fec56f5890d93f Alexei Starovoitov 2019-11-14 11369 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11370 if (prog_extension &&
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11371 btf_check_type_match(log, prog, btf, t))
be8704ff07d237 Alexei Starovoitov 2020-01-20 11372 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11373 t = btf_type_by_id(btf, t->type);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11374 if (!btf_type_is_func_proto(t))
fec56f5890d93f Alexei Starovoitov 2019-11-14 11375 return -EINVAL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11376
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11377 if ((prog->aux->saved_dst_prog_type &&
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 @11378 prog->aux->saved_dst_prog_type != dst_prog->type) ||
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11379 (prog->aux->saved_dst_attach_type &&
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11380 prog->aux->saved_dst_attach_type != dst_prog->expected_attach_type))
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11381 return -EINVAL;
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11382
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11383 if (dst_prog && conservative)
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11384 t = NULL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11385
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11386 ret = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11387 if (ret < 0)
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11388 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11389
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11390 if (dst_prog) {
e9eeec58c992c4 Yonghong Song 2019-12-04 11391 if (subprog == 0)
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11392 addr = (long) dst_prog->bpf_func;
e9eeec58c992c4 Yonghong Song 2019-12-04 11393 else
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11394 addr = (long) dst_prog->aux->func[subprog]->bpf_func;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11395 } else {
fec56f5890d93f Alexei Starovoitov 2019-11-14 11396 addr = kallsyms_lookup_name(tname);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11397 if (!addr) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11398 bpf_log(log,
fec56f5890d93f Alexei Starovoitov 2019-11-14 11399 "The address of function %s cannot be found\n",
fec56f5890d93f Alexei Starovoitov 2019-11-14 11400 tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11401 return -ENOENT;
fec56f5890d93f Alexei Starovoitov 2019-11-14 11402 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11403 }
18644cec714aab Alexei Starovoitov 2020-05-28 11404
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11405 if (prog->aux->sleepable) {
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11406 ret = -EINVAL;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11407 switch (prog->type) {
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11408 case BPF_PROG_TYPE_TRACING:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11409 /* fentry/fexit/fmod_ret progs can be sleepable only if they are
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11410 * attached to ALLOW_ERROR_INJECTION and are not in denylist.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11411 */
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11412 if (!check_non_sleepable_error_inject(btf_id) &&
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11413 within_error_injection_list(addr))
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11414 ret = 0;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11415 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11416 case BPF_PROG_TYPE_LSM:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11417 /* LSM progs check that they are attached to bpf_lsm_*() funcs.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11418 * Only some of them are sleepable.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11419 */
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11420 if (check_sleepable_lsm_hook(btf_id))
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11421 ret = 0;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11422 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11423 default:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11424 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11425 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11426 if (ret) {
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11427 bpf_log(log, "%s is not sleepable\n", tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11428 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11429 }
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11430 } else if (prog->expected_attach_type == BPF_MODIFY_RETURN) {
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11431 if (dst_prog) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11432 bpf_log(log, "can't modify return codes of BPF programs\n");
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11433 return -EINVAL;
81a09cc12e4a91 Toke Høiland-Jørgensen 2020-09-25 11434 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11435 ret = check_attach_modify_return(addr, tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11436 if (ret) {
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11437 bpf_log(log, "%s() is not modifiable\n", tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11438 return ret;
18644cec714aab Alexei Starovoitov 2020-05-28 11439 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11440 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11441
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11442 break;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11443 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11444 tgt_info->tgt_addr = addr;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11445 tgt_info->tgt_name = tname;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11446 tgt_info->tgt_type = t;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11447 return 0;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11448 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11449
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30894 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH bpf-next v9 00/11] bpf: Support multi-attach for freplace programs
@ 2020-09-25 21:24 Toke Høiland-Jørgensen
2020-09-25 21:25 ` [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points Toke Høiland-Jørgensen
0 siblings, 1 reply; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-09-25 21:24 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
Andrii Nakryiko, John Fastabend, Jiri Olsa, Eelco Chaudron,
KP Singh, netdev, bpf
This series adds support attaching freplace BPF programs to multiple targets.
This is needed to support incremental attachment of multiple XDP programs using
the libxdp dispatcher model.
The first patch fixes an issue that came up in review: The verifier will
currently allow MODIFY_RETURN tracing functions to attach to other BPF programs,
even though it is pretty clear from the commit messages introducing the
functionality that this was not the intention. This patch is included in the
series because the subsequent refactoring patches touch the same code.
The next three patches are refactoring patches: Patch 2 is a trivial change to
the logging in the verifier, split out to make the subsequent refactor easier to
read. Patch 3 refactors check_attach_btf_id() so that the checks on program and
target compatibility can be reused when attaching to a secondary location.
Patch 4 moves prog_aux->linked_prog and the trampoline to be embedded in
bpf_tracing_link on attach, and freed by the link release logic, and introduces
a mutex to protect the writing of the pointers in prog->aux.
Based on these refactorings, it becomes pretty straight-forward to support
multiple-attach for freplace programs (patch 5). This is simply a matter of
creating a second bpf_tracing_link if a target is supplied. However, for API
consistency with other types of link attach, this option is added to the
BPF_LINK_CREATE API instead of extending bpf_raw_tracepoint_open().
Patch 6 is a port of Jiri Olsa's patch to support fentry/fexit on freplace
programs. His approach of getting the target type from the target program
reference no longer works after we've gotten rid of linked_prog (because the
bpf_tracing_link reference disappears on attach). Instead, we used the saved
reference to the target prog type that is also used to verify compatibility on
secondary freplace attachment.
Patches 7 is the accompanying libbpf update, and patches 8-11 are selftests:
patch 8 tests for the multi-freplace functionality itself; patch 9 is Jiri's
previous selftest for the fentry-to-freplace fix; patch 10 is a test for the
change introduced in patch 1, blocking MODIFY_RETURN functions from attaching to
other BPF programs; and finally, patch 11 removes the MODIFY_RETURN function
from test_overhead program in selftests, as this was never supposed to work in
the first place.
With this series, libxdp and xdp-tools can successfully attach multiple programs
one at a time. To play with this, use the 'freplace-multi-attach' branch of
xdp-tools:
$ git clone --recurse-submodules --branch freplace-multi-attach https://github.com/xdp-project/xdp-tools
$ cd xdp-tools/xdp-loader
$ make
$ sudo ./xdp-loader load veth0 ../lib/testing/xdp_drop.o
$ sudo ./xdp-loader load veth0 ../lib/testing/xdp_pass.o
$ sudo ./xdp-loader status
The series is also available here:
https://git.kernel.org/pub/scm/linux/kernel/git/toke/linux.git/log/?h=bpf-freplace-multi-attach-alt-09
Changelog:
v9:
- Clarify commit message of patch 3
- Add new struct bpf_attach_target_info for returning from
bpf_check_attach_target() and passing to bpf_trampoline_get()
- Move trampoline key computation into a helper
- Make sure we don't break bpffs debug umh
- Add some comment blocks explaining the logic flow in
bpf_tracing_prog_attach()
- s/tgt_/dst_/ in prog->aux, and for local variables using those members
- Always drop dst_trampoline and dst_prog from prog->aux on first attach
- Don't remove syscall fmod_ret test from selftest benchmarks
- Add saved_ prefix to dst_{prog,attach}_type members in prog_aux
- Drop prog argument from check_attach_modify_return()
- Add comment about possible NULL of tr_link->tgt_prog on link_release()
v8:
- Add a separate error message when trying to attach FMOD_REPLACE to tgt_prog
- Better error messages in bpf_program__attach_freplace()
- Don't lock mutex when setting tgt_* pointers in prog create and verifier
- Remove fmod_ret programs from benchmarks in selftests (new patch 11)
- Fix a few other nits in selftests
v7:
- Add back missing ptype == prog->type check in link_create()
- Use tracing_bpf_link_attach() instead of separate freplace_bpf_link_attach()
- Don't break attachment of bpf_iters in libbpf (by clobbering link_create.iter_info)
v6:
- Rebase to latest bpf-next
- Simplify logic in bpf_tracing_prog_attach()
- Don't create a new attach_type for link_create(), disambiguate on prog->type
instead
- Use raw_tracepoint_open() in libbpf bpf_program__attach_ftrace() if called
with NULL target
- Switch bpf_program__attach_ftrace() to take function name as parameter
instead of btf_id
- Add a patch disallowing MODIFY_RETURN programs from attaching to other BPF
programs, and an accompanying selftest (patches 1 and 10)
v5:
- Fix typo in inline function definition of bpf_trampoline_get()
- Don't put bpf_tracing_link in prog->aux, use a mutex to protect tgt_prog and
trampoline instead, and move them to the link on attach.
- Restore Jiri as author of the last selftest patch
v4:
- Cleanup the refactored check_attach_btf_id() to make the logic easier to follow
- Fix cleanup paths for bpf_tracing_link
- Use xchg() for removing the bpf_tracing_link from prog->aux and restore on (some) failures
- Use BPF_LINK_CREATE operation to create link with target instead of extending raw_tracepoint_open
- Fold update of tools/ UAPI header into main patch
- Update arg dereference patch to use skeletons and set_attach_target()
v3:
- Get rid of prog_aux->linked_prog entirely in favour of a bpf_tracing_link
- Incorporate Jiri's fix for attaching fentry to freplace programs
v2:
- Drop the log arguments from bpf_raw_tracepoint_open
- Fix kbot errors
- Rebase to latest bpf-next
---
Jiri Olsa (1):
selftests/bpf: Adding test for arg dereference in extension trace
Toke Høiland-Jørgensen (10):
bpf: disallow attaching modify_return tracing functions to other BPF programs
bpf: change logging calls from verbose() to bpf_log() and use log pointer
bpf: verifier: refactor check_attach_btf_id()
bpf: move prog->aux->linked_prog and trampoline into bpf_link on attach
bpf: support attaching freplace programs to multiple attach points
bpf: Fix context type resolving for extension programs
libbpf: add support for freplace attachment in bpf_link_create
selftests: add test for multiple attachments of freplace program
selftests: Add selftest for disallowing modify_return attachment to freplace
selftests: Remove fmod_ret from test_overhead
include/linux/bpf.h | 36 +-
include/linux/bpf_verifier.h | 18 +-
include/uapi/linux/bpf.h | 9 +-
kernel/bpf/btf.c | 27 +-
kernel/bpf/core.c | 9 +-
kernel/bpf/preload/iterators/iterators.bpf.c | 4 +-
kernel/bpf/preload/iterators/iterators.skel.h | 444 +++++++++---------
kernel/bpf/syscall.c | 180 ++++++-
kernel/bpf/trampoline.c | 34 +-
kernel/bpf/verifier.c | 263 ++++++-----
tools/include/uapi/linux/bpf.h | 9 +-
tools/lib/bpf/bpf.c | 18 +-
tools/lib/bpf/bpf.h | 3 +-
tools/lib/bpf/libbpf.c | 44 +-
tools/lib/bpf/libbpf.h | 3 +
tools/lib/bpf/libbpf.map | 1 +
tools/testing/selftests/bpf/bench.c | 3 -
.../selftests/bpf/benchs/bench_rename.c | 17 -
.../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 212 +++++++--
.../selftests/bpf/prog_tests/test_overhead.c | 14 +-
.../selftests/bpf/prog_tests/trace_ext.c | 111 +++++
.../selftests/bpf/progs/fmod_ret_freplace.c | 14 +
.../bpf/progs/freplace_get_constant.c | 15 +
.../selftests/bpf/progs/test_overhead.c | 6 -
.../selftests/bpf/progs/test_trace_ext.c | 18 +
.../bpf/progs/test_trace_ext_tracing.c | 25 +
26 files changed, 1052 insertions(+), 485 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/trace_ext.c
create mode 100644 tools/testing/selftests/bpf/progs/fmod_ret_freplace.c
create mode 100644 tools/testing/selftests/bpf/progs/freplace_get_constant.c
create mode 100644 tools/testing/selftests/bpf/progs/test_trace_ext.c
create mode 100644 tools/testing/selftests/bpf/progs/test_trace_ext_tracing.c
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points
2020-09-25 21:24 [PATCH bpf-next v9 00/11] bpf: Support multi-attach for freplace programs Toke Høiland-Jørgensen
@ 2020-09-25 21:25 ` Toke Høiland-Jørgensen
2020-09-29 7:07 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-09-25 21:25 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
Andrii Nakryiko, John Fastabend, Jiri Olsa, Eelco Chaudron,
KP Singh, netdev, bpf
From: Toke Høiland-Jørgensen <toke@redhat.com>
This enables support for attaching freplace programs to multiple attach
points. It does this by amending the UAPI for bpf_link_Create with a target
btf ID that can be used to supply the new attachment point along with the
target program fd. The target must be compatible with the target that was
supplied at program load time.
The implementation reuses the checks that were factored out of
check_attach_btf_id() to ensure compatibility between the BTF types of the
old and new attachment. If these match, a new bpf_tracing_link will be
created for the new attach target, allowing multiple attachments to
co-exist simultaneously.
The code could theoretically support multiple-attach of other types of
tracing programs as well, but since I don't have a use case for any of
those, there is no API support for doing so.
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
include/linux/bpf.h | 2 +
include/uapi/linux/bpf.h | 9 ++-
kernel/bpf/syscall.c | 132 +++++++++++++++++++++++++++++++++++-----
kernel/bpf/verifier.c | 11 +++
tools/include/uapi/linux/bpf.h | 9 ++-
5 files changed, 143 insertions(+), 20 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 8f80dd3ed5ed..d45cda3ab441 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -753,6 +753,8 @@ struct bpf_prog_aux {
struct mutex dst_mutex; /* protects dst_* pointers below, *after* prog becomes visible */
struct bpf_prog *dst_prog;
struct bpf_trampoline *dst_trampoline;
+ enum bpf_prog_type saved_dst_prog_type;
+ enum bpf_attach_type saved_dst_attach_type;
bool verifier_zext; /* Zero extensions has been inserted by verifier. */
bool offload_requested;
bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index a22812561064..feff1ed49f86 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -632,8 +632,13 @@ union bpf_attr {
};
__u32 attach_type; /* attach type */
__u32 flags; /* extra flags */
- __aligned_u64 iter_info; /* extra bpf_iter_link_info */
- __u32 iter_info_len; /* iter_info length */
+ union {
+ __u32 target_btf_id; /* btf_id of target to attach to */
+ struct {
+ __aligned_u64 iter_info; /* extra bpf_iter_link_info */
+ __u32 iter_info_len; /* iter_info length */
+ };
+ };
} link_create;
struct { /* struct used by BPF_LINK_UPDATE command */
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 099a651efe8b..743953f6bf21 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -4,6 +4,7 @@
#include <linux/bpf.h>
#include <linux/bpf_trace.h>
#include <linux/bpf_lirc.h>
+#include <linux/bpf_verifier.h>
#include <linux/btf.h>
#include <linux/syscalls.h>
#include <linux/slab.h>
@@ -2554,12 +2555,15 @@ static const struct bpf_link_ops bpf_tracing_link_lops = {
.fill_link_info = bpf_tracing_link_fill_link_info,
};
-static int bpf_tracing_prog_attach(struct bpf_prog *prog)
+static int bpf_tracing_prog_attach(struct bpf_prog *prog,
+ int tgt_prog_fd,
+ u32 btf_id)
{
struct bpf_link_primer link_primer;
struct bpf_prog *tgt_prog = NULL;
+ struct bpf_trampoline *tr = NULL;
struct bpf_tracing_link *link;
- struct bpf_trampoline *tr;
+ u64 key = 0;
int err;
switch (prog->type) {
@@ -2588,6 +2592,28 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog)
goto out_put_prog;
}
+ if (!!tgt_prog_fd != !!btf_id) {
+ err = -EINVAL;
+ goto out_put_prog;
+ }
+
+ if (tgt_prog_fd) {
+ /* For now we only allow new targets for BPF_PROG_TYPE_EXT */
+ if (prog->type != BPF_PROG_TYPE_EXT) {
+ err = -EINVAL;
+ goto out_put_prog;
+ }
+
+ tgt_prog = bpf_prog_get(tgt_prog_fd);
+ if (IS_ERR(tgt_prog)) {
+ err = PTR_ERR(tgt_prog);
+ tgt_prog = NULL;
+ goto out_put_prog;
+ }
+
+ key = bpf_trampoline_compute_key(tgt_prog, btf_id);
+ }
+
link = kzalloc(sizeof(*link), GFP_USER);
if (!link) {
err = -ENOMEM;
@@ -2599,12 +2625,58 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog)
mutex_lock(&prog->aux->dst_mutex);
- if (!prog->aux->dst_trampoline) {
+ /* There are a few possible cases here:
+ *
+ * - if prog->aux->dst_trampoline is set, the program was just loaded
+ * and not yet attached to anything, so we can use the values stored
+ * in prog->aux
+ *
+ * - if prog->aux->dst_trampoline is NULL, the program has already been
+ * attached to a target and its initial target was cleared (below)
+ *
+ * - if tgt_prog != NULL, the caller specified tgt_prog_fd +
+ * target_btf_id using the link_create API.
+ *
+ * - if tgt_prog == NULL when this function was called using the old
+ * raw_tracepoint_open API, and we need a target from prog->aux
+ *
+ * The combination of no saved target in prog->aux, and no target
+ * specified on load is illegal, and we reject that here.
+ */
+ if (!prog->aux->dst_trampoline && !tgt_prog) {
err = -ENOENT;
goto out_unlock;
}
- tr = prog->aux->dst_trampoline;
- tgt_prog = prog->aux->dst_prog;
+
+ if (!prog->aux->dst_trampoline ||
+ (key && key != prog->aux->dst_trampoline->key)) {
+ /* If there is no saved target, or the specified target is
+ * different from the destination specified at load time, we
+ * need a new trampoline and a check for compatibility
+ */
+ struct bpf_attach_target_info tgt_info = {};
+
+ err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
+ &tgt_info);
+ if (err)
+ goto out_unlock;
+
+ tr = bpf_trampoline_get(key, &tgt_info);
+ if (!tr) {
+ err = -ENOMEM;
+ goto out_unlock;
+ }
+ } else {
+ /* The caller didn't specify a target, or the target was the
+ * same as the destination supplied during program load. This
+ * means we can reuse the trampoline and reference from program
+ * load time, and there is no need to allocate a new one. This
+ * can only happen once for any program, as the saved values in
+ * prog->aux are cleared below.
+ */
+ tr = prog->aux->dst_trampoline;
+ tgt_prog = prog->aux->dst_prog;
+ }
err = bpf_link_prime(&link->link, &link_primer);
if (err)
@@ -2620,15 +2692,31 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog)
link->tgt_prog = tgt_prog;
link->trampoline = tr;
+ /* Always clear the trampoline and target prog from prog->aux to make
+ * sure the original attach destination is not kept alive after a
+ * program is (re-)attached to another target.
+ */
+ if (prog->aux->dst_prog &&
+ (tgt_prog_fd || tr != prog->aux->dst_trampoline))
+ /* got extra prog ref from syscall, or attaching to different prog */
+ bpf_prog_put(prog->aux->dst_prog);
+ if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline)
+ /* we allocated a new trampoline, so free the old one */
+ bpf_trampoline_put(prog->aux->dst_trampoline);
+
prog->aux->dst_prog = NULL;
prog->aux->dst_trampoline = NULL;
mutex_unlock(&prog->aux->dst_mutex);
return bpf_link_settle(&link_primer);
out_unlock:
+ if (tr && tr != prog->aux->dst_trampoline)
+ bpf_trampoline_put(tr);
mutex_unlock(&prog->aux->dst_mutex);
kfree(link);
out_put_prog:
+ if (tgt_prog_fd && tgt_prog)
+ bpf_prog_put(tgt_prog);
bpf_prog_put(prog);
return err;
}
@@ -2742,7 +2830,7 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr)
tp_name = prog->aux->attach_func_name;
break;
}
- return bpf_tracing_prog_attach(prog);
+ return bpf_tracing_prog_attach(prog, 0, 0);
case BPF_PROG_TYPE_RAW_TRACEPOINT:
case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
if (strncpy_from_user(buf,
@@ -3926,10 +4014,15 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
static int tracing_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
{
- if (attr->link_create.attach_type == BPF_TRACE_ITER &&
- prog->expected_attach_type == BPF_TRACE_ITER)
- return bpf_iter_link_attach(attr, prog);
+ if (attr->link_create.attach_type != prog->expected_attach_type)
+ return -EINVAL;
+ if (prog->expected_attach_type == BPF_TRACE_ITER)
+ return bpf_iter_link_attach(attr, prog);
+ else if (prog->type == BPF_PROG_TYPE_EXT)
+ return bpf_tracing_prog_attach(prog,
+ attr->link_create.target_fd,
+ attr->link_create.target_btf_id);
return -EINVAL;
}
@@ -3943,18 +4036,25 @@ static int link_create(union bpf_attr *attr)
if (CHECK_ATTR(BPF_LINK_CREATE))
return -EINVAL;
- ptype = attach_type_to_prog_type(attr->link_create.attach_type);
- if (ptype == BPF_PROG_TYPE_UNSPEC)
- return -EINVAL;
-
- prog = bpf_prog_get_type(attr->link_create.prog_fd, ptype);
+ prog = bpf_prog_get(attr->link_create.prog_fd);
if (IS_ERR(prog))
return PTR_ERR(prog);
ret = bpf_prog_attach_check_attach_type(prog,
attr->link_create.attach_type);
if (ret)
- goto err_out;
+ goto out;
+
+ if (prog->type == BPF_PROG_TYPE_EXT) {
+ ret = tracing_bpf_link_attach(attr, prog);
+ goto out;
+ }
+
+ ptype = attach_type_to_prog_type(attr->link_create.attach_type);
+ if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) {
+ ret = -EINVAL;
+ goto out;
+ }
switch (ptype) {
case BPF_PROG_TYPE_CGROUP_SKB:
@@ -3982,7 +4082,7 @@ static int link_create(union bpf_attr *attr)
ret = -EINVAL;
}
-err_out:
+out:
if (ret < 0)
bpf_prog_put(prog);
return ret;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 8fe93c84df90..aa1b725706da 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -11374,6 +11374,12 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
if (!btf_type_is_func_proto(t))
return -EINVAL;
+ if ((prog->aux->saved_dst_prog_type &&
+ prog->aux->saved_dst_prog_type != dst_prog->type) ||
+ (prog->aux->saved_dst_attach_type &&
+ prog->aux->saved_dst_attach_type != dst_prog->expected_attach_type))
+ return -EINVAL;
+
if (dst_prog && conservative)
t = NULL;
@@ -11482,6 +11488,11 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
prog->aux->attach_func_proto = tgt_info.tgt_type;
prog->aux->attach_func_name = tgt_info.tgt_name;
+ if (dst_prog) {
+ prog->aux->saved_dst_prog_type = dst_prog->type;
+ prog->aux->saved_dst_attach_type = dst_prog->expected_attach_type;
+ }
+
if (prog->expected_attach_type == BPF_TRACE_RAW_TP) {
prog->aux->attach_btf_trace = true;
return 0;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index a22812561064..feff1ed49f86 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -632,8 +632,13 @@ union bpf_attr {
};
__u32 attach_type; /* attach type */
__u32 flags; /* extra flags */
- __aligned_u64 iter_info; /* extra bpf_iter_link_info */
- __u32 iter_info_len; /* iter_info length */
+ union {
+ __u32 target_btf_id; /* btf_id of target to attach to */
+ struct {
+ __aligned_u64 iter_info; /* extra bpf_iter_link_info */
+ __u32 iter_info_len; /* iter_info length */
+ };
+ };
} link_create;
struct { /* struct used by BPF_LINK_UPDATE command */
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points
2020-09-25 21:25 ` [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points Toke Høiland-Jørgensen
@ 2020-09-29 7:07 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2020-09-29 7:07 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 21364 bytes --]
Hi Toke,
url: https://github.com/0day-ci/linux/commits/Toke-H-iland-J-rgensen/bpf-Support-multi-attach-for-freplace-programs/20200926-052738
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: x86_64-randconfig-m001-20200925 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
kernel/bpf/verifier.c:11378 bpf_check_attach_target() error: we previously assumed 'dst_prog' could be null (see line 11250)
vim +/dst_prog +11378 kernel/bpf/verifier.c
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11215 int bpf_check_attach_target(struct bpf_verifier_log *log,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11216 const struct bpf_prog *prog,
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11217 const struct bpf_prog *dst_prog,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11218 u32 btf_id,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11219 struct bpf_attach_target_info *tgt_info)
38207291604401 Martin KaFai Lau 2019-10-24 11220 {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11221 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11222 const char prefix[] = "btf_trace_";
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11223 int ret = 0, subprog = -1, i;
38207291604401 Martin KaFai Lau 2019-10-24 11224 const struct btf_type *t;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11225 bool conservative = true;
38207291604401 Martin KaFai Lau 2019-10-24 11226 const char *tname;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11227 struct btf *btf;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11228 long addr = 0;
38207291604401 Martin KaFai Lau 2019-10-24 11229
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11230 if (!btf_id) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11231 bpf_log(log, "Tracing programs must provide btf_id\n");
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11232 return -EINVAL;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11233 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11234 btf = dst_prog ? dst_prog->aux->btf : btf_vmlinux;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11235 if (!btf) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11236 bpf_log(log,
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11237 "FENTRY/FEXIT program can only be attached to another program annotated with BTF\n");
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11238 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11239 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11240 t = btf_type_by_id(btf, btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11241 if (!t) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11242 bpf_log(log, "attach_btf_id %u is invalid\n", btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11243 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11244 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11245 tname = btf_name_by_offset(btf, t->name_off);
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11246 if (!tname) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11247 bpf_log(log, "attach_btf_id %u doesn't have a name\n", btf_id);
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11248 return -EINVAL;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11249 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 @11250 if (dst_prog) {
Check for NULL.
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11251 struct bpf_prog_aux *aux = dst_prog->aux;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11252
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11253 for (i = 0; i < aux->func_info_cnt; i++)
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11254 if (aux->func_info[i].type_id == btf_id) {
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11255 subprog = i;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11256 break;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11257 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11258 if (subprog == -1) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11259 bpf_log(log, "Subprog %s doesn't exist\n", tname);
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11260 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11261 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11262 conservative = aux->func_info_aux[subprog].unreliable;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11263 if (prog_extension) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11264 if (conservative) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11265 bpf_log(log,
be8704ff07d237 Alexei Starovoitov 2020-01-20 11266 "Cannot replace static functions\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11267 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11268 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11269 if (!prog->jit_requested) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11270 bpf_log(log,
be8704ff07d237 Alexei Starovoitov 2020-01-20 11271 "Extension programs should be JITed\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11272 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11273 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11274 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11275 if (!dst_prog->jited) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11276 bpf_log(log, "Can attach to only JITed progs\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11277 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11278 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11279 if (dst_prog->type == prog->type) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11280 /* Cannot fentry/fexit another fentry/fexit program.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11281 * Cannot attach program extension to another extension.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11282 * It's ok to attach fentry/fexit to extension program.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11283 */
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11284 bpf_log(log, "Cannot recursively attach\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11285 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11286 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11287 if (dst_prog->type == BPF_PROG_TYPE_TRACING &&
be8704ff07d237 Alexei Starovoitov 2020-01-20 11288 prog_extension &&
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11289 (dst_prog->expected_attach_type == BPF_TRACE_FENTRY ||
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11290 dst_prog->expected_attach_type == BPF_TRACE_FEXIT)) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11291 /* Program extensions can extend all program types
be8704ff07d237 Alexei Starovoitov 2020-01-20 11292 * except fentry/fexit. The reason is the following.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11293 * The fentry/fexit programs are used for performance
be8704ff07d237 Alexei Starovoitov 2020-01-20 11294 * analysis, stats and can be attached to any program
be8704ff07d237 Alexei Starovoitov 2020-01-20 11295 * type except themselves. When extension program is
be8704ff07d237 Alexei Starovoitov 2020-01-20 11296 * replacing XDP function it is necessary to allow
be8704ff07d237 Alexei Starovoitov 2020-01-20 11297 * performance analysis of all functions. Both original
be8704ff07d237 Alexei Starovoitov 2020-01-20 11298 * XDP program and its program extension. Hence
be8704ff07d237 Alexei Starovoitov 2020-01-20 11299 * attaching fentry/fexit to BPF_PROG_TYPE_EXT is
be8704ff07d237 Alexei Starovoitov 2020-01-20 11300 * allowed. If extending of fentry/fexit was allowed it
be8704ff07d237 Alexei Starovoitov 2020-01-20 11301 * would be possible to create long call chain
be8704ff07d237 Alexei Starovoitov 2020-01-20 11302 * fentry->extension->fentry->extension beyond
be8704ff07d237 Alexei Starovoitov 2020-01-20 11303 * reasonable stack size. Hence extending fentry is not
be8704ff07d237 Alexei Starovoitov 2020-01-20 11304 * allowed.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11305 */
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11306 bpf_log(log, "Cannot extend fentry/fexit\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11307 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11308 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11309 } else {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11310 if (prog_extension) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11311 bpf_log(log, "Cannot replace kernel functions\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11312 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11313 }
>From here we know that "dst_prog" can only be NULL when "prog_extension"
is NULL.
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11314 }
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11315
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11316 switch (prog->expected_attach_type) {
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11317 case BPF_TRACE_RAW_TP:
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11318 if (dst_prog) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11319 bpf_log(log,
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11320 "Only FENTRY/FEXIT progs are attachable to another BPF prog\n");
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11321 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11322 }
38207291604401 Martin KaFai Lau 2019-10-24 11323 if (!btf_type_is_typedef(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11324 bpf_log(log, "attach_btf_id %u is not a typedef\n",
38207291604401 Martin KaFai Lau 2019-10-24 11325 btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11326 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11327 }
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11328 if (strncmp(prefix, tname, sizeof(prefix) - 1)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11329 bpf_log(log, "attach_btf_id %u points to wrong type name %s\n",
38207291604401 Martin KaFai Lau 2019-10-24 11330 btf_id, tname);
38207291604401 Martin KaFai Lau 2019-10-24 11331 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11332 }
38207291604401 Martin KaFai Lau 2019-10-24 11333 tname += sizeof(prefix) - 1;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11334 t = btf_type_by_id(btf, t->type);
38207291604401 Martin KaFai Lau 2019-10-24 11335 if (!btf_type_is_ptr(t))
38207291604401 Martin KaFai Lau 2019-10-24 11336 /* should never happen in valid vmlinux build */
38207291604401 Martin KaFai Lau 2019-10-24 11337 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11338 t = btf_type_by_id(btf, t->type);
38207291604401 Martin KaFai Lau 2019-10-24 11339 if (!btf_type_is_func_proto(t))
38207291604401 Martin KaFai Lau 2019-10-24 11340 /* should never happen in valid vmlinux build */
38207291604401 Martin KaFai Lau 2019-10-24 11341 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11342
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11343 break;
15d83c4d7cef5c Yonghong Song 2020-05-09 11344 case BPF_TRACE_ITER:
15d83c4d7cef5c Yonghong Song 2020-05-09 11345 if (!btf_type_is_func(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11346 bpf_log(log, "attach_btf_id %u is not a function\n",
15d83c4d7cef5c Yonghong Song 2020-05-09 11347 btf_id);
15d83c4d7cef5c Yonghong Song 2020-05-09 11348 return -EINVAL;
15d83c4d7cef5c Yonghong Song 2020-05-09 11349 }
15d83c4d7cef5c Yonghong Song 2020-05-09 11350 t = btf_type_by_id(btf, t->type);
15d83c4d7cef5c Yonghong Song 2020-05-09 11351 if (!btf_type_is_func_proto(t))
15d83c4d7cef5c Yonghong Song 2020-05-09 11352 return -EINVAL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11353 ret = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11354 if (ret)
15d83c4d7cef5c Yonghong Song 2020-05-09 11355 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11356 break;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11357 default:
be8704ff07d237 Alexei Starovoitov 2020-01-20 11358 if (!prog_extension)
be8704ff07d237 Alexei Starovoitov 2020-01-20 11359 return -EINVAL;
df561f6688fef7 Gustavo A. R. Silva 2020-08-23 11360 fallthrough;
ae24082331d9bb KP Singh 2020-03-04 11361 case BPF_MODIFY_RETURN:
9e4e01dfd3254c KP Singh 2020-03-29 11362 case BPF_LSM_MAC:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11363 case BPF_TRACE_FENTRY:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11364 case BPF_TRACE_FEXIT:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11365 if (!btf_type_is_func(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11366 bpf_log(log, "attach_btf_id %u is not a function\n",
fec56f5890d93f Alexei Starovoitov 2019-11-14 11367 btf_id);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11368 return -EINVAL;
fec56f5890d93f Alexei Starovoitov 2019-11-14 11369 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11370 if (prog_extension &&
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11371 btf_check_type_match(log, prog, btf, t))
If "prog_extension" can be NULL or non-NULL.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11372 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11373 t = btf_type_by_id(btf, t->type);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11374 if (!btf_type_is_func_proto(t))
fec56f5890d93f Alexei Starovoitov 2019-11-14 11375 return -EINVAL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11376
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11377 if ((prog->aux->saved_dst_prog_type &&
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 @11378 prog->aux->saved_dst_prog_type != dst_prog->type) ||
^^^^^^^^^^^^^^
Unchecked dereference.
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11379 (prog->aux->saved_dst_attach_type &&
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11380 prog->aux->saved_dst_attach_type != dst_prog->expected_attach_type))
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11381 return -EINVAL;
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11382
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11383 if (dst_prog && conservative)
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11384 t = NULL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11385
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11386 ret = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11387 if (ret < 0)
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11388 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11389
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11390 if (dst_prog) {
e9eeec58c992c4 Yonghong Song 2019-12-04 11391 if (subprog == 0)
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11392 addr = (long) dst_prog->bpf_func;
e9eeec58c992c4 Yonghong Song 2019-12-04 11393 else
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11394 addr = (long) dst_prog->aux->func[subprog]->bpf_func;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11395 } else {
fec56f5890d93f Alexei Starovoitov 2019-11-14 11396 addr = kallsyms_lookup_name(tname);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11397 if (!addr) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11398 bpf_log(log,
fec56f5890d93f Alexei Starovoitov 2019-11-14 11399 "The address of function %s cannot be found\n",
fec56f5890d93f Alexei Starovoitov 2019-11-14 11400 tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11401 return -ENOENT;
fec56f5890d93f Alexei Starovoitov 2019-11-14 11402 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11403 }
18644cec714aab Alexei Starovoitov 2020-05-28 11404
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11405 if (prog->aux->sleepable) {
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11406 ret = -EINVAL;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11407 switch (prog->type) {
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11408 case BPF_PROG_TYPE_TRACING:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11409 /* fentry/fexit/fmod_ret progs can be sleepable only if they are
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11410 * attached to ALLOW_ERROR_INJECTION and are not in denylist.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11411 */
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11412 if (!check_non_sleepable_error_inject(btf_id) &&
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11413 within_error_injection_list(addr))
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11414 ret = 0;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11415 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11416 case BPF_PROG_TYPE_LSM:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11417 /* LSM progs check that they are attached to bpf_lsm_*() funcs.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11418 * Only some of them are sleepable.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11419 */
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11420 if (check_sleepable_lsm_hook(btf_id))
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11421 ret = 0;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11422 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11423 default:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11424 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11425 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11426 if (ret) {
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11427 bpf_log(log, "%s is not sleepable\n", tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11428 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11429 }
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11430 } else if (prog->expected_attach_type == BPF_MODIFY_RETURN) {
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11431 if (dst_prog) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11432 bpf_log(log, "can't modify return codes of BPF programs\n");
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11433 return -EINVAL;
81a09cc12e4a91 Toke Høiland-Jørgensen 2020-09-25 11434 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11435 ret = check_attach_modify_return(addr, tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11436 if (ret) {
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11437 bpf_log(log, "%s() is not modifiable\n", tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11438 return ret;
18644cec714aab Alexei Starovoitov 2020-05-28 11439 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11440 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11441
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11442 break;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11443 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11444 tgt_info->tgt_addr = addr;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11445 tgt_info->tgt_name = tname;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11446 tgt_info->tgt_type = t;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11447 return 0;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11448 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30894 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points
@ 2020-09-29 7:07 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2020-09-29 7:07 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 21364 bytes --]
Hi Toke,
url: https://github.com/0day-ci/linux/commits/Toke-H-iland-J-rgensen/bpf-Support-multi-attach-for-freplace-programs/20200926-052738
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: x86_64-randconfig-m001-20200925 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
kernel/bpf/verifier.c:11378 bpf_check_attach_target() error: we previously assumed 'dst_prog' could be null (see line 11250)
vim +/dst_prog +11378 kernel/bpf/verifier.c
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11215 int bpf_check_attach_target(struct bpf_verifier_log *log,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11216 const struct bpf_prog *prog,
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11217 const struct bpf_prog *dst_prog,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11218 u32 btf_id,
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11219 struct bpf_attach_target_info *tgt_info)
38207291604401 Martin KaFai Lau 2019-10-24 11220 {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11221 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11222 const char prefix[] = "btf_trace_";
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11223 int ret = 0, subprog = -1, i;
38207291604401 Martin KaFai Lau 2019-10-24 11224 const struct btf_type *t;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11225 bool conservative = true;
38207291604401 Martin KaFai Lau 2019-10-24 11226 const char *tname;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11227 struct btf *btf;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11228 long addr = 0;
38207291604401 Martin KaFai Lau 2019-10-24 11229
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11230 if (!btf_id) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11231 bpf_log(log, "Tracing programs must provide btf_id\n");
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11232 return -EINVAL;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11233 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11234 btf = dst_prog ? dst_prog->aux->btf : btf_vmlinux;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11235 if (!btf) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11236 bpf_log(log,
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11237 "FENTRY/FEXIT program can only be attached to another program annotated with BTF\n");
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11238 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11239 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11240 t = btf_type_by_id(btf, btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11241 if (!t) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11242 bpf_log(log, "attach_btf_id %u is invalid\n", btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11243 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11244 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11245 tname = btf_name_by_offset(btf, t->name_off);
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11246 if (!tname) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11247 bpf_log(log, "attach_btf_id %u doesn't have a name\n", btf_id);
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11248 return -EINVAL;
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11249 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 @11250 if (dst_prog) {
Check for NULL.
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11251 struct bpf_prog_aux *aux = dst_prog->aux;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11252
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11253 for (i = 0; i < aux->func_info_cnt; i++)
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11254 if (aux->func_info[i].type_id == btf_id) {
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11255 subprog = i;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11256 break;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11257 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11258 if (subprog == -1) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11259 bpf_log(log, "Subprog %s doesn't exist\n", tname);
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11260 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11261 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11262 conservative = aux->func_info_aux[subprog].unreliable;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11263 if (prog_extension) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11264 if (conservative) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11265 bpf_log(log,
be8704ff07d237 Alexei Starovoitov 2020-01-20 11266 "Cannot replace static functions\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11267 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11268 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11269 if (!prog->jit_requested) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11270 bpf_log(log,
be8704ff07d237 Alexei Starovoitov 2020-01-20 11271 "Extension programs should be JITed\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11272 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11273 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11274 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11275 if (!dst_prog->jited) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11276 bpf_log(log, "Can attach to only JITed progs\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11277 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11278 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11279 if (dst_prog->type == prog->type) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11280 /* Cannot fentry/fexit another fentry/fexit program.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11281 * Cannot attach program extension to another extension.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11282 * It's ok to attach fentry/fexit to extension program.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11283 */
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11284 bpf_log(log, "Cannot recursively attach\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11285 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11286 }
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11287 if (dst_prog->type == BPF_PROG_TYPE_TRACING &&
be8704ff07d237 Alexei Starovoitov 2020-01-20 11288 prog_extension &&
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11289 (dst_prog->expected_attach_type == BPF_TRACE_FENTRY ||
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11290 dst_prog->expected_attach_type == BPF_TRACE_FEXIT)) {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11291 /* Program extensions can extend all program types
be8704ff07d237 Alexei Starovoitov 2020-01-20 11292 * except fentry/fexit. The reason is the following.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11293 * The fentry/fexit programs are used for performance
be8704ff07d237 Alexei Starovoitov 2020-01-20 11294 * analysis, stats and can be attached to any program
be8704ff07d237 Alexei Starovoitov 2020-01-20 11295 * type except themselves. When extension program is
be8704ff07d237 Alexei Starovoitov 2020-01-20 11296 * replacing XDP function it is necessary to allow
be8704ff07d237 Alexei Starovoitov 2020-01-20 11297 * performance analysis of all functions. Both original
be8704ff07d237 Alexei Starovoitov 2020-01-20 11298 * XDP program and its program extension. Hence
be8704ff07d237 Alexei Starovoitov 2020-01-20 11299 * attaching fentry/fexit to BPF_PROG_TYPE_EXT is
be8704ff07d237 Alexei Starovoitov 2020-01-20 11300 * allowed. If extending of fentry/fexit was allowed it
be8704ff07d237 Alexei Starovoitov 2020-01-20 11301 * would be possible to create long call chain
be8704ff07d237 Alexei Starovoitov 2020-01-20 11302 * fentry->extension->fentry->extension beyond
be8704ff07d237 Alexei Starovoitov 2020-01-20 11303 * reasonable stack size. Hence extending fentry is not
be8704ff07d237 Alexei Starovoitov 2020-01-20 11304 * allowed.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11305 */
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11306 bpf_log(log, "Cannot extend fentry/fexit\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11307 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11308 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11309 } else {
be8704ff07d237 Alexei Starovoitov 2020-01-20 11310 if (prog_extension) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11311 bpf_log(log, "Cannot replace kernel functions\n");
be8704ff07d237 Alexei Starovoitov 2020-01-20 11312 return -EINVAL;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11313 }
>From here we know that "dst_prog" can only be NULL when "prog_extension"
is NULL.
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11314 }
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11315
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11316 switch (prog->expected_attach_type) {
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11317 case BPF_TRACE_RAW_TP:
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11318 if (dst_prog) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11319 bpf_log(log,
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11320 "Only FENTRY/FEXIT progs are attachable to another BPF prog\n");
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11321 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11322 }
38207291604401 Martin KaFai Lau 2019-10-24 11323 if (!btf_type_is_typedef(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11324 bpf_log(log, "attach_btf_id %u is not a typedef\n",
38207291604401 Martin KaFai Lau 2019-10-24 11325 btf_id);
38207291604401 Martin KaFai Lau 2019-10-24 11326 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11327 }
f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 11328 if (strncmp(prefix, tname, sizeof(prefix) - 1)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11329 bpf_log(log, "attach_btf_id %u points to wrong type name %s\n",
38207291604401 Martin KaFai Lau 2019-10-24 11330 btf_id, tname);
38207291604401 Martin KaFai Lau 2019-10-24 11331 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11332 }
38207291604401 Martin KaFai Lau 2019-10-24 11333 tname += sizeof(prefix) - 1;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11334 t = btf_type_by_id(btf, t->type);
38207291604401 Martin KaFai Lau 2019-10-24 11335 if (!btf_type_is_ptr(t))
38207291604401 Martin KaFai Lau 2019-10-24 11336 /* should never happen in valid vmlinux build */
38207291604401 Martin KaFai Lau 2019-10-24 11337 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11338 t = btf_type_by_id(btf, t->type);
38207291604401 Martin KaFai Lau 2019-10-24 11339 if (!btf_type_is_func_proto(t))
38207291604401 Martin KaFai Lau 2019-10-24 11340 /* should never happen in valid vmlinux build */
38207291604401 Martin KaFai Lau 2019-10-24 11341 return -EINVAL;
38207291604401 Martin KaFai Lau 2019-10-24 11342
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11343 break;
15d83c4d7cef5c Yonghong Song 2020-05-09 11344 case BPF_TRACE_ITER:
15d83c4d7cef5c Yonghong Song 2020-05-09 11345 if (!btf_type_is_func(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11346 bpf_log(log, "attach_btf_id %u is not a function\n",
15d83c4d7cef5c Yonghong Song 2020-05-09 11347 btf_id);
15d83c4d7cef5c Yonghong Song 2020-05-09 11348 return -EINVAL;
15d83c4d7cef5c Yonghong Song 2020-05-09 11349 }
15d83c4d7cef5c Yonghong Song 2020-05-09 11350 t = btf_type_by_id(btf, t->type);
15d83c4d7cef5c Yonghong Song 2020-05-09 11351 if (!btf_type_is_func_proto(t))
15d83c4d7cef5c Yonghong Song 2020-05-09 11352 return -EINVAL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11353 ret = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11354 if (ret)
15d83c4d7cef5c Yonghong Song 2020-05-09 11355 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11356 break;
be8704ff07d237 Alexei Starovoitov 2020-01-20 11357 default:
be8704ff07d237 Alexei Starovoitov 2020-01-20 11358 if (!prog_extension)
be8704ff07d237 Alexei Starovoitov 2020-01-20 11359 return -EINVAL;
df561f6688fef7 Gustavo A. R. Silva 2020-08-23 11360 fallthrough;
ae24082331d9bb KP Singh 2020-03-04 11361 case BPF_MODIFY_RETURN:
9e4e01dfd3254c KP Singh 2020-03-29 11362 case BPF_LSM_MAC:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11363 case BPF_TRACE_FENTRY:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11364 case BPF_TRACE_FEXIT:
fec56f5890d93f Alexei Starovoitov 2019-11-14 11365 if (!btf_type_is_func(t)) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11366 bpf_log(log, "attach_btf_id %u is not a function\n",
fec56f5890d93f Alexei Starovoitov 2019-11-14 11367 btf_id);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11368 return -EINVAL;
fec56f5890d93f Alexei Starovoitov 2019-11-14 11369 }
be8704ff07d237 Alexei Starovoitov 2020-01-20 11370 if (prog_extension &&
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11371 btf_check_type_match(log, prog, btf, t))
If "prog_extension" can be NULL or non-NULL.
be8704ff07d237 Alexei Starovoitov 2020-01-20 11372 return -EINVAL;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11373 t = btf_type_by_id(btf, t->type);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11374 if (!btf_type_is_func_proto(t))
fec56f5890d93f Alexei Starovoitov 2019-11-14 11375 return -EINVAL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11376
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11377 if ((prog->aux->saved_dst_prog_type &&
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 @11378 prog->aux->saved_dst_prog_type != dst_prog->type) ||
^^^^^^^^^^^^^^
Unchecked dereference.
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11379 (prog->aux->saved_dst_attach_type &&
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11380 prog->aux->saved_dst_attach_type != dst_prog->expected_attach_type))
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11381 return -EINVAL;
7c9bfdeec82c49 Toke Høiland-Jørgensen 2020-09-25 11382
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11383 if (dst_prog && conservative)
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11384 t = NULL;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11385
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11386 ret = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11387 if (ret < 0)
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11388 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11389
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11390 if (dst_prog) {
e9eeec58c992c4 Yonghong Song 2019-12-04 11391 if (subprog == 0)
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11392 addr = (long) dst_prog->bpf_func;
e9eeec58c992c4 Yonghong Song 2019-12-04 11393 else
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11394 addr = (long) dst_prog->aux->func[subprog]->bpf_func;
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11395 } else {
fec56f5890d93f Alexei Starovoitov 2019-11-14 11396 addr = kallsyms_lookup_name(tname);
fec56f5890d93f Alexei Starovoitov 2019-11-14 11397 if (!addr) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11398 bpf_log(log,
fec56f5890d93f Alexei Starovoitov 2019-11-14 11399 "The address of function %s cannot be found\n",
fec56f5890d93f Alexei Starovoitov 2019-11-14 11400 tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11401 return -ENOENT;
fec56f5890d93f Alexei Starovoitov 2019-11-14 11402 }
5b92a28aae4dd0 Alexei Starovoitov 2019-11-14 11403 }
18644cec714aab Alexei Starovoitov 2020-05-28 11404
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11405 if (prog->aux->sleepable) {
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11406 ret = -EINVAL;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11407 switch (prog->type) {
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11408 case BPF_PROG_TYPE_TRACING:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11409 /* fentry/fexit/fmod_ret progs can be sleepable only if they are
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11410 * attached to ALLOW_ERROR_INJECTION and are not in denylist.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11411 */
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11412 if (!check_non_sleepable_error_inject(btf_id) &&
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11413 within_error_injection_list(addr))
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11414 ret = 0;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11415 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11416 case BPF_PROG_TYPE_LSM:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11417 /* LSM progs check that they are attached to bpf_lsm_*() funcs.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11418 * Only some of them are sleepable.
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11419 */
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11420 if (check_sleepable_lsm_hook(btf_id))
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11421 ret = 0;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11422 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11423 default:
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11424 break;
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11425 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11426 if (ret) {
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11427 bpf_log(log, "%s is not sleepable\n", tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11428 return ret;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11429 }
1e6c62a8821557 Alexei Starovoitov 2020-08-27 11430 } else if (prog->expected_attach_type == BPF_MODIFY_RETURN) {
0f8a745b60efb2 Toke Høiland-Jørgensen 2020-09-25 11431 if (dst_prog) {
afd82d19795ce2 Toke Høiland-Jørgensen 2020-09-25 11432 bpf_log(log, "can't modify return codes of BPF programs\n");
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11433 return -EINVAL;
81a09cc12e4a91 Toke Høiland-Jørgensen 2020-09-25 11434 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11435 ret = check_attach_modify_return(addr, tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11436 if (ret) {
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11437 bpf_log(log, "%s() is not modifiable\n", tname);
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11438 return ret;
18644cec714aab Alexei Starovoitov 2020-05-28 11439 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11440 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11441
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11442 break;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11443 }
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11444 tgt_info->tgt_addr = addr;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11445 tgt_info->tgt_name = tname;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11446 tgt_info->tgt_type = t;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11447 return 0;
f96b5387a45625 Toke Høiland-Jørgensen 2020-09-25 11448 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30894 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-29 7:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-26 2:59 [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2020-09-25 21:24 [PATCH bpf-next v9 00/11] bpf: Support multi-attach for freplace programs Toke Høiland-Jørgensen
2020-09-25 21:25 ` [PATCH bpf-next v9 05/11] bpf: support attaching freplace programs to multiple attach points Toke Høiland-Jørgensen
2020-09-29 7:07 ` Dan Carpenter
2020-09-29 7:07 ` Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.