cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

task_fd_query_rawtp.c (2414B)


      1// SPDX-License-Identifier: GPL-2.0
      2#include <test_progs.h>
      3
      4void test_task_fd_query_rawtp(void)
      5{
      6	const char *file = "./test_get_stack_rawtp.o";
      7	__u64 probe_offset, probe_addr;
      8	__u32 len, prog_id, fd_type;
      9	struct bpf_object *obj;
     10	int efd, err, prog_fd;
     11	__u32 duration = 0;
     12	char buf[256];
     13
     14	err = bpf_prog_test_load(file, BPF_PROG_TYPE_RAW_TRACEPOINT, &obj, &prog_fd);
     15	if (CHECK(err, "prog_load raw tp", "err %d errno %d\n", err, errno))
     16		return;
     17
     18	efd = bpf_raw_tracepoint_open("sys_enter", prog_fd);
     19	if (CHECK(efd < 0, "raw_tp_open", "err %d errno %d\n", efd, errno))
     20		goto close_prog;
     21
     22	/* query (getpid(), efd) */
     23	len = sizeof(buf);
     24	err = bpf_task_fd_query(getpid(), efd, 0, buf, &len, &prog_id,
     25				&fd_type, &probe_offset, &probe_addr);
     26	if (CHECK(err < 0, "bpf_task_fd_query", "err %d errno %d\n", err,
     27		  errno))
     28		goto close_prog;
     29
     30	err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
     31	      strcmp(buf, "sys_enter") == 0;
     32	if (CHECK(!err, "check_results", "fd_type %d tp_name %s\n",
     33		  fd_type, buf))
     34		goto close_prog;
     35
     36	/* test zero len */
     37	len = 0;
     38	err = bpf_task_fd_query(getpid(), efd, 0, buf, &len, &prog_id,
     39				&fd_type, &probe_offset, &probe_addr);
     40	if (CHECK(err < 0, "bpf_task_fd_query (len = 0)", "err %d errno %d\n",
     41		  err, errno))
     42		goto close_prog;
     43	err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
     44	      len == strlen("sys_enter");
     45	if (CHECK(!err, "check_results", "fd_type %d len %u\n", fd_type, len))
     46		goto close_prog;
     47
     48	/* test empty buffer */
     49	len = sizeof(buf);
     50	err = bpf_task_fd_query(getpid(), efd, 0, 0, &len, &prog_id,
     51				&fd_type, &probe_offset, &probe_addr);
     52	if (CHECK(err < 0, "bpf_task_fd_query (buf = 0)", "err %d errno %d\n",
     53		  err, errno))
     54		goto close_prog;
     55	err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
     56	      len == strlen("sys_enter");
     57	if (CHECK(!err, "check_results", "fd_type %d len %u\n", fd_type, len))
     58		goto close_prog;
     59
     60	/* test smaller buffer */
     61	len = 3;
     62	err = bpf_task_fd_query(getpid(), efd, 0, buf, &len, &prog_id,
     63				&fd_type, &probe_offset, &probe_addr);
     64	if (CHECK(err >= 0 || errno != ENOSPC, "bpf_task_fd_query (len = 3)",
     65		  "err %d errno %d\n", err, errno))
     66		goto close_prog;
     67	err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
     68	      len == strlen("sys_enter") &&
     69	      strcmp(buf, "sy") == 0;
     70	if (CHECK(!err, "check_results", "fd_type %d len %u\n", fd_type, len))
     71		goto close_prog;
     72
     73close_prog:
     74	bpf_object__close(obj);
     75}