Re: [PATCH bpf-next v8 2/2] bpf/selftests: Test fentry attachment to shadowed functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 22, 2023 at 03:35:29PM +0100, Viktor Malik wrote:

SNIP

> +	for (i = 0; i < 2; i++) {
> +		load_opts.attach_btf_id = btf_id[i];
> +		load_opts.attach_btf_obj_fd = btf_fd[i];
> +		prog_fd[i] = bpf_prog_load(BPF_PROG_TYPE_TRACING, NULL, "GPL",
> +					   trace_program,
> +					   sizeof(trace_program) / sizeof(struct bpf_insn),
> +					   &load_opts);
> +		if (!ASSERT_GE(prog_fd[i], 0, "bpf_prog_load"))
> +			goto out;
> +
> +		/* If the verifier incorrectly resolves addresses of the
> +		 * shadowed functions and uses the same address for both the
> +		 * vmlinux and the bpf_testmod functions, this will fail on
> +		 * attempting to create two trampolines for the same address,
> +		 * which is forbidden.
> +		 */
> +		link_fd[i] = bpf_link_create(prog_fd[i], 0, BPF_TRACE_FENTRY, NULL);
> +		if (!ASSERT_GE(link_fd[i], 0, "bpf_link_create"))
> +			goto out;
> +	}
> +
> +	err = bpf_prog_test_run_opts(prog_fd[0], NULL);
> +	ASSERT_OK(err, "running test");
> +
> +out:
> +	btf__free(vmlinux_btf);
> +	btf__free(mod_btf);
> +	for (i = 0; i < 2; i++) {
> +		if (btf_fd[i])
> +			close(btf_fd[i]);
> +		if (prog_fd[i])
> +			close(prog_fd[i]);

should we check prog_fd[i] > 0 ? same below

jirka

> +		if (link_fd[i])
> +			close(link_fd[i]);
> +	}
> +}
> -- 
> 2.39.1
> 



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux