Module: Seccomp::Action

Defined in:
lib/seccomp/action.rb

Overview

Seccomp action constants and conversions.

Constant Summary collapse

DATA_MASK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mask for action payload data.

0xFFFF
ERRNO =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Base value for errno actions.

0x0005_0000
TRACE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Base value for trace actions.

0x7FF0_0000
ACTION_MASK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mask selecting an action without its payload.

0xFFFF_0000
API_LEVELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Minimum runtime API level for newer actions.

{
  KILL_PROCESS => 3,
  LOG => 3,
  NOTIFY => 5
}.freeze
NAMES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Symbol-to-action lookup.

{
  kill_process: KILL_PROCESS,
  kill_thread: KILL_THREAD,
  kill: KILL,
  trap: TRAP,
  notify: NOTIFY,
  log: LOG,
  allow: ALLOW
}.freeze

Class Method Summary collapse

Class Method Details

.describe(value) ⇒ String

Returns debug representation.

Examples:

Action.describe(Action.errno(1))

Parameters:

  • value (Integer)

    action value

Returns:

  • (String)

    debug representation



109
110
111
112
113
114
115
# File 'lib/seccomp/action.rb', line 109

def describe(value)
  return "SCMP_ACT_ERRNO(#{value & DATA_MASK})" if (value & 0xFFFF_0000) == ERRNO
  return "SCMP_ACT_TRACE(#{value & DATA_MASK})" if (value & 0xFFFF_0000) == TRACE

  name = NAMES.key(value)
  name ? "SCMP_ACT_#{name.to_s.upcase}" : format("0x%08x", value)
end

.errno(value) ⇒ Integer

Returns SCMP_ACT_ERRNO action.

Examples:

Action.errno(Errno::EPERM)

Parameters:

  • value (Integer, SystemCallError, Class)

    positive or negative errno

Returns:

  • (Integer)

    SCMP_ACT_ERRNO action

Raises:

  • (ArgumentError)

    for an invalid value



44
45
46
47
48
49
# File 'lib/seccomp/action.rb', line 44

def errno(value)
  number = errno_number(value)
  raise ArgumentError, "errno must not be zero" if number.zero?

  ERRNO | data(number.abs)
end

.resolve(value) ⇒ Integer

Returns action constant.

Examples:

Action.resolve([:errno, Errno::EPERM])

Parameters:

  • value (Symbol, Integer, Array)

    action representation

Returns:

  • (Integer)

    action constant

Raises:

  • (ArgumentError)

    for an unknown action

  • (NotSupportedError)

    when the runtime API level is too low



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/seccomp/action.rb', line 76

def resolve(value)
  action = if value.is_a?(Integer)
             value
           elsif value.is_a?(Array)
             resolve_tuple(value)
           else
             unless value.respond_to?(:to_sym)
               raise ArgumentError, "unknown action: #{value.inspect}"
             end

             NAMES.fetch(value.to_sym) do
               raise ArgumentError, "unknown action: #{value.inspect}"
             end
           end
  ensure_supported!(action)
  action
end

.trace(value) ⇒ Integer

Returns SCMP_ACT_TRACE action.

Examples:

Action.trace(42)

Parameters:

  • value (Integer)

    16-bit trace payload

Returns:

  • (Integer)

    SCMP_ACT_TRACE action

Raises:

  • (ArgumentError)

    outside 0..65535



55
56
57
# File 'lib/seccomp/action.rb', line 55

def trace(value)
  TRACE | data(value)
end

.trap(value = 0) ⇒ Integer

Returns SCMP_ACT_TRAP action.

Examples:

Action.trap(7)

Parameters:

  • value (Integer) (defaults to: 0)

    optional 16-bit trap payload

Returns:

  • (Integer)

    SCMP_ACT_TRAP action

Raises:



63
64
65
66
67
68
69
# File 'lib/seccomp/action.rb', line 63

def trap(value = 0)
  value = data(value)
  return TRAP if value.zero?
  raise NotSupportedError, "SCMP_ACT_TRAPX is not available" unless Seccomp.supports?(:trapx)

  TRAP | value
end