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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/verifier/bpf_st_mem.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 {
  2         "BPF_ST_MEM stack imm non-zero",
  3         .insns = {
  4         BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 42),
  5         BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
  6         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, -42),
  7         /* if value is tracked correctly R0 is zero */
  8         BPF_EXIT_INSN(),
  9         },
 10         .result = ACCEPT,
 11         /* Use prog type that requires return value in range [0, 1] */
 12         .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
 13         .expected_attach_type = BPF_SK_LOOKUP,
 14         .runs = -1,
 15 },
 16 {
 17         "BPF_ST_MEM stack imm zero",
 18         .insns = {
 19         /* mark stack 0000 0000 */
 20         BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
 21         /* read and sum a few bytes */
 22         BPF_MOV64_IMM(BPF_REG_0, 0),
 23         BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_10, -8),
 24         BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
 25         BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_10, -4),
 26         BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
 27         BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_10, -1),
 28         BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
 29         /* if value is tracked correctly R0 is zero */
 30         BPF_EXIT_INSN(),
 31         },
 32         .result = ACCEPT,
 33         /* Use prog type that requires return value in range [0, 1] */
 34         .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
 35         .expected_attach_type = BPF_SK_LOOKUP,
 36         .runs = -1,
 37 },
 38 {
 39         "BPF_ST_MEM stack imm zero, variable offset",
 40         .insns = {
 41         /* set fp[-16], fp[-24] to zeros */
 42         BPF_ST_MEM(BPF_DW, BPF_REG_10, -16, 0),
 43         BPF_ST_MEM(BPF_DW, BPF_REG_10, -24, 0),
 44         /* r0 = random value in range [-32, -15] */
 45         BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32),
 46         BPF_JMP_IMM(BPF_JLE, BPF_REG_0, 16, 2),
 47         BPF_MOV64_IMM(BPF_REG_0, 0),
 48         BPF_EXIT_INSN(),
 49         BPF_ALU64_IMM(BPF_SUB, BPF_REG_0, 32),
 50         /* fp[r0] = 0, make a variable offset write of zero,
 51          *             this should preserve zero marks on stack.
 52          */
 53         BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_10),
 54         BPF_ST_MEM(BPF_B, BPF_REG_0, 0, 0),
 55         /* r0 = fp[-20], if variable offset write was tracked correctly
 56          *               r0 would be a known zero.
 57          */
 58         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_10, -20),
 59         /* Would fail return code verification if r0 range is not tracked correctly. */
 60         BPF_EXIT_INSN(),
 61         },
 62         .result = ACCEPT,
 63         /* Use prog type that requires return value in range [0, 1] */
 64         .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
 65         .expected_attach_type = BPF_SK_LOOKUP,
 66         .runs = -1,
 67 },
 68 {
 69         "BPF_ST_MEM stack imm sign",
 70         /* Check if verifier correctly reasons about sign of an
 71          * immediate spilled to stack by BPF_ST instruction.
 72          *
 73          *   fp[-8] = -44;
 74          *   r0 = fp[-8];
 75          *   if r0 s< 0 goto ret0;
 76          *   r0 = -1;
 77          *   exit;
 78          * ret0:
 79          *   r0 = 0;
 80          *   exit;
 81          */
 82         .insns = {
 83         BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, -44),
 84         BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
 85         BPF_JMP_IMM(BPF_JSLT, BPF_REG_0, 0, 2),
 86         BPF_MOV64_IMM(BPF_REG_0, -1),
 87         BPF_EXIT_INSN(),
 88         BPF_MOV64_IMM(BPF_REG_0, 0),
 89         BPF_EXIT_INSN(),
 90         },
 91         /* Use prog type that requires return value in range [0, 1] */
 92         .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
 93         .expected_attach_type = BPF_SK_LOOKUP,
 94         .result = VERBOSE_ACCEPT,
 95         .runs = -1,
 96         .errstr = "0: (7a) *(u64 *)(r10 -8) = -44        ; R10=fp0 fp-8_w=-44\
 97         2: (c5) if r0 s< 0x0 goto pc+2\
 98         R0_w=-44",
 99 },
100 

~ [ 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