xref: /openbmc/linux/tools/testing/selftests/bpf/progs/verifier_d_path.c (revision 16f6ccde74a6f8538c62f127f17207c75f4dba7a)
160802802SEduard Zingerman // SPDX-License-Identifier: GPL-2.0
260802802SEduard Zingerman /* Converted from tools/testing/selftests/bpf/verifier/d_path.c */
360802802SEduard Zingerman 
460802802SEduard Zingerman #include <linux/bpf.h>
560802802SEduard Zingerman #include <bpf/bpf_helpers.h>
660802802SEduard Zingerman #include "bpf_misc.h"
760802802SEduard Zingerman 
860802802SEduard Zingerman SEC("fentry/dentry_open")
960802802SEduard Zingerman __description("d_path accept")
1060802802SEduard Zingerman __success __retval(0)
d_path_accept(void)1160802802SEduard Zingerman __naked void d_path_accept(void)
1260802802SEduard Zingerman {
1360802802SEduard Zingerman 	asm volatile ("					\
14*c7e1962aSKumar Kartikeya Dwivedi 	r1 = *(u64 *)(r1 + 0);				\
1560802802SEduard Zingerman 	r2 = r10;					\
1660802802SEduard Zingerman 	r2 += -8;					\
1760802802SEduard Zingerman 	r6 = 0;						\
1860802802SEduard Zingerman 	*(u64*)(r2 + 0) = r6;				\
1960802802SEduard Zingerman 	r3 = 8 ll;					\
2060802802SEduard Zingerman 	call %[bpf_d_path];				\
2160802802SEduard Zingerman 	r0 = 0;						\
2260802802SEduard Zingerman 	exit;						\
2360802802SEduard Zingerman "	:
2460802802SEduard Zingerman 	: __imm(bpf_d_path)
2560802802SEduard Zingerman 	: __clobber_all);
2660802802SEduard Zingerman }
2760802802SEduard Zingerman 
2860802802SEduard Zingerman SEC("fentry/d_path")
2960802802SEduard Zingerman __description("d_path reject")
3060802802SEduard Zingerman __failure __msg("helper call is not allowed in probe")
d_path_reject(void)3160802802SEduard Zingerman __naked void d_path_reject(void)
3260802802SEduard Zingerman {
3360802802SEduard Zingerman 	asm volatile ("					\
34*c7e1962aSKumar Kartikeya Dwivedi 	r1 = *(u64 *)(r1 + 0);				\
3560802802SEduard Zingerman 	r2 = r10;					\
3660802802SEduard Zingerman 	r2 += -8;					\
3760802802SEduard Zingerman 	r6 = 0;						\
3860802802SEduard Zingerman 	*(u64*)(r2 + 0) = r6;				\
3960802802SEduard Zingerman 	r3 = 8 ll;					\
4060802802SEduard Zingerman 	call %[bpf_d_path];				\
4160802802SEduard Zingerman 	r0 = 0;						\
4260802802SEduard Zingerman 	exit;						\
4360802802SEduard Zingerman "	:
4460802802SEduard Zingerman 	: __imm(bpf_d_path)
4560802802SEduard Zingerman 	: __clobber_all);
4660802802SEduard Zingerman }
4760802802SEduard Zingerman 
4860802802SEduard Zingerman char _license[] SEC("license") = "GPL";
49