diff --git a/pkg/bpf/BUILD b/pkg/bpf/BUILD index b1e9ff776..bcd6bb7d6 100644 --- a/pkg/bpf/BUILD +++ b/pkg/bpf/BUILD @@ -14,6 +14,7 @@ go_library( "interpreter.go", "program_builder.go", ], + imports = ["gvisor.dev/gvisor/pkg/abi/linux"], visibility = ["//visibility:public"], deps = ["//pkg/abi/linux"], ) diff --git a/pkg/bpf/bpf.go b/pkg/bpf/bpf.go index 505b24413..8d888fc07 100644 --- a/pkg/bpf/bpf.go +++ b/pkg/bpf/bpf.go @@ -17,7 +17,11 @@ // https://www.freebsd.org/cgi/man.cgi?bpf(4) package bpf -import "gvisor.dev/gvisor/pkg/abi/linux" +import ( + "fmt" + + "gvisor.dev/gvisor/pkg/abi/linux" +) const ( // MaxInstructions is the maximum number of instructions in a BPF program, @@ -110,17 +114,34 @@ const ( retUnusedBitsMask = 0xe0 // returns only use instruction class and source operand ) -// Stmt returns a linux.BPFInstruction representing a BPF non-jump instruction. -func Stmt(code uint16, k uint32) linux.BPFInstruction { - return linux.BPFInstruction{ +// Instruction is a type alias for linux.BPFInstruction. +// It adds a human-readable stringification function. +// +// +marshal slice:InstructionSlice +// +stateify savable +// +stateify identtype +type Instruction linux.BPFInstruction + +// String returns a human-readable version of the instruction. +func (ins *Instruction) String() string { + s, err := Decode(*ins) + if err != nil { + return fmt.Sprintf("[invalid %v: %v]", (*linux.BPFInstruction)(ins), err) + } + return s +} + +// Stmt returns an Instruction representing a BPF non-jump instruction. +func Stmt(code uint16, k uint32) Instruction { + return Instruction{ OpCode: code, K: k, } } -// Jump returns a linux.BPFInstruction representing a BPF jump instruction. -func Jump(code uint16, k uint32, jt, jf uint8) linux.BPFInstruction { - return linux.BPFInstruction{ +// Jump returns an Instruction representing a BPF jump instruction. +func Jump(code uint16, k uint32, jt, jf uint8) Instruction { + return Instruction{ OpCode: code, JumpIfTrue: jt, JumpIfFalse: jf, diff --git a/pkg/bpf/decoder.go b/pkg/bpf/decoder.go index 6d1e65cb1..e3b82b5d1 100644 --- a/pkg/bpf/decoder.go +++ b/pkg/bpf/decoder.go @@ -27,7 +27,7 @@ func DecodeProgram(p Program) (string, error) { } // DecodeInstructions translates an array of BPF instructions into text format. -func DecodeInstructions(instns []linux.BPFInstruction) (string, error) { +func DecodeInstructions(instns []Instruction) (string, error) { var ret bytes.Buffer for line, s := range instns { ret.WriteString(fmt.Sprintf("%v: ", line)) @@ -40,13 +40,13 @@ func DecodeInstructions(instns []linux.BPFInstruction) (string, error) { } // Decode translates a single BPF instruction into text format. -func Decode(inst linux.BPFInstruction) (string, error) { +func Decode(ins Instruction) (string, error) { var ret bytes.Buffer - err := decode(inst, -1, &ret) + err := decode(ins, -1, &ret) return ret.String(), err } -func decode(inst linux.BPFInstruction, line int, w *bytes.Buffer) error { +func decode(inst Instruction, line int, w *bytes.Buffer) error { var err error switch inst.OpCode & instructionClassMask { case Ld: @@ -66,13 +66,13 @@ func decode(inst linux.BPFInstruction, line int, w *bytes.Buffer) error { case Misc: err = decodeMisc(inst, w) default: - return fmt.Errorf("invalid BPF instruction: %v", inst) + return fmt.Errorf("invalid BPF instruction: %v", linux.BPFInstruction(inst)) } return err } // A <- P[k:4] -func decodeLd(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeLd(inst Instruction, w *bytes.Buffer) error { w.WriteString("A <- ") switch inst.OpCode & loadModeMask { @@ -95,12 +95,12 @@ func decodeLd(inst linux.BPFInstruction, w *bytes.Buffer) error { case Len: w.WriteString("len") default: - return fmt.Errorf("invalid BPF LD instruction: %v", inst) + return fmt.Errorf("invalid BPF LD instruction: %v", linux.BPFInstruction(inst)) } return nil } -func decodeLdSize(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeLdSize(inst Instruction, w *bytes.Buffer) error { switch inst.OpCode & loadSizeMask { case W: w.WriteString("4") @@ -109,13 +109,13 @@ func decodeLdSize(inst linux.BPFInstruction, w *bytes.Buffer) error { case B: w.WriteString("1") default: - return fmt.Errorf("invalid BPF LD size: %v", inst) + return fmt.Errorf("invalid BPF LD size: %v", linux.BPFInstruction(inst)) } return nil } // X <- P[k:4] -func decodeLdx(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeLdx(inst Instruction, w *bytes.Buffer) error { w.WriteString("X <- ") switch inst.OpCode & loadModeMask { @@ -128,13 +128,13 @@ func decodeLdx(inst linux.BPFInstruction, w *bytes.Buffer) error { case Msh: w.WriteString(fmt.Sprintf("4*(P[%v:1]&0xf)", inst.K)) default: - return fmt.Errorf("invalid BPF LDX instruction: %v", inst) + return fmt.Errorf("invalid BPF LDX instruction: %v", linux.BPFInstruction(inst)) } return nil } // A <- A + k -func decodeAlu(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeAlu(inst Instruction, w *bytes.Buffer) error { code := inst.OpCode & aluMask if code == Neg { w.WriteString("A <- -A") @@ -164,25 +164,25 @@ func decodeAlu(inst linux.BPFInstruction, w *bytes.Buffer) error { case Xor: w.WriteString("^ ") default: - return fmt.Errorf("invalid BPF ALU instruction: %v", inst) + return fmt.Errorf("invalid BPF ALU instruction: %v", linux.BPFInstruction(inst)) } return decodeSource(inst, w) } -func decodeSource(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeSource(inst Instruction, w *bytes.Buffer) error { switch inst.OpCode & srcAluJmpMask { case K: w.WriteString(fmt.Sprintf("%v", inst.K)) case X: w.WriteString("X") default: - return fmt.Errorf("invalid BPF ALU/JMP source instruction: %v", inst) + return fmt.Errorf("invalid BPF ALU/JMP source instruction: %v", linux.BPFInstruction(inst)) } return nil } // pc += (A > k) ? jt : jf -func decodeJmp(inst linux.BPFInstruction, line int, w *bytes.Buffer) error { +func decodeJmp(inst Instruction, line int, w *bytes.Buffer) error { code := inst.OpCode & jmpMask w.WriteString("pc += ") @@ -200,7 +200,7 @@ func decodeJmp(inst linux.BPFInstruction, line int, w *bytes.Buffer) error { case Jset: w.WriteString("& ") default: - return fmt.Errorf("invalid BPF ALU instruction: %v", inst) + return fmt.Errorf("invalid BPF ALU instruction: %v", linux.BPFInstruction(inst)) } if err := decodeSource(inst, w); err != nil { return err @@ -221,7 +221,7 @@ func printJmpTarget(target uint32, line int) string { } // ret k -func decodeRet(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeRet(inst Instruction, w *bytes.Buffer) error { w.WriteString("ret ") code := inst.OpCode & srcRetMask @@ -231,12 +231,12 @@ func decodeRet(inst linux.BPFInstruction, w *bytes.Buffer) error { case A: w.WriteString("A") default: - return fmt.Errorf("invalid BPF RET source instruction: %v", inst) + return fmt.Errorf("invalid BPF RET source instruction: %v", linux.BPFInstruction(inst)) } return nil } -func decodeMisc(inst linux.BPFInstruction, w *bytes.Buffer) error { +func decodeMisc(inst Instruction, w *bytes.Buffer) error { code := inst.OpCode & miscMask switch code { case Tax: @@ -244,7 +244,7 @@ func decodeMisc(inst linux.BPFInstruction, w *bytes.Buffer) error { case Txa: w.WriteString("A <- X") default: - return fmt.Errorf("invalid BPF ALU/JMP source instruction: %v", inst) + return fmt.Errorf("invalid BPF ALU/JMP source instruction: %v", linux.BPFInstruction(inst)) } return nil } diff --git a/pkg/bpf/decoder_test.go b/pkg/bpf/decoder_test.go index bb971ce21..19e41eb49 100644 --- a/pkg/bpf/decoder_test.go +++ b/pkg/bpf/decoder_test.go @@ -16,13 +16,11 @@ package bpf import ( "testing" - - "gvisor.dev/gvisor/pkg/abi/linux" ) func TestDecode(t *testing.T) { for _, test := range []struct { - filter linux.BPFInstruction + filter Instruction expected string fail bool }{ @@ -96,12 +94,12 @@ func TestDecode(t *testing.T) { func TestDecodeInstructions(t *testing.T) { for _, test := range []struct { name string - program []linux.BPFInstruction + program []Instruction expected string fail bool }{ {name: "basic with jump indexes", - program: []linux.BPFInstruction{ + program: []Instruction{ Stmt(Ld+Abs+W, 10), Stmt(Ldx+Mem, 10), Stmt(St, 10), @@ -123,7 +121,7 @@ func TestDecodeInstructions(t *testing.T) { "8: X <- A\n", }, {name: "invalid instruction", - program: []linux.BPFInstruction{Stmt(Ld+Abs+W, 10), Stmt(Ld+Len+Mem, 0)}, + program: []Instruction{Stmt(Ld+Abs+W, 10), Stmt(Ld+Len+Mem, 0)}, fail: true}, } { got, err := DecodeInstructions(test.program) diff --git a/pkg/bpf/interpreter.go b/pkg/bpf/interpreter.go index c81f2d99f..de06bc694 100644 --- a/pkg/bpf/interpreter.go +++ b/pkg/bpf/interpreter.go @@ -16,8 +16,6 @@ package bpf import ( "fmt" - - "gvisor.dev/gvisor/pkg/abi/linux" ) // Possible values for ProgramError.Code. @@ -91,7 +89,7 @@ func (e Error) Error() string { // // +stateify savable type Program struct { - instructions []linux.BPFInstruction + instructions []Instruction } // Length returns the number of instructions in the program. @@ -101,7 +99,7 @@ func (p Program) Length() int { // Compile performs validation on a sequence of BPF instructions before // wrapping them in a Program. -func Compile(insns []linux.BPFInstruction) (Program, error) { +func Compile(insns []Instruction) (Program, error) { if len(insns) == 0 || len(insns) > MaxInstructions { return Program{}, Error{InvalidInstructionCount, len(insns)} } @@ -255,7 +253,7 @@ type machine struct { M [ScratchMemRegisters]uint32 } -func conditionalJumpOffset(insn linux.BPFInstruction, cond bool) int { +func conditionalJumpOffset(insn Instruction, cond bool) int { if cond { return int(insn.JumpIfTrue) } diff --git a/pkg/bpf/interpreter_test.go b/pkg/bpf/interpreter_test.go index f64a2dc50..8052d2f46 100644 --- a/pkg/bpf/interpreter_test.go +++ b/pkg/bpf/interpreter_test.go @@ -29,7 +29,7 @@ func TestCompilationErrors(t *testing.T) { desc string // insns is the BPF instructions to be compiled. - insns []linux.BPFInstruction + insns []Instruction // expectedErr is the expected compilation error. expectedErr error @@ -40,22 +40,22 @@ func TestCompilationErrors(t *testing.T) { }, { desc: "Instructions must not be empty", - insns: []linux.BPFInstruction{}, + insns: []Instruction{}, expectedErr: Error{InvalidInstructionCount, 0}, }, { desc: "A program must end with a return", - insns: make([]linux.BPFInstruction, MaxInstructions), + insns: make([]Instruction, MaxInstructions), expectedErr: Error{InvalidEndOfProgram, MaxInstructions - 1}, }, { desc: "A program must have MaxInstructions or fewer instructions", - insns: append(make([]linux.BPFInstruction, MaxInstructions), Stmt(Ret|K, 0)), + insns: append(make([]Instruction, MaxInstructions), Stmt(Ret|K, 0)), expectedErr: Error{InvalidInstructionCount, MaxInstructions + 1}, }, { desc: "A load from an invalid M register is a compilation error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Mem|W, ScratchMemRegisters), // A = M[16] Stmt(Ret|K, 0), // return 0 }, @@ -63,7 +63,7 @@ func TestCompilationErrors(t *testing.T) { }, { desc: "A store to an invalid M register is a compilation error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(St, ScratchMemRegisters), // M[16] = A Stmt(Ret|K, 0), // return 0 }, @@ -71,7 +71,7 @@ func TestCompilationErrors(t *testing.T) { }, { desc: "Division by literal zero is a compilation error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Alu|Div|K, 0), // A /= 0 Stmt(Ret|K, 0), // return 0 }, @@ -79,7 +79,7 @@ func TestCompilationErrors(t *testing.T) { }, { desc: "An unconditional jump outside of the program is a compilation error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Jump(Jmp|Ja, 1, 0, 0), // jmp nextpc+1 Stmt(Ret|K, 0), // return 0 }, @@ -87,7 +87,7 @@ func TestCompilationErrors(t *testing.T) { }, { desc: "A conditional jump outside of the program in the true case is a compilation error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Jump(Jmp|Jeq|K, 0, 1, 0), // if (A == K) jmp nextpc+1 Stmt(Ret|K, 0), // return 0 }, @@ -95,7 +95,7 @@ func TestCompilationErrors(t *testing.T) { }, { desc: "A conditional jump outside of the program in the false case is a compilation error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Jump(Jmp|Jeq|K, 0, 0, 1), // if (A != K) jmp nextpc+1 Stmt(Ret|K, 0), // return 0 }, @@ -115,14 +115,14 @@ func TestExecErrors(t *testing.T) { desc string // insns is the BPF instructions to be executed. - insns []linux.BPFInstruction + insns []Instruction // expectedErr is the expected execution error. expectedErr error }{ { desc: "An out-of-bounds load of input data is an execution error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Abs|B, 0), // A = input[0] Stmt(Ret|K, 0), // return 0 }, @@ -130,7 +130,7 @@ func TestExecErrors(t *testing.T) { }, { desc: "Division by zero at runtime is an execution error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Alu|Div|X, 0), // A /= X Stmt(Ret|K, 0), // return 0 }, @@ -138,7 +138,7 @@ func TestExecErrors(t *testing.T) { }, { desc: "Modulo zero at runtime is an execution error", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Alu|Mod|X, 0), // A %= X Stmt(Ret|K, 0), // return 0 }, @@ -163,7 +163,7 @@ func TestValidInstructions(t *testing.T) { desc string // insns is the BPF instructions to be compiled. - insns []linux.BPFInstruction + insns []Instruction // input is the input data. Note that input will be read as big-endian. input []byte @@ -173,14 +173,14 @@ func TestValidInstructions(t *testing.T) { }{ { desc: "Return of immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ret|K, 42), // return 42 }, expectedRet: 42, }, { desc: "Load of immediate into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 42), // A = 42 Stmt(Ret|A, 0), // return A }, @@ -188,7 +188,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of immediate into X and copying of X into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Imm|W, 42), // X = 42 Stmt(Misc|Tax, 0), // A = X Stmt(Ret|A, 0), // return A @@ -197,7 +197,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Copying of A into X and back", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 42), // A = 42 Stmt(Misc|Txa, 0), // X = A Stmt(Ld|Imm|W, 0), // A = 0 @@ -208,7 +208,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of 32-bit input by absolute offset into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Abs|W, 1), // A = input[1..4] Stmt(Ret|A, 0), // return A }, @@ -217,7 +217,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of 16-bit input by absolute offset into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Abs|H, 1), // A = input[1..2] Stmt(Ret|A, 0), // return A }, @@ -226,7 +226,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of 8-bit input by absolute offset into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Abs|B, 1), // A = input[1] Stmt(Ret|A, 0), // return A }, @@ -235,7 +235,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of 32-bit input by relative offset into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Imm|W, 1), // X = 1 Stmt(Ld|Ind|W, 1), // A = input[X+1..X+4] Stmt(Ret|A, 0), // return A @@ -245,7 +245,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of 16-bit input by relative offset into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Imm|W, 1), // X = 1 Stmt(Ld|Ind|H, 1), // A = input[X+1..X+2] Stmt(Ret|A, 0), // return A @@ -255,7 +255,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of 8-bit input by relative offset into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Imm|W, 1), // X = 1 Stmt(Ld|Ind|B, 1), // A = input[X+1] Stmt(Ret|A, 0), // return A @@ -265,7 +265,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load/store between A and scratch memory", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 42), // A = 42 Stmt(St, 2), // M[2] = A Stmt(Ld|Imm|W, 0), // A = 0 @@ -276,7 +276,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load/store between X and scratch memory", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Imm|W, 42), // X = 42 Stmt(Stx, 3), // M[3] = X Stmt(Ldx|Imm|W, 0), // X = 0 @@ -288,7 +288,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of input length into A", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Len|W, 0), // A = len(input) Stmt(Ret|A, 0), // return A }, @@ -297,7 +297,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of input length into X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Len|W, 0), // X = len(input) Stmt(Misc|Tax, 0), // A = X Stmt(Ret|A, 0), // return A @@ -307,7 +307,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Load of MSH (?) into X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ldx|Msh|B, 0), // X = 4*(input[0]&0xf) Stmt(Misc|Tax, 0), // A = X Stmt(Ret|A, 0), // return A @@ -317,7 +317,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Addition of immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Stmt(Alu|Add|K, 20), // A += 20 Stmt(Ret|A, 0), // return A @@ -326,7 +326,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Addition of X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Stmt(Ldx|Imm|W, 20), // X = 20 Stmt(Alu|Add|X, 0), // A += X @@ -336,7 +336,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Subtraction of immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 30), // A = 30 Stmt(Alu|Sub|K, 20), // A -= 20 Stmt(Ret|A, 0), // return A @@ -345,7 +345,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Subtraction of X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 30), // A = 30 Stmt(Ldx|Imm|W, 20), // X = 20 Stmt(Alu|Sub|X, 0), // A -= X @@ -355,7 +355,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Multiplication of immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 2), // A = 2 Stmt(Alu|Mul|K, 3), // A *= 3 Stmt(Ret|A, 0), // return A @@ -364,7 +364,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Multiplication of X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 2), // A = 2 Stmt(Ldx|Imm|W, 3), // X = 3 Stmt(Alu|Mul|X, 0), // A *= X @@ -374,7 +374,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Division by immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 6), // A = 6 Stmt(Alu|Div|K, 3), // A /= 3 Stmt(Ret|A, 0), // return A @@ -383,7 +383,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Division by X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 6), // A = 6 Stmt(Ldx|Imm|W, 3), // X = 3 Stmt(Alu|Div|X, 0), // A /= X @@ -393,7 +393,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Modulo immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 17), // A = 17 Stmt(Alu|Mod|K, 7), // A %= 7 Stmt(Ret|A, 0), // return A @@ -402,7 +402,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Modulo X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 17), // A = 17 Stmt(Ldx|Imm|W, 7), // X = 7 Stmt(Alu|Mod|X, 0), // A %= X @@ -412,7 +412,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Arithmetic negation", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 1), // A = 1 Stmt(Alu|Neg, 0), // A = -A Stmt(Ret|A, 0), // return A @@ -421,7 +421,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Bitwise OR with immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff00aa55), // A = 0xff00aa55 Stmt(Alu|Or|K, 0xff0055aa), // A |= 0xff0055aa Stmt(Ret|A, 0), // return A @@ -430,7 +430,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Bitwise OR with X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff00aa55), // A = 0xff00aa55 Stmt(Ldx|Imm|W, 0xff0055aa), // X = 0xff0055aa Stmt(Alu|Or|X, 0), // A |= X @@ -440,7 +440,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Bitwise AND with immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff00aa55), // A = 0xff00aa55 Stmt(Alu|And|K, 0xff0055aa), // A &= 0xff0055aa Stmt(Ret|A, 0), // return A @@ -449,7 +449,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Bitwise AND with X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff00aa55), // A = 0xff00aa55 Stmt(Ldx|Imm|W, 0xff0055aa), // X = 0xff0055aa Stmt(Alu|And|X, 0), // A &= X @@ -459,7 +459,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Bitwise XOR with immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff00aa55), // A = 0xff00aa55 Stmt(Alu|Xor|K, 0xff0055aa), // A ^= 0xff0055aa Stmt(Ret|A, 0), // return A @@ -468,7 +468,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Bitwise XOR with X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff00aa55), // A = 0xff00aa55 Stmt(Ldx|Imm|W, 0xff0055aa), // X = 0xff0055aa Stmt(Alu|Xor|X, 0), // A ^= X @@ -478,7 +478,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Left shift by immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 1), // A = 1 Stmt(Alu|Lsh|K, 5), // A <<= 5 Stmt(Ret|A, 0), // return A @@ -487,7 +487,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Left shift by X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 1), // A = 1 Stmt(Ldx|Imm|W, 5), // X = 5 Stmt(Alu|Lsh|X, 0), // A <<= X @@ -497,7 +497,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Right shift by immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xffffffff), // A = 0xffffffff Stmt(Alu|Rsh|K, 31), // A >>= 31 Stmt(Ret|A, 0), // return A @@ -506,7 +506,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Right shift by X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xffffffff), // A = 0xffffffff Stmt(Ldx|Imm|W, 31), // X = 31 Stmt(Alu|Rsh|X, 0), // A >>= X @@ -516,7 +516,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Unconditional jump", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Jump(Jmp|Ja, 1, 0, 0), // jmp nextpc+1 Stmt(Ret|K, 0), // return 0 Stmt(Ret|K, 1), // return 1 @@ -525,7 +525,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A == immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 42), // A = 42 Jump(Jmp|Jeq|K, 42, 1, 2), // if (A == 42) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -536,7 +536,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A != immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Jump(Jmp|Jeq|K, 42, 1, 2), // if (A == 42) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 Stmt(Ret|K, 1), // return 1 @@ -546,7 +546,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A == X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 42), // A = 42 Stmt(Ldx|Imm|W, 42), // X = 42 Jump(Jmp|Jeq|X, 0, 1, 2), // if (A == X) jmp nextpc+1 else jmp nextpc+2 @@ -558,7 +558,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A != X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 42), // A = 42 Jump(Jmp|Jeq|X, 0, 1, 2), // if (A == X) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -569,7 +569,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A > immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Jump(Jmp|Jgt|K, 9, 1, 2), // if (A > 9) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -580,7 +580,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A <= immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Jump(Jmp|Jgt|K, 10, 1, 2), // if (A > 10) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -591,7 +591,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A > X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Stmt(Ldx|Imm|W, 9), // X = 9 Jump(Jmp|Jgt|X, 0, 1, 2), // if (A > X) jmp nextpc+1 else jmp nextpc+2 @@ -603,7 +603,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A <= X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Stmt(Ldx|Imm|W, 10), // X = 10 Jump(Jmp|Jgt|X, 0, 1, 2), // if (A > X) jmp nextpc+1 else jmp nextpc+2 @@ -615,7 +615,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A >= immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Jump(Jmp|Jge|K, 10, 1, 2), // if (A >= 10) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -626,7 +626,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A < immediate", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Jump(Jmp|Jge|K, 11, 1, 2), // if (A >= 11) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -637,7 +637,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A >= X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Stmt(Ldx|Imm|W, 10), // X = 10 Jump(Jmp|Jge|X, 0, 1, 2), // if (A >= X) jmp nextpc+1 else jmp nextpc+2 @@ -649,7 +649,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A < X", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 10), // A = 10 Stmt(Ldx|Imm|W, 11), // X = 11 Jump(Jmp|Jge|X, 0, 1, 2), // if (A >= X) jmp nextpc+1 else jmp nextpc+2 @@ -661,7 +661,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A & immediate != 0", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff), // A = 0xff Jump(Jmp|Jset|K, 0x101, 1, 2), // if (A & 0x101) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -672,7 +672,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A & immediate == 0", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xfe), // A = 0xfe Jump(Jmp|Jset|K, 0x101, 1, 2), // if (A & 0x101) jmp nextpc+1 else jmp nextpc+2 Stmt(Ret|K, 0), // return 0 @@ -683,7 +683,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A & X != 0", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xff), // A = 0xff Stmt(Ldx|Imm|W, 0x101), // X = 0x101 Jump(Jmp|Jset|X, 0, 1, 2), // if (A & X) jmp nextpc+1 else jmp nextpc+2 @@ -695,7 +695,7 @@ func TestValidInstructions(t *testing.T) { }, { desc: "Jump when A & X == 0", - insns: []linux.BPFInstruction{ + insns: []Instruction{ Stmt(Ld|Imm|W, 0xfe), // A = 0xfe Stmt(Ldx|Imm|W, 0x101), // X = 0x101 Jump(Jmp|Jset|X, 0, 1, 2), // if (A & X) jmp nextpc+1 else jmp nextpc+2 @@ -726,7 +726,7 @@ func TestSimpleFilter(t *testing.T) { // Seccomp filter example given in Linux's // Documentation/networking/filter.txt, translated to bytecode using the // Linux kernel tree's tools/net/bpf_asm. - filter := []linux.BPFInstruction{ + filter := []Instruction{ {0x20, 0, 0, 0x00000004}, // ld [4] /* offsetof(struct seccomp_data, arch) */ {0x15, 0, 11, 0xc000003e}, // jne #0xc000003e, bad /* AUDIT_ARCH_X86_64 */ {0x20, 0, 0, 0000000000}, // ld [0] /* offsetof(struct seccomp_data, nr) */ diff --git a/pkg/bpf/program_builder.go b/pkg/bpf/program_builder.go index caaf99c83..8839c61cf 100644 --- a/pkg/bpf/program_builder.go +++ b/pkg/bpf/program_builder.go @@ -17,8 +17,6 @@ package bpf import ( "fmt" "math" - - "gvisor.dev/gvisor/pkg/abi/linux" ) const ( @@ -38,7 +36,7 @@ type ProgramBuilder struct { unusableLabels map[string]bool // Array of BPF instructions that makes up the program. - instructions []linux.BPFInstruction + instructions []Instruction } // NewProgramBuilder creates a new ProgramBuilder instance. @@ -134,7 +132,7 @@ func (b *ProgramBuilder) AddLabel(name string) error { // resolved. Return error in case label resolution failed due to an invalid program. // // N.B. Partial results will be returned in the error case, which is useful for debugging. -func (b *ProgramBuilder) Instructions() ([]linux.BPFInstruction, error) { +func (b *ProgramBuilder) Instructions() ([]Instruction, error) { if err := b.resolveLabels(); err != nil { return b.instructions, err } diff --git a/pkg/bpf/program_builder_test.go b/pkg/bpf/program_builder_test.go index 37f684f25..cb5bb90a6 100644 --- a/pkg/bpf/program_builder_test.go +++ b/pkg/bpf/program_builder_test.go @@ -17,11 +17,9 @@ package bpf import ( "fmt" "testing" - - "gvisor.dev/gvisor/pkg/abi/linux" ) -func validate(p *ProgramBuilder, expected []linux.BPFInstruction) error { +func validate(p *ProgramBuilder, expected []Instruction) error { instructions, err := p.Instructions() if err != nil { return fmt.Errorf("Instructions() failed: %v", err) @@ -45,7 +43,7 @@ func TestProgramBuilderSimple(t *testing.T) { p.AddStmt(Ld+Abs+W, 10) p.AddJump(Jmp+Ja, 10, 0, 0) - expected := []linux.BPFInstruction{ + expected := []Instruction{ Stmt(Ld+Abs+W, 10), Jump(Jmp+Ja, 10, 0, 0), } @@ -84,7 +82,7 @@ func TestProgramBuilderLabels(t *testing.T) { } p.AddStmt(Ld+Abs+W, 5) - expected := []linux.BPFInstruction{ + expected := []Instruction{ Jump(Jmp+Jeq+K, 11, 2, 0), Jump(Jmp+Jeq+K, 12, 0, 3), Jump(Jmp+Jeq+K, 13, 1, 3), @@ -131,7 +129,7 @@ func TestProgramBuilderUnusedLabel(t *testing.T) { p.AddStmt(Ld+Abs+W, 10) p.AddJump(Jmp+Ja, 10, 0, 0) - expected := []linux.BPFInstruction{ + expected := []Instruction{ Stmt(Ld+Abs+W, 10), Jump(Jmp+Ja, 10, 0, 0), } diff --git a/pkg/seccomp/seccomp.go b/pkg/seccomp/seccomp.go index c2e860c55..9f476f3ab 100644 --- a/pkg/seccomp/seccomp.go +++ b/pkg/seccomp/seccomp.go @@ -130,7 +130,7 @@ var SyscallName = func(sysno uintptr) string { // BuildProgram builds a BPF program from the given map of actions to matching // SyscallRules. The single generated program covers all provided RuleSets. -func BuildProgram(rules []RuleSet, defaultAction, badArchAction linux.BPFAction) ([]linux.BPFInstruction, error) { +func BuildProgram(rules []RuleSet, defaultAction, badArchAction linux.BPFAction) ([]bpf.Instruction, error) { program := bpf.NewProgramBuilder() // Be paranoid and check that syscall is done in the expected architecture. diff --git a/pkg/seccomp/seccomp_unsafe.go b/pkg/seccomp/seccomp_unsafe.go index d2e7ea8a6..b289d72ce 100644 --- a/pkg/seccomp/seccomp_unsafe.go +++ b/pkg/seccomp/seccomp_unsafe.go @@ -21,10 +21,11 @@ import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" + "gvisor.dev/gvisor/pkg/bpf" ) // SetFilter installs the given BPF program. -func SetFilter(instrs []linux.BPFInstruction) error { +func SetFilter(instrs []bpf.Instruction) error { // PR_SET_NO_NEW_PRIVS is required in order to enable seccomp. See // seccomp(2) for details. // @@ -73,7 +74,7 @@ func SetFilter(instrs []linux.BPFInstruction) error { // //go:norace //go:nosplit -func SetFilterInChild(instrs []linux.BPFInstruction) unix.Errno { +func SetFilterInChild(instrs []bpf.Instruction) unix.Errno { if _, _, errno := unix.RawSyscall6(unix.SYS_PRCTL, linux.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0, 0); errno != 0 { return errno } diff --git a/pkg/sentry/platform/ptrace/BUILD b/pkg/sentry/platform/ptrace/BUILD index d973623d5..9d89b2571 100644 --- a/pkg/sentry/platform/ptrace/BUILD +++ b/pkg/sentry/platform/ptrace/BUILD @@ -27,6 +27,7 @@ go_library( visibility = ["//:sandbox"], deps = [ "//pkg/abi/linux", + "//pkg/bpf", "//pkg/context", "//pkg/cpuid", "//pkg/hostarch", diff --git a/pkg/sentry/platform/ptrace/subprocess_linux.go b/pkg/sentry/platform/ptrace/subprocess_linux.go index 901ad9213..80ce18d81 100644 --- a/pkg/sentry/platform/ptrace/subprocess_linux.go +++ b/pkg/sentry/platform/ptrace/subprocess_linux.go @@ -22,6 +22,7 @@ import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" + "gvisor.dev/gvisor/pkg/bpf" "gvisor.dev/gvisor/pkg/hosttid" "gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/seccomp" @@ -130,7 +131,7 @@ func attachedThread(flags uintptr, defaultAction linux.BPFAction) (*thread, erro // not race instrument it. // //go:norace -func forkStub(flags uintptr, instrs []linux.BPFInstruction) (*thread, error) { +func forkStub(flags uintptr, instrs []bpf.Instruction) (*thread, error) { // Declare all variables up front in order to ensure that there's no // need for allocations between beforeFork & afterFork. var ( diff --git a/pkg/sentry/platform/systrap/BUILD b/pkg/sentry/platform/systrap/BUILD index 1a3864a36..05e81c470 100644 --- a/pkg/sentry/platform/systrap/BUILD +++ b/pkg/sentry/platform/systrap/BUILD @@ -74,6 +74,7 @@ go_library( deps = [ "//pkg/abi/linux", "//pkg/atomicbitops", + "//pkg/bpf", "//pkg/context", "//pkg/cpuid", "//pkg/hostarch", diff --git a/pkg/sentry/platform/systrap/stub_unsafe.go b/pkg/sentry/platform/systrap/stub_unsafe.go index fb7f096ba..1c5b89f4b 100644 --- a/pkg/sentry/platform/systrap/stub_unsafe.go +++ b/pkg/sentry/platform/systrap/stub_unsafe.go @@ -21,6 +21,7 @@ import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" + "gvisor.dev/gvisor/pkg/bpf" "gvisor.dev/gvisor/pkg/hostarch" "gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/safecopy" @@ -55,16 +56,15 @@ func unsafeSlice(addr uintptr, length int) (slice []byte) { // //go:nosplit func prepareSeccompRules(stubSysmsgStart, stubSysmsgRules, stubSysmsgRulesLen uintptr) { - instrs := sysmsgThreadRules(stubSysmsgStart) - progLen := len(instrs) * int(unsafe.Sizeof(linux.BPFInstruction{})) + progLen := len(instrs) * int(unsafe.Sizeof(bpf.Instruction{})) progPtr := stubSysmsgRules + unsafe.Sizeof(linux.SockFprog{}) if progLen+int(unsafe.Sizeof(linux.SockFprog{})) > int(stubSysmsgRulesLen) { panic("not enough space for sysmsg seccomp rules") } - var targetSlice []linux.BPFInstruction + var targetSlice []bpf.Instruction sh := (*reflect.SliceHeader)(unsafe.Pointer(&targetSlice)) sh.Data = progPtr sh.Cap = len(instrs) diff --git a/pkg/sentry/platform/systrap/subprocess_linux.go b/pkg/sentry/platform/systrap/subprocess_linux.go index 3ac73bb82..dda3d8281 100644 --- a/pkg/sentry/platform/systrap/subprocess_linux.go +++ b/pkg/sentry/platform/systrap/subprocess_linux.go @@ -22,6 +22,7 @@ import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" + "gvisor.dev/gvisor/pkg/bpf" "gvisor.dev/gvisor/pkg/seccomp" "gvisor.dev/gvisor/pkg/sentry/arch" ) @@ -139,7 +140,7 @@ func attachedThread(flags uintptr, defaultAction linux.BPFAction) (*thread, erro // not race instrument it. // //go:norace -func forkStub(flags uintptr, instrs []linux.BPFInstruction) (*thread, error) { +func forkStub(flags uintptr, instrs []bpf.Instruction) (*thread, error) { // Declare all variables up front in order to ensure that there's no // need for allocations between beforeFork & afterFork. var ( diff --git a/pkg/sentry/platform/systrap/sysmsg_thread.go b/pkg/sentry/platform/systrap/sysmsg_thread.go index 6b97f3be3..4472a5d69 100644 --- a/pkg/sentry/platform/systrap/sysmsg_thread.go +++ b/pkg/sentry/platform/systrap/sysmsg_thread.go @@ -19,6 +19,7 @@ import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" + "gvisor.dev/gvisor/pkg/bpf" "gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/seccomp" "gvisor.dev/gvisor/pkg/sentry/arch" @@ -96,7 +97,7 @@ func (p *sysmsgThread) Debugf(format string, v ...any) { p.thread.Debugf(format+postfix, v...) } -func sysmsgThreadRules(stubStart uintptr) []linux.BPFInstruction { +func sysmsgThreadRules(stubStart uintptr) []bpf.Instruction { rules := []seccomp.RuleSet{} rules = appendSysThreadArchSeccompRules(rules) rules = append(rules, []seccomp.RuleSet{ diff --git a/pkg/sentry/syscalls/linux/sys_seccomp.go b/pkg/sentry/syscalls/linux/sys_seccomp.go index cf824b407..e9cfe055d 100644 --- a/pkg/sentry/syscalls/linux/sys_seccomp.go +++ b/pkg/sentry/syscalls/linux/sys_seccomp.go @@ -63,7 +63,11 @@ func seccomp(t *kernel.Task, mode, flags uint64, addr hostarch.Addr) error { if _, err := linux.CopyBPFInstructionSliceIn(t, hostarch.Addr(fprog.Filter), filter); err != nil { return err } - compiledFilter, err := bpf.Compile(filter) + bpfFilter := make([]bpf.Instruction, len(filter)) + for i, ins := range filter { + bpfFilter[i] = bpf.Instruction(ins) + } + compiledFilter, err := bpf.Compile(bpfFilter) if err != nil { t.Debugf("Invalid seccomp-bpf filter: %v", err) return linuxerr.EINVAL diff --git a/test/secbench/runner.go b/test/secbench/runner.go index 97e33ac51..86f4f01cd 100644 --- a/test/secbench/runner.go +++ b/test/secbench/runner.go @@ -34,11 +34,11 @@ import ( ) // install installs the given program on the runner. -func install(program []linux.BPFInstruction) error { +func install(program []bpf.Instruction) error { // Rewrite the program so that all return actions are either ALLOW or // RET_ERRNO. This allows us to benchmark the program without worrying // that we'll crash if we call a bad system call. - rewritten := make([]linux.BPFInstruction, len(program)) + rewritten := make([]bpf.Instruction, len(program)) copy(rewritten, program) for pc, ins := range rewritten { switch ins.OpCode { diff --git a/test/secbench/secbenchdef/BUILD b/test/secbench/secbenchdef/BUILD index 7ed60abc6..89fec50c3 100644 --- a/test/secbench/secbenchdef/BUILD +++ b/test/secbench/secbenchdef/BUILD @@ -16,6 +16,7 @@ go_library( ], deps = [ "//pkg/abi/linux", + "//pkg/bpf", "@org_golang_x_sys//unix:go_default_library", ], ) diff --git a/test/secbench/secbenchdef/secbenchdef.go b/test/secbench/secbenchdef/secbenchdef.go index 070451d14..f5afd8225 100644 --- a/test/secbench/secbenchdef/secbenchdef.go +++ b/test/secbench/secbenchdef/secbenchdef.go @@ -20,7 +20,7 @@ import ( "fmt" "golang.org/x/sys/unix" - "gvisor.dev/gvisor/pkg/abi/linux" + "gvisor.dev/gvisor/pkg/bpf" ) // Bench represents a benchmark to run. @@ -30,7 +30,7 @@ type Bench struct { // Profile represents the syscall pattern profile being benchmarked. Profile Profile `json:"profile"` // Program is the seccomp-bpf program to run the benchmark with. - Program []linux.BPFInstruction `json:"program"` + Program []bpf.Instruction `json:"program"` // AllowRejected can be set to true if some sequences in the application // profile are expected to not be allowed. // If this is the case, the program's overall performance will not be