-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(driver): support process_vm_readv and process_vm_writev syscalls #1675
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70b3420
feat(driver): add support for process_vm syscalls
therealbobo 720ed41
fix(driver): don't push redundant size with process_vm syscall
therealbobo 3cd30e3
chore(driver): bump schema version
therealbobo 2b0bbfe
fix(test/drivers): wait the right pid
therealbobo a34d576
fix(driver): set appropriate schema version
therealbobo 89d029b
fix(test/drivers): write on parent memory
therealbobo cea9725
fix(driver): always retrieve the local iov
therealbobo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.15.1 | ||
2.16.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...r/modern_bpf/programs/tail_called/events/syscall_dispatched_events/process_vm_readv.bpf.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
/* | ||
* Copyright (C) 2024 The Falco Authors. | ||
* | ||
* This file is dual licensed under either the MIT or GPL 2. See MIT.txt | ||
* or GPL2.txt for full copies of the license. | ||
*/ | ||
|
||
#include <helpers/interfaces/fixed_size_event.h> | ||
#include <helpers/interfaces/variable_size_event.h> | ||
|
||
/*=============================== ENTER EVENT ===========================*/ | ||
|
||
SEC("tp_btf/sys_enter") | ||
int BPF_PROG(process_vm_readv_e, | ||
struct pt_regs *regs, | ||
long id) | ||
{ | ||
struct ringbuf_struct ringbuf; | ||
if(!ringbuf__reserve_space(&ringbuf, ctx, PROCESS_VM_READV_E_SIZE, PPME_SYSCALL_PROCESS_VM_READV_E)) | ||
{ | ||
return 0; | ||
} | ||
|
||
ringbuf__store_event_header(&ringbuf); | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
// Here we have no parameters to collect. | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
ringbuf__submit_event(&ringbuf); | ||
|
||
return 0; | ||
} | ||
|
||
/*=============================== ENTER EVENT ===========================*/ | ||
|
||
/*=============================== EXIT EVENT ===========================*/ | ||
|
||
SEC("tp_btf/sys_exit") | ||
int BPF_PROG(process_vm_readv_x, | ||
struct pt_regs *regs, | ||
long ret) | ||
{ | ||
struct auxiliary_map *auxmap = auxmap__get(); | ||
if(!auxmap) | ||
{ | ||
return 0; | ||
} | ||
|
||
auxmap__preload_event_header(auxmap, PPME_SYSCALL_PROCESS_VM_READV_X); | ||
|
||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
/* Parameter 1: res (type: PT_INT64) */ | ||
auxmap__store_s64_param(auxmap, ret); | ||
|
||
/* Parameter 2: pid (type: PT_PID) */ | ||
int64_t pid = extract__syscall_argument(regs, 0); | ||
auxmap__store_s64_param(auxmap, pid); | ||
|
||
if(ret > 0) | ||
{ | ||
/* We read the minimum between `snaplen` and what we really | ||
* have in the buffer. | ||
*/ | ||
uint16_t snaplen = maps__get_snaplen(); | ||
apply_dynamic_snaplen(regs, &snaplen, true); | ||
if(snaplen > ret) | ||
{ | ||
snaplen = ret; | ||
} | ||
|
||
unsigned long iov_pointer = extract__syscall_argument(regs, 1); | ||
unsigned long iov_cnt = extract__syscall_argument(regs, 2); | ||
|
||
/* Parameter 3: data (type: PT_BYTEBUF) */ | ||
auxmap__store_iovec_data_param(auxmap, iov_pointer, iov_cnt, snaplen); | ||
} | ||
else | ||
{ | ||
/* Parameter 3: data (type: PT_BYTEBUF) */ | ||
auxmap__store_empty_param(auxmap); | ||
} | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
auxmap__finalize_event_header(auxmap); | ||
|
||
auxmap__submit_event(auxmap, ctx); | ||
|
||
return 0; | ||
} | ||
|
||
/*=============================== EXIT EVENT ===========================*/ |
98 changes: 98 additions & 0 deletions
98
.../modern_bpf/programs/tail_called/events/syscall_dispatched_events/process_vm_writev.bpf.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
/* | ||
* Copyright (C) 2024 The Falco Authors. | ||
* | ||
* This file is dual licensed under either the MIT or GPL 2. See MIT.txt | ||
* or GPL2.txt for full copies of the license. | ||
*/ | ||
|
||
#include <helpers/interfaces/fixed_size_event.h> | ||
#include <helpers/interfaces/variable_size_event.h> | ||
|
||
/*=============================== ENTER EVENT ===========================*/ | ||
|
||
SEC("tp_btf/sys_enter") | ||
int BPF_PROG(process_vm_writev_e, | ||
struct pt_regs *regs, | ||
long id) | ||
{ | ||
struct ringbuf_struct ringbuf; | ||
if(!ringbuf__reserve_space(&ringbuf, ctx, PROCESS_VM_WRITEV_E_SIZE, PPME_SYSCALL_PROCESS_VM_WRITEV_E)) | ||
{ | ||
return 0; | ||
} | ||
|
||
ringbuf__store_event_header(&ringbuf); | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
// Here we have no parameters to collect. | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
ringbuf__submit_event(&ringbuf); | ||
|
||
return 0; | ||
} | ||
|
||
/*=============================== ENTER EVENT ===========================*/ | ||
|
||
/*=============================== EXIT EVENT ===========================*/ | ||
|
||
SEC("tp_btf/sys_exit") | ||
int BPF_PROG(process_vm_writev_x, | ||
struct pt_regs *regs, | ||
long ret) | ||
{ | ||
struct auxiliary_map *auxmap = auxmap__get(); | ||
if(!auxmap) | ||
{ | ||
return 0; | ||
} | ||
|
||
auxmap__preload_event_header(auxmap, PPME_SYSCALL_PROCESS_VM_WRITEV_X); | ||
|
||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
/* Parameter 1: res (type: PT_INT64) */ | ||
auxmap__store_s64_param(auxmap, ret); | ||
|
||
/* Parameter 2: pid (type: PT_PID) */ | ||
int64_t pid = extract__syscall_argument(regs, 0); | ||
auxmap__store_s64_param(auxmap, pid); | ||
|
||
if(ret > 0) | ||
{ | ||
/* We read the minimum between `snaplen` and what we really | ||
* have in the buffer. | ||
*/ | ||
uint16_t snaplen = maps__get_snaplen(); | ||
apply_dynamic_snaplen(regs, &snaplen, true); | ||
if(snaplen > ret) | ||
{ | ||
snaplen = ret; | ||
} | ||
|
||
unsigned long iov_pointer = extract__syscall_argument(regs, 1); | ||
unsigned long iov_cnt = extract__syscall_argument(regs, 2); | ||
|
||
//* Parameter 3: data (type: PT_BYTEBUF) */ | ||
auxmap__store_iovec_data_param(auxmap, iov_pointer, iov_cnt, snaplen); | ||
} | ||
else | ||
{ | ||
/* Parameter 3: data (type: PT_BYTEBUF) */ | ||
auxmap__store_empty_param(auxmap); | ||
} | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
auxmap__finalize_event_header(auxmap); | ||
|
||
auxmap__submit_event(auxmap, ctx); | ||
|
||
return 0; | ||
} | ||
|
||
/*=============================== EXIT EVENT ===========================*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in the other syscall, otherwise cases with
-1
won't be handled