Linux Audio

Check our new training course

Loading...
Note: File does not exist in v6.8.
  1// SPDX-License-Identifier: GPL-2.0
  2
  3#include <linux/bpf.h>
  4#include <bpf/bpf_helpers.h>
  5#include "bpf_misc.h"
  6
  7SEC("lsm/file_alloc_security")
  8__description("lsm bpf prog with -4095~0 retval. test 1")
  9__success
 10__naked int errno_zero_retval_test1(void *ctx)
 11{
 12	asm volatile (
 13	"r0 = 0;"
 14	"exit;"
 15	::: __clobber_all);
 16}
 17
 18SEC("lsm/file_alloc_security")
 19__description("lsm bpf prog with -4095~0 retval. test 2")
 20__success
 21__naked int errno_zero_retval_test2(void *ctx)
 22{
 23	asm volatile (
 24	"r0 = -4095;"
 25	"exit;"
 26	::: __clobber_all);
 27}
 28
 29SEC("lsm/file_mprotect")
 30__description("lsm bpf prog with -4095~0 retval. test 4")
 31__failure __msg("R0 has smin=-4096 smax=-4096 should have been in [-4095, 0]")
 32__naked int errno_zero_retval_test4(void *ctx)
 33{
 34	asm volatile (
 35	"r0 = -4096;"
 36	"exit;"
 37	::: __clobber_all);
 38}
 39
 40SEC("lsm/file_mprotect")
 41__description("lsm bpf prog with -4095~0 retval. test 5")
 42__failure __msg("R0 has smin=4096 smax=4096 should have been in [-4095, 0]")
 43__naked int errno_zero_retval_test5(void *ctx)
 44{
 45	asm volatile (
 46	"r0 = 4096;"
 47	"exit;"
 48	::: __clobber_all);
 49}
 50
 51SEC("lsm/file_mprotect")
 52__description("lsm bpf prog with -4095~0 retval. test 6")
 53__failure __msg("R0 has smin=1 smax=1 should have been in [-4095, 0]")
 54__naked int errno_zero_retval_test6(void *ctx)
 55{
 56	asm volatile (
 57	"r0 = 1;"
 58	"exit;"
 59	::: __clobber_all);
 60}
 61
 62SEC("lsm/audit_rule_known")
 63__description("lsm bpf prog with bool retval. test 1")
 64__success
 65__naked int bool_retval_test1(void *ctx)
 66{
 67	asm volatile (
 68	"r0 = 1;"
 69	"exit;"
 70	::: __clobber_all);
 71}
 72
 73SEC("lsm/audit_rule_known")
 74__description("lsm bpf prog with bool retval. test 2")
 75__success
 76__success
 77__naked int bool_retval_test2(void *ctx)
 78{
 79	asm volatile (
 80	"r0 = 0;"
 81	"exit;"
 82	::: __clobber_all);
 83}
 84
 85SEC("lsm/audit_rule_known")
 86__description("lsm bpf prog with bool retval. test 3")
 87__failure __msg("R0 has smin=-1 smax=-1 should have been in [0, 1]")
 88__naked int bool_retval_test3(void *ctx)
 89{
 90	asm volatile (
 91	"r0 = -1;"
 92	"exit;"
 93	::: __clobber_all);
 94}
 95
 96SEC("lsm/audit_rule_known")
 97__description("lsm bpf prog with bool retval. test 4")
 98__failure __msg("R0 has smin=2 smax=2 should have been in [0, 1]")
 99__naked int bool_retval_test4(void *ctx)
100{
101	asm volatile (
102	"r0 = 2;"
103	"exit;"
104	::: __clobber_all);
105}
106
107SEC("lsm/file_free_security")
108__success
109__description("lsm bpf prog with void retval. test 1")
110__naked int void_retval_test1(void *ctx)
111{
112	asm volatile (
113	"r0 = -4096;"
114	"exit;"
115	::: __clobber_all);
116}
117
118SEC("lsm/file_free_security")
119__success
120__description("lsm bpf prog with void retval. test 2")
121__naked int void_retval_test2(void *ctx)
122{
123	asm volatile (
124	"r0 = 4096;"
125	"exit;"
126	::: __clobber_all);
127}
128
129SEC("lsm/getprocattr")
130__description("lsm disabled hook: getprocattr")
131__failure __msg("points to disabled hook")
132__naked int disabled_hook_test1(void *ctx)
133{
134	asm volatile (
135	"r0 = 0;"
136	"exit;"
137	::: __clobber_all);
138}
139
140SEC("lsm/setprocattr")
141__description("lsm disabled hook: setprocattr")
142__failure __msg("points to disabled hook")
143__naked int disabled_hook_test2(void *ctx)
144{
145	asm volatile (
146	"r0 = 0;"
147	"exit;"
148	::: __clobber_all);
149}
150
151SEC("lsm/ismaclabel")
152__description("lsm disabled hook: ismaclabel")
153__failure __msg("points to disabled hook")
154__naked int disabled_hook_test3(void *ctx)
155{
156	asm volatile (
157	"r0 = 0;"
158	"exit;"
159	::: __clobber_all);
160}
161
162char _license[] SEC("license") = "GPL";