Module: Seccomp::Attributes

Included in:
Filter
Defined in:
lib/seccomp/attributes.rb

Overview

Named accessors for libseccomp filter attributes.

Constant Summary collapse

ATTRIBUTE_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-C-attribute lookup.

{
  default_action: FilterAttr::ACT_DEFAULT,
  bad_arch_action: FilterAttr::ACT_BADARCH,
  no_new_privs: FilterAttr::CTL_NNP,
  tsync: FilterAttr::CTL_TSYNC,
  tskip: FilterAttr::API_TSKIP,
  log: FilterAttr::CTL_LOG,
  ssb: FilterAttr::CTL_SSB,
  optimize: FilterAttr.const_defined?(:CTL_OPTIMIZE) ? FilterAttr::CTL_OPTIMIZE : nil,
  raw_rc: FilterAttr.const_defined?(:API_SYSRAWRC) ? FilterAttr::API_SYSRAWRC : nil,
  wait_killable: FilterAttr.const_defined?(:CTL_WAITKILL) ? FilterAttr::CTL_WAITKILL : nil
}.compact.freeze
BOOLEAN_ATTRIBUTES =

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.

Attributes exposed as predicate accessors.

%i[no_new_privs tsync tskip log ssb raw_rc wait_killable].freeze
ATTRIBUTE_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 attributes.

{
  FilterAttr::CTL_TSYNC => 2,
  FilterAttr::CTL_LOG => 3,
  FilterAttr::CTL_SSB => 4,
  (FilterAttr::CTL_WAITKILL if FilterAttr.const_defined?(:CTL_WAITKILL)) => 7
}.compact.freeze

Instance Method Summary collapse

Instance Method Details

#[](attribute) ⇒ Integer

Returns raw attribute value.

Examples:

filter[:optimize]

Parameters:

  • attribute (Symbol, Integer)

    attribute name or enum value

Returns:

  • (Integer)

    raw attribute value

Raises:

  • (Error)

    if the attribute cannot be read



37
38
39
40
41
42
43
# File 'lib/seccomp/attributes.rb', line 37

def [](attribute)
  synchronize do
    rc, value = LowLevel.attr_get(@context, resolve_attribute(attribute))
    Error.check!(rc, call: "seccomp_attr_get", hint: "attribute #{attribute}")
    value
  end
end

#[]=(attribute, value) ⇒ Integer

Returns assigned value.

Examples:

filter[:optimize] = 2

Parameters:

  • attribute (Symbol, Integer)

    attribute name or enum value

  • value (Integer)

    raw attribute value

Returns:

  • (Integer)

    assigned value

Raises:

  • (Error)

    if the attribute cannot be set



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/seccomp/attributes.rb', line 50

def []=(attribute, value)
  synchronize do
    resolved = resolve_attribute(attribute)
    value = Action.resolve(value) if resolved == FilterAttr::ACT_BADARCH
    if resolved == FilterAttr::CTL_TSYNC && value.is_a?(Integer) && !value.zero?
      ensure_notification_tsync_supported!(tsync: true)
    end

    Error.check!(LowLevel.attr_set(@context, resolved, value),
                 call: "seccomp_attr_set", hint: "attribute #{attribute}")
  end
  value
end

#bad_arch_actionInteger

Returns action for unsupported architectures.

Examples:

filter.bad_arch_action

Returns:

  • (Integer)

    action for unsupported architectures



72
73
74
# File 'lib/seccomp/attributes.rb', line 72

def bad_arch_action
  self[:bad_arch_action]
end

#bad_arch_action=(value) ⇒ Integer

Returns assigned action.

Examples:

filter.bad_arch_action = :kill_process

Parameters:

  • value (Symbol, Integer)

    action

Returns:

  • (Integer)

    assigned action

Raises:

  • (Error)

    if rejected



80
81
82
# File 'lib/seccomp/attributes.rb', line 80

def bad_arch_action=(value)
  self[:bad_arch_action] = value
end

#default_actionInteger

Returns default action.

Examples:

filter.default_action

Returns:

  • (Integer)

    default action



66
67
68
# File 'lib/seccomp/attributes.rb', line 66

def default_action
  self[:default_action]
end

#optimizeInteger

Returns optimization level.

Examples:

filter.optimize

Returns:

  • (Integer)

    optimization level



95
96
97
# File 'lib/seccomp/attributes.rb', line 95

def optimize
  self[:optimize]
end

#optimize=(value) ⇒ Integer

Returns assigned level.

Examples:

filter.optimize = 2

Parameters:

  • value (Integer)

    optimization level

Returns:

  • (Integer)

    assigned level

Raises:

  • (Error)

    if rejected



103
104
105
# File 'lib/seccomp/attributes.rb', line 103

def optimize=(value)
  self[:optimize] = value
end