Module: SeccompTools::Dumper
- Defined in:
- lib/seccomp-tools/dumper.rb
Overview
Dump seccomp-bpf using ptrace of binary.
Defined Under Namespace
Classes: Handler
Constant Summary collapse
- SUPPORTED =
Whether the dumper is supported. Dumper works based on ptrace, so we need the platform be Linux.
OS.linux?
Class Method Summary collapse
-
.dump(*args, limit: 1) {|bpf, arch| ... } ⇒ Array<Object>, Array<String>
Main bpf dump function.
-
.dump_by_pid(pid, limit) {|bpf, arch| ... } ⇒ Array<Object>, Array<String>
Dump installed seccomp-bpf of an existing process using PTRACE_SECCOMP_GET_FILTER.
Class Method Details
.dump(*args, limit: 1) {|bpf, arch| ... } ⇒ Array<Object>, Array<String>
TODO:
timeout option.
Main bpf dump function. Yield seccomp bpf whenever find a prctl(SET_SECCOMP) call.
42 43 44 45 46 47 |
# File 'lib/seccomp-tools/dumper.rb', line 42 def dump(*args, limit: 1, &block) return [] unless SUPPORTED pid = fork { handle_child(*args) } Handler.new(pid).handle(limit, &block) end |
.dump_by_pid(pid, limit) {|bpf, arch| ... } ⇒ Array<Object>, Array<String>
Dump installed seccomp-bpf of an existing process using PTRACE_SECCOMP_GET_FILTER.
Dump the installed seccomp-bpf from a running process. This is achieved by the ptrace command PTRACE_SECCOMP_GET_FILTER, which needs CAP_SYS_ADMIN capability.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/seccomp-tools/dumper.rb', line 173 def dump_by_pid(pid, limit, &block) return [] unless SUPPORTED collect = [] Ptrace.attach_and_wait(pid) begin i = 0 while limit.negative? || i < limit begin bpf = Ptrace.seccomp_get_filter(pid, i) rescue Errno::ENOENT, Errno::EINVAL break end collect << (block.nil? ? bpf : yield(bpf, nil)) i += 1 end ensure Ptrace.detach(pid) end collect end |