authorgravatar for bjorn.linse@gmail.combfredl <bjorn.linse@gmail.com> 2023-06-05 15:56:25+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-13 10:57:51-07:00
log4f914c8414c5220de145b141103ea71e01b23bda
tree72c5ff5a6649e18f779cea7ccc54dc6c67bd89d6
parent28eed1f7b3a8654b941960232d7c707d88649d8d

bpf: expose "syscall" program type and F_SLEEPABLE flag


1 files changed, 15 insertions(+), 2 deletions(-)

lib/std/os/linux/bpf.zig+15-2
......@@ -167,6 +167,13 @@ pub const F_ANY_ALIGNMENT = 0x2;
167167/// will regress tests to expose bugs.
168168pub const F_TEST_RND_HI32 = 0x4;
169169
170/// If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
171/// restrict map and helper usage for such programs. Sleepable BPF programs can
172/// only be attached to hooks where kernel execution context allows sleeping.
173/// Such programs are allowed to use helpers that may sleep like
174/// bpf_copy_from_user().
175pub const F_SLEEPABLE = 0x10;
176
170177/// When BPF ldimm64's insn[0].src_reg != 0 then this can have two extensions:
171178/// insn[0].src_reg: BPF_PSEUDO_MAP_FD BPF_PSEUDO_MAP_VALUE
172179/// insn[0].imm: map fd map fd
......@@ -1134,6 +1141,10 @@ pub const ProgType = enum(u32) {
11341141
11351142 /// context type: bpf_sk_lookup
11361143 sk_lookup,
1144
1145 /// context type: void *
1146 syscall,
1147
11371148 _,
11381149};
11391150
......@@ -1649,6 +1660,7 @@ pub fn prog_load(
16491660 log: ?*Log,
16501661 license: []const u8,
16511662 kern_version: u32,
1663 flags: u32,
16521664) !fd_t {
16531665 var attr = Attr{
16541666 .prog_load = std.mem.zeroes(ProgLoadAttr),
......@@ -1659,6 +1671,7 @@ pub fn prog_load(
16591671 attr.prog_load.insn_cnt = @intCast(u32, insns.len);
16601672 attr.prog_load.license = @ptrToInt(license.ptr);
16611673 attr.prog_load.kern_version = kern_version;
1674 attr.prog_load.prog_flags = flags;
16621675
16631676 if (log) |l| {
16641677 attr.prog_load.log_buf = @ptrToInt(l.buf.ptr);
......@@ -1688,8 +1701,8 @@ test "prog_load" {
16881701 Insn.exit(),
16891702 };
16901703
1691 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
1704 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0, 0);
16921705 defer std.os.close(prog);
16931706
1694 try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
1707 try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0, 0));
16951708}