Skip to content

Conversation

@ekoops
Copy link
Contributor

@ekoops ekoops commented Aug 7, 2025

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

This PR is related to #2407.

Current TOCTOU mitigation implementation leverages the enter events generated by eBPF programs which are tail-called by the sys_enter dispatcher. As the architecture is moving towards dropping enter event generation and collection, the sys_enter dispatcher will be ultimately removed. This requires to isolate TOCTOU mitigation handling logic in order to make it independent from sys_enter dispatcher removal.

This patch moves TOCTOU mitigation handling logic into separate ad-hoc eBPF tracepoint programs attached on corresponding syscalls/sys_enter_* hooks.

For each system call <syscall> that already supports TOCTOU mitigation, two eBPF tracepoint programs are defined:

  • ttm_<syscall>_e - this program is responsible for tail calling the <syscall>_e program after having performed syscall ID normalization and applied any required sampling/filtering logic
  • <syscall>_e - this program is responsible for collecting the information needed to generate the proper enter event and sending the generated event to userspace

Tail-called TOCTOU mitigation programs are inserted into a separate tail call map, called syscall_enter_toctou_mitigation_tail_table.

As the tracepoint attachment procedure generates an openat exit event on /sys/kernel/tracing/events/.../id that would pollute the stream of events read by the probe, the implementation takes care of attaching them before attaching the sys_exit dispatcher.

Notice that the new logic make the TOCTOU mitigation programs attachment dependent on the presence of the sys_exit dispatcher.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

/milestone 0.22.0

Does this PR introduce a user-facing change?:

feat!: isolate modern probe TOCTOU mitigation logic

@github-actions
Copy link

github-actions bot commented Aug 7, 2025

Please double check driver/API_VERSION file. See versioning.

/hold

@codecov
Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.17%. Comparing base (082157d) to head (bfad8ce).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2576   +/-   ##
=======================================
  Coverage   78.17%   78.17%           
=======================================
  Files         298      298           
  Lines       32098    32098           
  Branches     4693     4691    -2     
=======================================
  Hits        25092    25092           
  Misses       7006     7006           
Flag Coverage Δ
libsinsp 78.17% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ekoops ekoops force-pushed the ekoops/isolate-modern-toctou branch 2 times, most recently from 1a55cba to 65adf8e Compare August 8, 2025 08:31
@ekoops ekoops changed the title feat: isolate modern probe TOCTOU mitigation logic feat!: isolate modern probe TOCTOU mitigation logic Aug 8, 2025
@ekoops
Copy link
Contributor Author

ekoops commented Aug 8, 2025

Not bumping the driver schema version is currently a practice we are following as we will bump it in a single shot once we are done with the #2068 proposal.
/hold cancel

@github-actions
Copy link

github-actions bot commented Aug 8, 2025

Perf diff from master - unit tests

     2.37%     +0.45%  [.] sinsp_thread_manager::get_thread_ref
     5.95%     +0.31%  [.] sinsp_evt::get_type
     2.03%     -0.29%  [.] can_query_os_for_thread_info
     1.26%     +0.29%  [.] user_group_updater::~user_group_updater
     3.62%     +0.28%  [.] next_event_from_file
     1.53%     -0.27%  [.] sinsp::fetch_next_event
     1.75%     +0.22%  [.] next
     2.96%     +0.21%  [.] gzfile_read
     2.62%     -0.19%  [.] std::_Hashtable<conversion_key, std::pair<conversion_key const, conversion_info>, std::allocator<std::pair<conversion_key const, conversion_info> >, std::__detail::_Select1st, std::equal_to<conversion_key>, std::hash<conversion_key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_find_before_node
     5.02%     +0.18%  [.] sinsp_parser::reset

Heap diff from master - unit tests

peak heap memory consumption: -110.26K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 32.44K

Heap diff from master - scap file

peak heap memory consumption: 7.90K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            -0.0093         -0.0092           146           145           146           145
BM_sinsp_split_median                                          -0.0093         -0.0093           147           145           147           145
BM_sinsp_split_stddev                                          -0.7542         -0.7577             1             0             1             0
BM_sinsp_split_cv                                              -0.7518         -0.7555             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  -0.0289         -0.0288            64            62            64            62
BM_sinsp_concatenate_paths_relative_path_median                -0.0327         -0.0327            64            62            64            62
BM_sinsp_concatenate_paths_relative_path_stddev                +2.2728         +2.2803             0             1             0             1
BM_sinsp_concatenate_paths_relative_path_cv                    +2.3703         +2.3777             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     -0.0119         -0.0118            25            25            25            25
BM_sinsp_concatenate_paths_empty_path_median                   -0.0110         -0.0110            25            25            25            25
BM_sinsp_concatenate_paths_empty_path_stddev                   -0.1880         -0.1882             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       -0.1783         -0.1786             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  -0.0149         -0.0149            64            63            64            63
BM_sinsp_concatenate_paths_absolute_path_median                -0.0024         -0.0022            62            62            62            62
BM_sinsp_concatenate_paths_absolute_path_stddev                +0.2465         +0.2460             2             3             2             3
BM_sinsp_concatenate_paths_absolute_path_cv                    +0.2654         +0.2648             0             0             0             0

@ekoops ekoops force-pushed the ekoops/isolate-modern-toctou branch from 65adf8e to 1c5d390 Compare August 8, 2025 15:41
@github-actions
Copy link

github-actions bot commented Aug 8, 2025

X64 kernel testing matrix

KERNEL CMAKE-CONFIGURE KMOD BUILD KMOD SCAP-OPEN BPF-PROBE BUILD BPF-PROBE SCAP-OPEN MODERN-BPF SCAP-OPEN
amazonlinux2-4.19 🟢 🟢 🟢 🟢 🟢 🟡
amazonlinux2-5.10 🟢 🟢 🟢 🟢 🟢
amazonlinux2-5.15 🟢 🟢 🟢 🟢 🟢 🟢
amazonlinux2-5.4 🟢 🟢 🟢 🟢 🟢 🟡
amazonlinux2022-5.15 🟢 🟢 🟢 🟢 🟢
amazonlinux2023-6.1 🟢 🟢 🟢 🟢 🟢 🟢
archlinux-6.0 🟢 🟢 🟢 🟢 🟢 🟢
archlinux-6.7 🟢 🟢 🟢 🟢 🟢 🟢
centos-3.10 🟢 🟢 🟢 🟡 🟡 🟡
centos-4.18 🟢 🟢 🟢 🟢 🟢 🟢
centos-5.14 🟢 🟢 🟢 🟢 🟢 🟢
fedora-5.17 🟢 🟢 🟢 🟢 🟢
fedora-5.8 🟢 🟢 🟢 🟢 🟢
fedora-6.2 🟢 🟢 🟢 🟢 🟢 🟢
oraclelinux-3.10 🟢 🟢 🟢 🟡 🟡 🟡
oraclelinux-4.14 🟢 🟢 🟢 🟢 🟢 🟡
oraclelinux-5.15 🟢 🟢 🟢 🟢 🟢 🟢
oraclelinux-5.4 🟢 🟢 🟢 🟢 🟢 🟡
ubuntu-4.15 🟢 🟢 🟢 🟢 🟢 🟡
ubuntu-5.8 🟢 🟢 🟢 🟢 🟢 🟡
ubuntu-6.5 🟢 🟢 🟢 🟢 🟢 🟢

ARM64 kernel testing matrix

KERNEL CMAKE-CONFIGURE KMOD BUILD KMOD SCAP-OPEN BPF-PROBE BUILD BPF-PROBE SCAP-OPEN MODERN-BPF SCAP-OPEN
amazonlinux2-5.4 🟢 🟢 🟢 🟢 🟢 🟡
amazonlinux2022-5.15 🟢 🟢 🟢 🟢 🟢 🟢
fedora-6.2 🟢 🟢 🟢 🟢 🟢 🟢
oraclelinux-4.14 🟢 🟢 🟢 🟡 🟡 🟡
oraclelinux-5.15 🟢 🟢 🟢 🟢 🟢 🟢
ubuntu-6.5 🟢 🟢 🟢 🟢 🟢 🟢

Copy link
Contributor Author

@ekoops ekoops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some clarifying comments

// We don't want to send DROP_E/DROP_X events from the enter tracepoint because it would requires us
// to create a dedicated tail table for the enter. It is enough to send DROP_E/DROP_X events from
// the exit tracepoint.
static __always_inline bool syscalls_dispatcher__sampling_logic_enter(uint32_t syscall_id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from driver/modern_bpf/programs/attached/dispatchers/syscall_enter.bpf.c as it is shared by sys_enter dispatcher and TOCTOU mitigation progs.

* @return never returns in case of success; otherwise, returns 0
*/
static __always_inline int toctou_mitigation__call_prog(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken from sys_enter dispatcher logic

return 0;
}

static __always_inline void toctou_mitigation__push_connect_enter_event(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper allows to share code between the TTM socketcall and the TTM connect programs.

Comment on lines 45 to 76
/* Extract syscall arguments from socketcall args pointer. */
unsigned long args[3] = {0};
void *args_pointer = (void *)ctx->args;
if(bpf_in_ia32_syscall()) {
// First read all arguments on 32 bits.
uint32_t args_u32[3] = {};
bpf_probe_read_user(args_u32, 3 * sizeof(uint32_t), args_pointer);
for(int i = 0; i < 3; i++) {
args[i] = (unsigned long)args_u32[i];
}
} else {
bpf_probe_read_user(args, 3 * sizeof(unsigned long), args_pointer);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simplified version of the extract__network_args helper. We cannot reuse that helper as it expects the caller to have access to a registers pointer. For the moment, since this is the only place we use it, just inline the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering if renaming ttm_socketcall_e as ttm_socketcall_connect_e would make it simpler to follow the implementation...

Copy link
Contributor Author

@ekoops ekoops Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I call it this way to follow the convention defined in the README, and also because in the future we can decide to use it to implement other socketcall-related mitigations (e.g.: accept).

Copy link
Contributor

@terror96 terror96 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. The reason I was thinking its name was that it currently assumes the parameter structure to be for connect and indeed it gets called only for connect (as socketcall_e makes sure). Perhaps then just stating in the comment:

/* Extract connect syscall arguments from socketcall args pointer. */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes totally agree. If you agree, I'm gonna do it in the upcoming PR, as I guess it doesn't worth waiting for another entire CI cycle for this small comment update.


typedef struct {
char* name;
enum bpf_prog_type prog_type;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the program type information, because now programs in userspace/libpman/src/events_prog_table.c can have two types: BPF_PROG_TYPE_RAW_TRACEPOINT (as before) and BPF_PROG_TYPE_TRACEPOINT (new TTM mitigation programs). This information is used in https://github.com/falcosecurity/libs/pull/2576/files#diff-da696150f59c988d4ffde0c0a853f1d258c0db247a2be3f543ed945bdf734603R45

}

/* Enable desired tracepoints */
if(sys_exit) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to attach TOCTOU mitigation programs (dispatchers) if the sys_exit dispatcher is not attached. The reason behind this is that enter events, generated by the tail-called TOCTOU mitigation programs, are conceived to support exit events.

if(sys_exit) {
sys_enter_connect = sc_set[PPM_SC_CONNECT];
if(sys_enter_connect) {
sys_enter_socketcall = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socketcall TOCTOU mitigation program is only attach to support TOCTOU mitigation for connect.

FedeDP
FedeDP previously approved these changes Aug 11, 2025
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Aug 11, 2025

LGTM label has been added.

DetailsGit tree hash: 6f4c87257ce7735e3d4bdf9f06f9b51409230a9f

@ekoops ekoops requested a review from terror96 August 11, 2025 10:01
Copy link
Contributor

@terror96 terror96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds and looks good. :)

@poiana
Copy link
Contributor

poiana commented Aug 11, 2025

@terror96: changing LGTM is restricted to collaborators

Details

In response to this:

Sounds good.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Comment on lines 54 to 40
if(syscall_id == socketcall_syscall_id) {
syscall_id = convert_socketcall_call_to_syscall_id(socketcall_call);
if(syscall_id == -1) {
// We can't do anything since modern bpf filler jump table is syscall indexed.
return 0;
}
}
Copy link
Contributor

@terror96 terror96 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should introduce explicit casting because we compare unsigned value against signed? But this is okay unless -Wsign-compare is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversion is implicitly performed in this case 😄

@ekoops ekoops force-pushed the ekoops/isolate-modern-toctou branch from 1c5d390 to f17e914 Compare August 11, 2025 12:34
@poiana poiana removed the lgtm label Aug 11, 2025
@poiana poiana requested a review from FedeDP August 11, 2025 12:34
@ekoops ekoops force-pushed the ekoops/isolate-modern-toctou branch 3 times, most recently from bfa0a4e to bb5d4af Compare August 13, 2025 13:29
Current TOCTOU mitigation implementation leverages the enter events
generated by eBPF programs which are tail-called by the `sys_enter`
dispatcher. As the architecture is moving towards dropping enter
event generation and collection, the `sys_enter` dispatcher will
be ultimately removed. This requires to isolate TOCTOU mitigation
handling logic in order to make it independent from `sys_enter`
dispatcher removal.

This patch moves TOCTOU mitigation handling logic into separate
ad-hoc eBPF tracepoint programs attached on corresponding
`syscalls/sys_enter_*` hooks.

For each system call `<syscall>`, two eBPF programs are defined. These
programs perform:
- syscall events sampling/filtering
- information gathering
- enter event generation
- enter submission to userspace

The two program classes have the following naming schema and purpose:
- `<syscall>_e` - attached to
  `tracepoint/syscalls/sys_enter_<syscall>` tracepoint hook; provide
  support for 64 bit system calls
- `ia32_<syscall>_e` - attached to `fentry/__ia32_sys_<syscall>`
  fentry hook; provide support for ia32 emulated system calls

Tail-called TOCTOU mitigation programs are inserted into a separate
tail call map, called `syscall_enter_toctou_mitigation_tail_table`.

As the tracepoint attachment procedure generates an `openat` exit
event on `/sys/kernel/tracing/events/.../id` that would pollute the
stream of events read by the probe, the implementation takes care
of attaching them before attaching the `sys_exit` dispatcher.

Notice that the new logic make the TOCTOU mitigation programs
attachment dependent on the presence of the `sys_exit` dispatcher.

BREAKING CHANGE: change prerequisites for attaching some enter progs

Signed-off-by: Leonardo Di Giovanna <[email protected]>
@ekoops ekoops force-pushed the ekoops/isolate-modern-toctou branch from bb5d4af to bfad8ce Compare August 13, 2025 14:43
Copy link
Contributor

@Molter73 Molter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Thanks for the effort put into this! I left a couple comments but most are cleanups and nitpicks.

Comment on lines +24 to +30
int socketcall_syscall_id;

#ifdef __NR_socketcall
socketcall_syscall_id = __NR_socketcall;
#else
socketcall_syscall_id = -1;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick]

Suggested change
int socketcall_syscall_id;
#ifdef __NR_socketcall
socketcall_syscall_id = __NR_socketcall;
#else
socketcall_syscall_id = -1;
#endif
#ifdef __NR_socketcall
int socketcall_syscall_id = __NR_socketcall;
#else
int socketcall_syscall_id = -1;
#endif

Comment on lines +79 to +97
// Convert the socketcall id into the network syscall id.
// In this way the syscall will be treated exactly as the original one.
if(syscall_id == socketcall_syscall_id) {
syscall_id = convert_socketcall_call_to_syscall_id(socketcall_call);
if(syscall_id == -1) {
// We can't do anything since modern bpf filler jump table is syscall indexed.
return 1;
}
}

if(!syscalls_dispatcher__64bit_interesting_syscall(syscall_id)) {
return 1;
}

if(syscalls_dispatcher__sampling_logic_enter(syscall_id)) {
return 1;
}

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this code be moved into the #if defined(__TARGET_ARCH_x86) block? Since the #else for that block will just return 1;

Comment on lines +52 to +66
#if defined(__NR_connect) || defined(__NR_creat) || defined(__NR_open) || defined(__NR_openat)
#ifdef __NR_connect
case __NR_connect:
#endif // __NR_connect
#ifdef __NR_creat
case __NR_creat:
#endif // __NR_creat
#ifdef __NR_open
case __NR_open:
#endif // __NR_open
#ifdef __NR_openat
case __NR_openat:
#endif // __NR_openat
return 0;
#endif // __NR_connect ||__NR_creat || __NR_open || __NR_openat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This can be a bit more compact and readable in this way IMO

Suggested change
#if defined(__NR_connect) || defined(__NR_creat) || defined(__NR_open) || defined(__NR_openat)
#ifdef __NR_connect
case __NR_connect:
#endif // __NR_connect
#ifdef __NR_creat
case __NR_creat:
#endif // __NR_creat
#ifdef __NR_open
case __NR_open:
#endif // __NR_open
#ifdef __NR_openat
case __NR_openat:
#endif // __NR_openat
return 0;
#endif // __NR_connect ||__NR_creat || __NR_open || __NR_openat
#ifdef __NR_connect
case __NR_connect: return 0;
#endif // __NR_connect
#ifdef __NR_creat
case __NR_creat: return 0;
#endif // __NR_creat
#ifdef __NR_open
case __NR_open: return 0;
#endif // __NR_open
#ifdef __NR_openat
case __NR_openat: return 0;
#endif // __NR_openat

/* Extract connect syscall arguments from registers. */
void *args_pointer = (void *)extract__syscall_argument(regs, 1);
unsigned long args[3] = {0};
uint32_t args_u32[3] = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Just for consistency.

Suggested change
uint32_t args_u32[3] = {};
uint32_t args_u32[3] = {0};

Comment on lines +261 to +344
/**
* @brief Attach only the sys_enter_socketcall tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_attach_sys_enter_socketcall(void);

/**
* @brief Detach only the sys_enter_socketcall tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_detach_sys_enter_socketcall(void);

/**
* @brief Attach only the sys_enter_connect tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_attach_sys_enter_connect(void);

/**
* @brief Detach only the sys_enter_connect tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_detach_sys_enter_connect(void);

/**
* @brief Attach only the sys_enter_creat tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_attach_sys_enter_creat(void);

/**
* @brief Detach only the sys_enter_creat tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_detach_sys_enter_creat(void);

/**
* @brief Attach only the sys_enter_open tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_attach_sys_enter_open(void);

/**
* @brief Detach only the sys_enter_open tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_detach_sys_enter_open(void);

/**
* @brief Attach only the sys_enter_openat tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_attach_sys_enter_openat(void);

/**
* @brief Detach only the sys_enter_openat tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_detach_sys_enter_openat(void);

/**
* @brief Attach only the sys_enter_openat2 tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_attach_sys_enter_openat2(void);

/**
* @brief Detach only the sys_enter_openat2 tracepoint
*
* @return `0` on success, `errno` in case of error.
*/
int pman_detach_sys_enter_openat2(void);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a question for a wider PR, but do we need all of these definitions here? Usually having a header file for a library I would expect the definitions in there to be the publicly accessible part of the library, I don't think the intent would be that a user of libpman (like libscap) will want to call pman_detach_sys_enter_openat2(), but rather use something more generic and these would be lower level implementation details that live inside the library itself. IDK, I may be wrong here.

pman_print_error("failed to load BPF object");
return errno;
}
printf("AFTER LOADING\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf("AFTER LOADING\n");

const event_prog_t* enter_prog =
(const event_prog_t*)&event_prog_table[enter_event_type];
const char* enter_prog_name = enter_prog->name;
if(!enter_prog_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Checking for NULL is clearer IMO. I also believe is more correct from a type point of view, ! I would argue is for boolean operations, not pointers (and I know this is not how C works, I still just think this makes more sense).

Suggested change
if(!enter_prog_name) {
if(enter_prog_name == NULL) {

Comment on lines +320 to +335
const event_prog_t* enter_prog =
(const event_prog_t*)&event_prog_table[enter_event_type];
const char* enter_prog_name = enter_prog->name;
if(!enter_prog_name) {
enter_prog = (const event_prog_t*)&event_prog_table[PPME_GENERIC_E];
enter_prog_name = enter_prog->name;
}

/* No programs other tail raw tracepoints are currently tail-called by the sys_enter
* dispatcher. */
if(enter_prog->prog_type == BPF_PROG_TYPE_RAW_TRACEPOINT) {
if(add_bpf_program_to_tail_table(syscall_enter_tail_table_fd,
enter_prog_name,
syscall_id)) {
goto clean_fill_syscalls_tail_table;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need enter_prog_name here.

Suggested change
const event_prog_t* enter_prog =
(const event_prog_t*)&event_prog_table[enter_event_type];
const char* enter_prog_name = enter_prog->name;
if(!enter_prog_name) {
enter_prog = (const event_prog_t*)&event_prog_table[PPME_GENERIC_E];
enter_prog_name = enter_prog->name;
}
/* No programs other tail raw tracepoints are currently tail-called by the sys_enter
* dispatcher. */
if(enter_prog->prog_type == BPF_PROG_TYPE_RAW_TRACEPOINT) {
if(add_bpf_program_to_tail_table(syscall_enter_tail_table_fd,
enter_prog_name,
syscall_id)) {
goto clean_fill_syscalls_tail_table;
}
const event_prog_t* enter_prog =
(const event_prog_t*)&event_prog_table[enter_event_type];
if(enter_prog->name == NULL) {
enter_prog = (const event_prog_t*)&event_prog_table[PPME_GENERIC_E];
}
/* No programs other tail raw tracepoints are currently tail-called by the sys_enter
* dispatcher. */
if(enter_prog->prog_type == BPF_PROG_TYPE_RAW_TRACEPOINT) {
if(add_bpf_program_to_tail_table(syscall_enter_tail_table_fd,
enter_prog->name,
syscall_id)) {
goto clean_fill_syscalls_tail_table;
}

}

const event_prog_t* exit_prog = (const event_prog_t*)&event_prog_table[exit_event_type];
const char* exit_prog_name = exit_prog->name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as my previous comment on enter_prog_name, we probably don't need exit_prog_name.

Comment on lines +564 to +585
// static int detach(struct bpf_link **64_bit_prog_link, struct bpf_link **ia32_compat_prog_link,
// struct bpf_link **ia32_prog_link) { bpf_link if(openat_e && bpf_link__destroy(openat_e)) {
// pman_print_error("failed to detach the 'openat_e' program");
// return errno;
// }
// openat_e = NULL;
//
// if(ia32_openat_e && bpf_link__destroy(ia32_openat_e)) {
// pman_print_error("failed to detach the 'ia32_openat_e' program");
// return errno;
// }
// ia32_openat_e = NULL;
//
// if(ia32_compat_openat_e &&
// bpf_link__destroy(ia32_compat_openat_e)) {
// pman_print_error("failed to detach the 'ia32_compat_openat_e' program");
// return errno;
// }
// ia32_compat_openat_e = NULL;
//
// return 0;
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be removed?

@poiana
Copy link
Contributor

poiana commented Aug 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops, FedeDP, Molter73

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [FedeDP,Molter73,ekoops]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
Copy link
Contributor

poiana commented Aug 18, 2025

LGTM label has been added.

DetailsGit tree hash: 4b1523083605a63212a1ebdc9062be0e99a240a6

@ekoops
Copy link
Contributor Author

ekoops commented Aug 19, 2025

Closing in favor of #2581

@ekoops ekoops closed this Aug 19, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in Falco Roadmap Aug 19, 2025
@ekoops ekoops deleted the ekoops/isolate-modern-toctou branch August 19, 2025 10:09
@leogr leogr modified the milestones: 0.22.0, 9.0.0+driver Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants