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 to be Linux.
OS.linux?
Class Method Summary collapse
-
.dump(*args, limit: 1, timeout: nil) {|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, timeout: nil) {|bpf, arch| ... } ⇒ Array<Object>, Array<String>
Main bpf dump function.
Yields seccomp bpf whenever a prctl(SET_SECCOMP) call is found.
47 48 49 50 51 52 |
# File 'lib/seccomp-tools/dumper.rb', line 47 def dump(*args, limit: 1, timeout: nil, &block) return [] unless SUPPORTED pid = fork { handle_child(*args) } Handler.new(pid).handle(limit, timeout: timeout, &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.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/seccomp-tools/dumper.rb', line 204 def dump_by_pid(pid, limit, &block) return [] unless SUPPORTED collect = [] arch = Util.process_arch(pid) 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, arch)) i += 1 end ensure Ptrace.detach(pid) end collect end |