~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/exceptions_assert.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <vmlinux.h>
  3 #include <limits.h>
  4 #include <bpf/bpf_tracing.h>
  5 #include <bpf/bpf_helpers.h>
  6 #include <bpf/bpf_core_read.h>
  7 #include <bpf/bpf_endian.h>
  8 #include "bpf_misc.h"
  9 #include "bpf_experimental.h"
 10 
 11 #define check_assert(type, op, name, value)                             \
 12         SEC("?tc")                                                      \
 13         __log_level(2) __failure                                        \
 14         int check_assert_##name(void *ctx)                              \
 15         {                                                               \
 16                 type num = bpf_ktime_get_ns();                          \
 17                 bpf_assert(bpf_cmp_unlikely(num, op, value));           \
 18                 return *(u64 *)num;                                     \
 19         }
 20 
 21 __msg(": R0_w=0xffffffff80000000")
 22 check_assert(s64, ==, eq_int_min, INT_MIN);
 23 __msg(": R0_w=0x7fffffff")
 24 check_assert(s64, ==, eq_int_max, INT_MAX);
 25 __msg(": R0_w=0")
 26 check_assert(s64, ==, eq_zero, 0);
 27 __msg(": R0_w=0x8000000000000000 R1_w=0x8000000000000000")
 28 check_assert(s64, ==, eq_llong_min, LLONG_MIN);
 29 __msg(": R0_w=0x7fffffffffffffff R1_w=0x7fffffffffffffff")
 30 check_assert(s64, ==, eq_llong_max, LLONG_MAX);
 31 
 32 __msg(": R0_w=scalar(id=1,smax=0x7ffffffe)")
 33 check_assert(s64, <, lt_pos, INT_MAX);
 34 __msg(": R0_w=scalar(id=1,smax=-1,umin=0x8000000000000000,var_off=(0x8000000000000000; 0x7fffffffffffffff))")
 35 check_assert(s64, <, lt_zero, 0);
 36 __msg(": R0_w=scalar(id=1,smax=0xffffffff7fffffff")
 37 check_assert(s64, <, lt_neg, INT_MIN);
 38 
 39 __msg(": R0_w=scalar(id=1,smax=0x7fffffff)")
 40 check_assert(s64, <=, le_pos, INT_MAX);
 41 __msg(": R0_w=scalar(id=1,smax=0)")
 42 check_assert(s64, <=, le_zero, 0);
 43 __msg(": R0_w=scalar(id=1,smax=0xffffffff80000000")
 44 check_assert(s64, <=, le_neg, INT_MIN);
 45 
 46 __msg(": R0_w=scalar(id=1,smin=umin=0x80000000,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
 47 check_assert(s64, >, gt_pos, INT_MAX);
 48 __msg(": R0_w=scalar(id=1,smin=umin=1,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
 49 check_assert(s64, >, gt_zero, 0);
 50 __msg(": R0_w=scalar(id=1,smin=0xffffffff80000001")
 51 check_assert(s64, >, gt_neg, INT_MIN);
 52 
 53 __msg(": R0_w=scalar(id=1,smin=umin=0x7fffffff,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
 54 check_assert(s64, >=, ge_pos, INT_MAX);
 55 __msg(": R0_w=scalar(id=1,smin=0,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
 56 check_assert(s64, >=, ge_zero, 0);
 57 __msg(": R0_w=scalar(id=1,smin=0xffffffff80000000")
 58 check_assert(s64, >=, ge_neg, INT_MIN);
 59 
 60 SEC("?tc")
 61 __log_level(2) __failure
 62 __msg(": R0=0 R1=ctx() R2=scalar(smin=0xffffffff80000002,smax=smax32=0x7ffffffd,smin32=0x80000002) R10=fp0")
 63 int check_assert_range_s64(struct __sk_buff *ctx)
 64 {
 65         struct bpf_sock *sk = ctx->sk;
 66         s64 num;
 67 
 68         _Static_assert(_Generic((sk->rx_queue_mapping), s32: 1, default: 0), "type match");
 69         if (!sk)
 70                 return 0;
 71         num = sk->rx_queue_mapping;
 72         bpf_assert_range(num, INT_MIN + 2, INT_MAX - 2);
 73         return *((u8 *)ctx + num);
 74 }
 75 
 76 SEC("?tc")
 77 __log_level(2) __failure
 78 __msg(": R1=ctx() R2=scalar(smin=umin=smin32=umin32=4096,smax=umax=smax32=umax32=8192,var_off=(0x0; 0x3fff))")
 79 int check_assert_range_u64(struct __sk_buff *ctx)
 80 {
 81         u64 num = ctx->len;
 82 
 83         bpf_assert_range(num, 4096, 8192);
 84         return *((u8 *)ctx + num);
 85 }
 86 
 87 SEC("?tc")
 88 __log_level(2) __failure
 89 __msg(": R0=0 R1=ctx() R2=4096 R10=fp0")
 90 int check_assert_single_range_s64(struct __sk_buff *ctx)
 91 {
 92         struct bpf_sock *sk = ctx->sk;
 93         s64 num;
 94 
 95         _Static_assert(_Generic((sk->rx_queue_mapping), s32: 1, default: 0), "type match");
 96         if (!sk)
 97                 return 0;
 98         num = sk->rx_queue_mapping;
 99 
100         bpf_assert_range(num, 4096, 4096);
101         return *((u8 *)ctx + num);
102 }
103 
104 SEC("?tc")
105 __log_level(2) __failure
106 __msg(": R1=ctx() R2=4096 R10=fp0")
107 int check_assert_single_range_u64(struct __sk_buff *ctx)
108 {
109         u64 num = ctx->len;
110 
111         bpf_assert_range(num, 4096, 4096);
112         return *((u8 *)ctx + num);
113 }
114 
115 SEC("?tc")
116 __log_level(2) __failure
117 __msg(": R1=pkt(off=64,r=64) R2=pkt_end() R6=pkt(r=64) R10=fp0")
118 int check_assert_generic(struct __sk_buff *ctx)
119 {
120         u8 *data_end = (void *)(long)ctx->data_end;
121         u8 *data = (void *)(long)ctx->data;
122 
123         bpf_assert(data + 64 <= data_end);
124         return data[128];
125 }
126 
127 SEC("?fentry/bpf_check")
128 __failure __msg("At program exit the register R1 has smin=64 smax=64")
129 int check_assert_with_return(void *ctx)
130 {
131         bpf_assert_with(!ctx, 64);
132         return 0;
133 }
134 
135 char _license[] SEC("license") = "GPL";
136 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php