| ... | ... | @@ -167,6 +167,13 @@ pub const F_ANY_ALIGNMENT = 0x2; |
| 167 | 167 | /// will regress tests to expose bugs. |
| 168 | 168 | pub const F_TEST_RND_HI32 = 0x4; |
| 169 | 169 | |
| 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(). |
| 175 | pub const F_SLEEPABLE = 0x10; |
| 176 | |
| 170 | 177 | /// When BPF ldimm64's insn[0].src_reg != 0 then this can have two extensions: |
| 171 | 178 | /// insn[0].src_reg: BPF_PSEUDO_MAP_FD BPF_PSEUDO_MAP_VALUE |
| 172 | 179 | /// insn[0].imm: map fd map fd |
| ... | ... | @@ -1134,6 +1141,10 @@ pub const ProgType = enum(u32) { |
| 1134 | 1141 | |
| 1135 | 1142 | /// context type: bpf_sk_lookup |
| 1136 | 1143 | sk_lookup, |
| 1144 | |
| 1145 | /// context type: void * |
| 1146 | syscall, |
| 1147 | |
| 1137 | 1148 | _, |
| 1138 | 1149 | }; |
| 1139 | 1150 | |
| ... | ... | @@ -1649,6 +1660,7 @@ pub fn prog_load( |
| 1649 | 1660 | log: ?*Log, |
| 1650 | 1661 | license: []const u8, |
| 1651 | 1662 | kern_version: u32, |
| 1663 | flags: u32, |
| 1652 | 1664 | ) !fd_t { |
| 1653 | 1665 | var attr = Attr{ |
| 1654 | 1666 | .prog_load = std.mem.zeroes(ProgLoadAttr), |
| ... | ... | @@ -1659,6 +1671,7 @@ pub fn prog_load( |
| 1659 | 1671 | attr.prog_load.insn_cnt = @intCast(u32, insns.len); |
| 1660 | 1672 | attr.prog_load.license = @ptrToInt(license.ptr); |
| 1661 | 1673 | attr.prog_load.kern_version = kern_version; |
| 1674 | attr.prog_load.prog_flags = flags; |
| 1662 | 1675 | |
| 1663 | 1676 | if (log) |l| { |
| 1664 | 1677 | attr.prog_load.log_buf = @ptrToInt(l.buf.ptr); |
| ... | ... | @@ -1688,8 +1701,8 @@ test "prog_load" { |
| 1688 | 1701 | Insn.exit(), |
| 1689 | 1702 | }; |
| 1690 | 1703 | |
| 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); |
| 1692 | 1705 | defer std.os.close(prog); |
| 1693 | 1706 | |
| 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)); |
| 1695 | 1708 | } |