1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 3 /* 4 * common eBPF ELF operations. 5 * 6 * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org> 7 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com> 8 * Copyright (C) 2015 Huawei Inc. 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; 13 * version 2.1 of the License (not later!) 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this program; if not, see <http://www.gnu.org/licenses> 22 */ 23 24 #include <stdlib.h> 25 #include <string.h> 26 #include <memory.h> 27 #include <unistd.h> 28 #include <asm/unistd.h> 29 #include <linux/bpf.h> 30 #include "bpf.h" 31 #include "libbpf.h" 32 #include <errno.h> 33 34 /* 35 * When building perf, unistd.h is overridden. __NR_bpf is 36 * required to be defined explicitly. 37 */ 38 #ifndef __NR_bpf 39 # if defined(__i386__) 40 # define __NR_bpf 357 41 # elif defined(__x86_64__) 42 # define __NR_bpf 321 43 # elif defined(__aarch64__) 44 # define __NR_bpf 280 45 # elif defined(__sparc__) 46 # define __NR_bpf 349 47 # elif defined(__s390__) 48 # define __NR_bpf 351 49 # else 50 # error __NR_bpf not defined. libbpf does not support your arch. 51 # endif 52 #endif 53 54 #ifndef min 55 #define min(x, y) ((x) < (y) ? (x) : (y)) 56 #endif 57 58 static inline __u64 ptr_to_u64(const void *ptr) 59 { 60 return (__u64) (unsigned long) ptr; 61 } 62 63 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, 64 unsigned int size) 65 { 66 return syscall(__NR_bpf, cmd, attr, size); 67 } 68 69 static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size) 70 { 71 int fd; 72 73 do { 74 fd = sys_bpf(BPF_PROG_LOAD, attr, size); 75 } while (fd < 0 && errno == EAGAIN); 76 77 return fd; 78 } 79 80 int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) 81 { 82 union bpf_attr attr; 83 84 memset(&attr, '\0', sizeof(attr)); 85 86 attr.map_type = create_attr->map_type; 87 attr.key_size = create_attr->key_size; 88 attr.value_size = create_attr->value_size; 89 attr.max_entries = create_attr->max_entries; 90 attr.map_flags = create_attr->map_flags; 91 if (create_attr->name) 92 memcpy(attr.map_name, create_attr->name, 93 min(strlen(create_attr->name), BPF_OBJ_NAME_LEN - 1)); 94 attr.numa_node = create_attr->numa_node; 95 attr.btf_fd = create_attr->btf_fd; 96 attr.btf_key_type_id = create_attr->btf_key_type_id; 97 attr.btf_value_type_id = create_attr->btf_value_type_id; 98 attr.map_ifindex = create_attr->map_ifindex; 99 attr.inner_map_fd = create_attr->inner_map_fd; 100 101 return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); 102 } 103 104 int bpf_create_map_node(enum bpf_map_type map_type, const char *name, 105 int key_size, int value_size, int max_entries, 106 __u32 map_flags, int node) 107 { 108 struct bpf_create_map_attr map_attr = {}; 109 110 map_attr.name = name; 111 map_attr.map_type = map_type; 112 map_attr.map_flags = map_flags; 113 map_attr.key_size = key_size; 114 map_attr.value_size = value_size; 115 map_attr.max_entries = max_entries; 116 if (node >= 0) { 117 map_attr.numa_node = node; 118 map_attr.map_flags |= BPF_F_NUMA_NODE; 119 } 120 121 return bpf_create_map_xattr(&map_attr); 122 } 123 124 int bpf_create_map(enum bpf_map_type map_type, int key_size, 125 int value_size, int max_entries, __u32 map_flags) 126 { 127 struct bpf_create_map_attr map_attr = {}; 128 129 map_attr.map_type = map_type; 130 map_attr.map_flags = map_flags; 131 map_attr.key_size = key_size; 132 map_attr.value_size = value_size; 133 map_attr.max_entries = max_entries; 134 135 return bpf_create_map_xattr(&map_attr); 136 } 137 138 int bpf_create_map_name(enum bpf_map_type map_type, const char *name, 139 int key_size, int value_size, int max_entries, 140 __u32 map_flags) 141 { 142 struct bpf_create_map_attr map_attr = {}; 143 144 map_attr.name = name; 145 map_attr.map_type = map_type; 146 map_attr.map_flags = map_flags; 147 map_attr.key_size = key_size; 148 map_attr.value_size = value_size; 149 map_attr.max_entries = max_entries; 150 151 return bpf_create_map_xattr(&map_attr); 152 } 153 154 int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name, 155 int key_size, int inner_map_fd, int max_entries, 156 __u32 map_flags, int node) 157 { 158 union bpf_attr attr; 159 160 memset(&attr, '\0', sizeof(attr)); 161 162 attr.map_type = map_type; 163 attr.key_size = key_size; 164 attr.value_size = 4; 165 attr.inner_map_fd = inner_map_fd; 166 attr.max_entries = max_entries; 167 attr.map_flags = map_flags; 168 if (name) 169 memcpy(attr.map_name, name, 170 min(strlen(name), BPF_OBJ_NAME_LEN - 1)); 171 172 if (node >= 0) { 173 attr.map_flags |= BPF_F_NUMA_NODE; 174 attr.numa_node = node; 175 } 176 177 return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); 178 } 179 180 int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name, 181 int key_size, int inner_map_fd, int max_entries, 182 __u32 map_flags) 183 { 184 return bpf_create_map_in_map_node(map_type, name, key_size, 185 inner_map_fd, max_entries, map_flags, 186 -1); 187 } 188 189 static void * 190 alloc_zero_tailing_info(const void *orecord, __u32 cnt, 191 __u32 actual_rec_size, __u32 expected_rec_size) 192 { 193 __u64 info_len = actual_rec_size * cnt; 194 void *info, *nrecord; 195 int i; 196 197 info = malloc(info_len); 198 if (!info) 199 return NULL; 200 201 /* zero out bytes kernel does not understand */ 202 nrecord = info; 203 for (i = 0; i < cnt; i++) { 204 memcpy(nrecord, orecord, expected_rec_size); 205 memset(nrecord + expected_rec_size, 0, 206 actual_rec_size - expected_rec_size); 207 orecord += actual_rec_size; 208 nrecord += actual_rec_size; 209 } 210 211 return info; 212 } 213 214 int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, 215 char *log_buf, size_t log_buf_sz) 216 { 217 void *finfo = NULL, *linfo = NULL; 218 union bpf_attr attr; 219 __u32 log_level; 220 int fd; 221 222 if (!load_attr || !log_buf != !log_buf_sz) 223 return -EINVAL; 224 225 log_level = load_attr->log_level; 226 if (log_level > (4 | 2 | 1) || (log_level && !log_buf)) 227 return -EINVAL; 228 229 memset(&attr, 0, sizeof(attr)); 230 attr.prog_type = load_attr->prog_type; 231 attr.expected_attach_type = load_attr->expected_attach_type; 232 attr.insn_cnt = (__u32)load_attr->insns_cnt; 233 attr.insns = ptr_to_u64(load_attr->insns); 234 attr.license = ptr_to_u64(load_attr->license); 235 236 attr.log_level = log_level; 237 if (log_level) { 238 attr.log_buf = ptr_to_u64(log_buf); 239 attr.log_size = log_buf_sz; 240 } else { 241 attr.log_buf = ptr_to_u64(NULL); 242 attr.log_size = 0; 243 } 244 245 attr.kern_version = load_attr->kern_version; 246 attr.prog_ifindex = load_attr->prog_ifindex; 247 attr.prog_btf_fd = load_attr->prog_btf_fd; 248 attr.func_info_rec_size = load_attr->func_info_rec_size; 249 attr.func_info_cnt = load_attr->func_info_cnt; 250 attr.func_info = ptr_to_u64(load_attr->func_info); 251 attr.line_info_rec_size = load_attr->line_info_rec_size; 252 attr.line_info_cnt = load_attr->line_info_cnt; 253 attr.line_info = ptr_to_u64(load_attr->line_info); 254 if (load_attr->name) 255 memcpy(attr.prog_name, load_attr->name, 256 min(strlen(load_attr->name), BPF_OBJ_NAME_LEN - 1)); 257 258 fd = sys_bpf_prog_load(&attr, sizeof(attr)); 259 if (fd >= 0) 260 return fd; 261 262 /* After bpf_prog_load, the kernel may modify certain attributes 263 * to give user space a hint how to deal with loading failure. 264 * Check to see whether we can make some changes and load again. 265 */ 266 while (errno == E2BIG && (!finfo || !linfo)) { 267 if (!finfo && attr.func_info_cnt && 268 attr.func_info_rec_size < load_attr->func_info_rec_size) { 269 /* try with corrected func info records */ 270 finfo = alloc_zero_tailing_info(load_attr->func_info, 271 load_attr->func_info_cnt, 272 load_attr->func_info_rec_size, 273 attr.func_info_rec_size); 274 if (!finfo) 275 goto done; 276 277 attr.func_info = ptr_to_u64(finfo); 278 attr.func_info_rec_size = load_attr->func_info_rec_size; 279 } else if (!linfo && attr.line_info_cnt && 280 attr.line_info_rec_size < 281 load_attr->line_info_rec_size) { 282 linfo = alloc_zero_tailing_info(load_attr->line_info, 283 load_attr->line_info_cnt, 284 load_attr->line_info_rec_size, 285 attr.line_info_rec_size); 286 if (!linfo) 287 goto done; 288 289 attr.line_info = ptr_to_u64(linfo); 290 attr.line_info_rec_size = load_attr->line_info_rec_size; 291 } else { 292 break; 293 } 294 295 fd = sys_bpf_prog_load(&attr, sizeof(attr)); 296 297 if (fd >= 0) 298 goto done; 299 } 300 301 if (log_level || !log_buf) 302 goto done; 303 304 /* Try again with log */ 305 attr.log_buf = ptr_to_u64(log_buf); 306 attr.log_size = log_buf_sz; 307 attr.log_level = 1; 308 log_buf[0] = 0; 309 fd = sys_bpf_prog_load(&attr, sizeof(attr)); 310 done: 311 free(finfo); 312 free(linfo); 313 return fd; 314 } 315 316 int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, 317 size_t insns_cnt, const char *license, 318 __u32 kern_version, char *log_buf, 319 size_t log_buf_sz) 320 { 321 struct bpf_load_program_attr load_attr; 322 323 memset(&load_attr, 0, sizeof(struct bpf_load_program_attr)); 324 load_attr.prog_type = type; 325 load_attr.expected_attach_type = 0; 326 load_attr.name = NULL; 327 load_attr.insns = insns; 328 load_attr.insns_cnt = insns_cnt; 329 load_attr.license = license; 330 load_attr.kern_version = kern_version; 331 332 return bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz); 333 } 334 335 int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, 336 size_t insns_cnt, __u32 prog_flags, const char *license, 337 __u32 kern_version, char *log_buf, size_t log_buf_sz, 338 int log_level) 339 { 340 union bpf_attr attr; 341 342 memset(&attr, 0, sizeof(attr)); 343 attr.prog_type = type; 344 attr.insn_cnt = (__u32)insns_cnt; 345 attr.insns = ptr_to_u64(insns); 346 attr.license = ptr_to_u64(license); 347 attr.log_buf = ptr_to_u64(log_buf); 348 attr.log_size = log_buf_sz; 349 attr.log_level = log_level; 350 log_buf[0] = 0; 351 attr.kern_version = kern_version; 352 attr.prog_flags = prog_flags; 353 354 return sys_bpf_prog_load(&attr, sizeof(attr)); 355 } 356 357 int bpf_map_update_elem(int fd, const void *key, const void *value, 358 __u64 flags) 359 { 360 union bpf_attr attr; 361 362 memset(&attr, 0, sizeof(attr)); 363 attr.map_fd = fd; 364 attr.key = ptr_to_u64(key); 365 attr.value = ptr_to_u64(value); 366 attr.flags = flags; 367 368 return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); 369 } 370 371 int bpf_map_lookup_elem(int fd, const void *key, void *value) 372 { 373 union bpf_attr attr; 374 375 memset(&attr, 0, sizeof(attr)); 376 attr.map_fd = fd; 377 attr.key = ptr_to_u64(key); 378 attr.value = ptr_to_u64(value); 379 380 return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); 381 } 382 383 int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, __u64 flags) 384 { 385 union bpf_attr attr; 386 387 memset(&attr, 0, sizeof(attr)); 388 attr.map_fd = fd; 389 attr.key = ptr_to_u64(key); 390 attr.value = ptr_to_u64(value); 391 attr.flags = flags; 392 393 return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); 394 } 395 396 int bpf_map_lookup_and_delete_elem(int fd, const void *key, void *value) 397 { 398 union bpf_attr attr; 399 400 memset(&attr, 0, sizeof(attr)); 401 attr.map_fd = fd; 402 attr.key = ptr_to_u64(key); 403 attr.value = ptr_to_u64(value); 404 405 return sys_bpf(BPF_MAP_LOOKUP_AND_DELETE_ELEM, &attr, sizeof(attr)); 406 } 407 408 int bpf_map_delete_elem(int fd, const void *key) 409 { 410 union bpf_attr attr; 411 412 memset(&attr, 0, sizeof(attr)); 413 attr.map_fd = fd; 414 attr.key = ptr_to_u64(key); 415 416 return sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); 417 } 418 419 int bpf_map_get_next_key(int fd, const void *key, void *next_key) 420 { 421 union bpf_attr attr; 422 423 memset(&attr, 0, sizeof(attr)); 424 attr.map_fd = fd; 425 attr.key = ptr_to_u64(key); 426 attr.next_key = ptr_to_u64(next_key); 427 428 return sys_bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr)); 429 } 430 431 int bpf_map_freeze(int fd) 432 { 433 union bpf_attr attr; 434 435 memset(&attr, 0, sizeof(attr)); 436 attr.map_fd = fd; 437 438 return sys_bpf(BPF_MAP_FREEZE, &attr, sizeof(attr)); 439 } 440 441 int bpf_obj_pin(int fd, const char *pathname) 442 { 443 union bpf_attr attr; 444 445 memset(&attr, 0, sizeof(attr)); 446 attr.pathname = ptr_to_u64((void *)pathname); 447 attr.bpf_fd = fd; 448 449 return sys_bpf(BPF_OBJ_PIN, &attr, sizeof(attr)); 450 } 451 452 int bpf_obj_get(const char *pathname) 453 { 454 union bpf_attr attr; 455 456 memset(&attr, 0, sizeof(attr)); 457 attr.pathname = ptr_to_u64((void *)pathname); 458 459 return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); 460 } 461 462 int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type, 463 unsigned int flags) 464 { 465 union bpf_attr attr; 466 467 memset(&attr, 0, sizeof(attr)); 468 attr.target_fd = target_fd; 469 attr.attach_bpf_fd = prog_fd; 470 attr.attach_type = type; 471 attr.attach_flags = flags; 472 473 return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); 474 } 475 476 int bpf_prog_detach(int target_fd, enum bpf_attach_type type) 477 { 478 union bpf_attr attr; 479 480 memset(&attr, 0, sizeof(attr)); 481 attr.target_fd = target_fd; 482 attr.attach_type = type; 483 484 return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); 485 } 486 487 int bpf_prog_detach2(int prog_fd, int target_fd, enum bpf_attach_type type) 488 { 489 union bpf_attr attr; 490 491 memset(&attr, 0, sizeof(attr)); 492 attr.target_fd = target_fd; 493 attr.attach_bpf_fd = prog_fd; 494 attr.attach_type = type; 495 496 return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); 497 } 498 499 int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags, 500 __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt) 501 { 502 union bpf_attr attr; 503 int ret; 504 505 memset(&attr, 0, sizeof(attr)); 506 attr.query.target_fd = target_fd; 507 attr.query.attach_type = type; 508 attr.query.query_flags = query_flags; 509 attr.query.prog_cnt = *prog_cnt; 510 attr.query.prog_ids = ptr_to_u64(prog_ids); 511 512 ret = sys_bpf(BPF_PROG_QUERY, &attr, sizeof(attr)); 513 if (attach_flags) 514 *attach_flags = attr.query.attach_flags; 515 *prog_cnt = attr.query.prog_cnt; 516 return ret; 517 } 518 519 int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, 520 void *data_out, __u32 *size_out, __u32 *retval, 521 __u32 *duration) 522 { 523 union bpf_attr attr; 524 int ret; 525 526 memset(&attr, 0, sizeof(attr)); 527 attr.test.prog_fd = prog_fd; 528 attr.test.data_in = ptr_to_u64(data); 529 attr.test.data_out = ptr_to_u64(data_out); 530 attr.test.data_size_in = size; 531 attr.test.repeat = repeat; 532 533 ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); 534 if (size_out) 535 *size_out = attr.test.data_size_out; 536 if (retval) 537 *retval = attr.test.retval; 538 if (duration) 539 *duration = attr.test.duration; 540 return ret; 541 } 542 543 int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr) 544 { 545 union bpf_attr attr; 546 int ret; 547 548 if (!test_attr->data_out && test_attr->data_size_out > 0) 549 return -EINVAL; 550 551 memset(&attr, 0, sizeof(attr)); 552 attr.test.prog_fd = test_attr->prog_fd; 553 attr.test.data_in = ptr_to_u64(test_attr->data_in); 554 attr.test.data_out = ptr_to_u64(test_attr->data_out); 555 attr.test.data_size_in = test_attr->data_size_in; 556 attr.test.data_size_out = test_attr->data_size_out; 557 attr.test.ctx_in = ptr_to_u64(test_attr->ctx_in); 558 attr.test.ctx_out = ptr_to_u64(test_attr->ctx_out); 559 attr.test.ctx_size_in = test_attr->ctx_size_in; 560 attr.test.ctx_size_out = test_attr->ctx_size_out; 561 attr.test.repeat = test_attr->repeat; 562 563 ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); 564 test_attr->data_size_out = attr.test.data_size_out; 565 test_attr->ctx_size_out = attr.test.ctx_size_out; 566 test_attr->retval = attr.test.retval; 567 test_attr->duration = attr.test.duration; 568 return ret; 569 } 570 571 int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) 572 { 573 union bpf_attr attr; 574 int err; 575 576 memset(&attr, 0, sizeof(attr)); 577 attr.start_id = start_id; 578 579 err = sys_bpf(BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr)); 580 if (!err) 581 *next_id = attr.next_id; 582 583 return err; 584 } 585 586 int bpf_map_get_next_id(__u32 start_id, __u32 *next_id) 587 { 588 union bpf_attr attr; 589 int err; 590 591 memset(&attr, 0, sizeof(attr)); 592 attr.start_id = start_id; 593 594 err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr)); 595 if (!err) 596 *next_id = attr.next_id; 597 598 return err; 599 } 600 601 int bpf_prog_get_fd_by_id(__u32 id) 602 { 603 union bpf_attr attr; 604 605 memset(&attr, 0, sizeof(attr)); 606 attr.prog_id = id; 607 608 return sys_bpf(BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr)); 609 } 610 611 int bpf_map_get_fd_by_id(__u32 id) 612 { 613 union bpf_attr attr; 614 615 memset(&attr, 0, sizeof(attr)); 616 attr.map_id = id; 617 618 return sys_bpf(BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr)); 619 } 620 621 int bpf_btf_get_fd_by_id(__u32 id) 622 { 623 union bpf_attr attr; 624 625 memset(&attr, 0, sizeof(attr)); 626 attr.btf_id = id; 627 628 return sys_bpf(BPF_BTF_GET_FD_BY_ID, &attr, sizeof(attr)); 629 } 630 631 int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len) 632 { 633 union bpf_attr attr; 634 int err; 635 636 memset(&attr, 0, sizeof(attr)); 637 attr.info.bpf_fd = prog_fd; 638 attr.info.info_len = *info_len; 639 attr.info.info = ptr_to_u64(info); 640 641 err = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)); 642 if (!err) 643 *info_len = attr.info.info_len; 644 645 return err; 646 } 647 648 int bpf_raw_tracepoint_open(const char *name, int prog_fd) 649 { 650 union bpf_attr attr; 651 652 memset(&attr, 0, sizeof(attr)); 653 attr.raw_tracepoint.name = ptr_to_u64(name); 654 attr.raw_tracepoint.prog_fd = prog_fd; 655 656 return sys_bpf(BPF_RAW_TRACEPOINT_OPEN, &attr, sizeof(attr)); 657 } 658 659 int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, 660 bool do_log) 661 { 662 union bpf_attr attr = {}; 663 int fd; 664 665 attr.btf = ptr_to_u64(btf); 666 attr.btf_size = btf_size; 667 668 retry: 669 if (do_log && log_buf && log_buf_size) { 670 attr.btf_log_level = 1; 671 attr.btf_log_size = log_buf_size; 672 attr.btf_log_buf = ptr_to_u64(log_buf); 673 } 674 675 fd = sys_bpf(BPF_BTF_LOAD, &attr, sizeof(attr)); 676 if (fd == -1 && !do_log && log_buf && log_buf_size) { 677 do_log = true; 678 goto retry; 679 } 680 681 return fd; 682 } 683 684 int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, 685 __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, 686 __u64 *probe_addr) 687 { 688 union bpf_attr attr = {}; 689 int err; 690 691 attr.task_fd_query.pid = pid; 692 attr.task_fd_query.fd = fd; 693 attr.task_fd_query.flags = flags; 694 attr.task_fd_query.buf = ptr_to_u64(buf); 695 attr.task_fd_query.buf_len = *buf_len; 696 697 err = sys_bpf(BPF_TASK_FD_QUERY, &attr, sizeof(attr)); 698 *buf_len = attr.task_fd_query.buf_len; 699 *prog_id = attr.task_fd_query.prog_id; 700 *fd_type = attr.task_fd_query.fd_type; 701 *probe_offset = attr.task_fd_query.probe_offset; 702 *probe_addr = attr.task_fd_query.probe_addr; 703 704 return err; 705 } 706