Class: SeccompTools::Explain::Summary

Inherits:
Object
  • Object
show all
Defined in:
lib/seccomp-tools/explain/summary.rb

Overview

Turns the raw Symbolic::Executor::Leafs collected by the walk into a human-readable policy, grouped by architecture and then by action (+ALLOW+, KILL, ERRNO(n), ...).

This class owns the presentation: sections, buckets and the default rule. It reads each leaf's path through PathFacts, decodes the returned action with Verdict, reassembles 64-bit word checks with QwordFusion, and stringifies conditions with Renderer.

Constant Summary collapse

SYS_NAME =

Display name of the syscall-number field, for the range subjects.

Const::BPF::SeccompData::NAMES.fetch(Const::BPF::SeccompData::SYS_NUMBER)
X32_SYSCALL_BIT =

The x32 ABI bit (+__X32_SYSCALL_BIT+); a lower-bound-only range at exactly this value is the conventional x32 guard, worth annotating.

0x40000000
WRAP_WIDTH =

Widest a wrapped bucket line may get, in columns.

72
TRUNCATION_WARNING =

Qualifies a policy whose walk did not finish. Saying results "may be incomplete" undersells it: the rules the walk never reached are absent from the buckets outright, and the syscalls they name are left reading as the default action - which is why the default bucket marks itself too. What those rules were cannot be told without the analysis that was cut.

<<~WARNING
  WARNING: analysis truncated; this policy is incomplete - rules the walk did not reach are
           absent below, and the syscalls they name read as the default action.
WARNING

Instance Method Summary collapse

Constructor Details

#initialize(leaves, arch:, source: nil, truncated: false) ⇒ Summary

Returns a new instance of Summary.

Parameters:

  • leaves (Array<Symbolic::Executor::Leaf>)
  • arch (Symbol) —

    The filter's declared architecture, used when the filter itself does not branch on arch.

  • source (String?) (defaults to: nil) —

    Label shown in the header.

  • truncated (Boolean) (defaults to: false) —

    Whether the walk hit Symbolic::Executor::STEP_CAP.



42
43
44
45
46
47
48
49
# File 'lib/seccomp-tools/explain/summary.rb', line 42

def initialize(leaves, arch:, source: nil, truncated: false)
  @arch = arch
  @source = source
  @truncated = truncated
  @fusion = QwordFusion.new(arch)
  @renderer = Renderer.new(@fusion)
  @analysis = Analysis.new(leaves)
end

Instance Method Details

#to_s ⇒ String

Renders the policy.

Returns:

  • (String)


53
54
55
56
57
58
59
60
61
62
# File 'lib/seccomp-tools/explain/summary.rb', line 53

def to_s
  out = +''
  out << "Seccomp policy for #{@source}\n" if @source
  out << TRUNCATION_WARNING if @truncated
  @analysis.sections(@arch).each do |_arch_val, arch_sym, title, leaves|
    out << "\n" << render_section(title, section_buckets(arch_sym, leaves))
  end
  out << render_other_arches
  out
end