Skip to content

FR: TOCTOU mitigation without userspace enter events #2407

@tuminoid

Description

@tuminoid

Motivation

TOCTOU mitigation should be handled on the kernel side to enable disabling of userspace enter events as proposed here.

Feature

As described in the proposal:

The mitigation implemented in this PR (#235) uses enter events. How can we achieve the same result without sending these events to userspace?

For the connect syscall, we can use the tuple parameter in the exit event to avoid issues with TOCTOU. So, the mitigation here is to populate the userspace with information directly from the kernel.

For what concerns the other 4 syscalls, the idea is to hook into the specific tracepoints (e.g., tracepoint/sys_enter_open), collect the necessary parameters, and save them in a map indexed by thread ID. So we use a bpf hash map with thread-id as a key and syscall arguments as a value. This is very similar to what we do today when RAW_TRACEPOINTS are not enabled: https://github.com/falcosecurity/libs/blob/0.19.0/driver/bpf/maps.h#L103 In the exit tracepoint, we can retrieve this information and send only one event to userspace. This drastically reduces the instrumentation time with respect to using the generic sys_enter tracepoint like today. Moreover, we won't send the enter event to userspace but we will merge the information directly in the kernel.

We have some options here, and I'm hoping to discuss the specific implementation design here, before embarking on journey to make it happen:

  • use of hash maps per driver (bpf hash maps where relevant, LRU maps in kernel driver, gvisor ??)
  • is the mentioned RAW_TRACEPOINT code a good example what is expected
  • is some refactoring needed in case we extend the implementation

Alternatives

Alternative or additional work: We could have a configuration flag or a compile time flag to allow opting out of TOCTOU mitigation to allow user choose between performance gain and the mitigation.

Additional context

Linked to configuration flag feature request, if we choose to implement runtime configuration flag for disabling enter events. Link to issue.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions