-
Notifications
You must be signed in to change notification settings - Fork 168
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
RFC: new(modern_bpf): add security_file_mprotect #1601
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
51 changes: 51 additions & 0 deletions
51
driver/modern_bpf/programs/attached/events/security_file_mprotect.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,51 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
/* | ||
* Copyright (C) 2023 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. | ||
*/ | ||
|
||
/*=============================== ENTER EVENT ===========================*/ | ||
|
||
#include <helpers/interfaces/variable_size_event.h> | ||
#include <helpers/extract/extract_from_kernel.h> | ||
|
||
SEC("lsm/file_mprotect") | ||
int BPF_PROG(file_mprotect, | ||
struct vm_area_struct *vma, | ||
unsigned long reqprot, | ||
unsigned long prot, | ||
int ret) | ||
{ | ||
struct auxiliary_map *auxmap = auxmap__get(); | ||
if(!auxmap) | ||
{ | ||
return 0; | ||
} | ||
|
||
auxmap__preload_event_header(auxmap, PPME_LSM_SECURITY_FILE_MPROTECT_E); | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
|
||
/* Parameter 1: vm_start (PT_UINT64) */ | ||
unsigned long vm_start = extract__vm_start(vma); | ||
auxmap__store_u64_param(auxmap, vm_start); | ||
|
||
/* Parameter 2: vm_end (PT_UINT64) */ | ||
unsigned long vm_end = extract__vm_end(vma); | ||
auxmap__store_u64_param(auxmap, vm_end); | ||
|
||
/* Parameter 3: reqprot (type: PT_FLAGS32) */ | ||
auxmap__store_u32_param(auxmap, reqprot); | ||
|
||
/* Parameter 4: prot (type: PT_FLAGS32)*/ | ||
auxmap__store_u32_param(auxmap, prot); | ||
|
||
/*=============================== COLLECT PARAMETERS ===========================*/ | ||
//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
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
69 changes: 69 additions & 0 deletions
69
test/drivers/test_suites/generic_tracepoints_suite/security_file_mprotect.cpp
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,69 @@ | ||
#include "../../event_class/event_class.h" | ||
#include "../../helpers/proc_parsing.h" | ||
|
||
#if defined(__NR_mprotect) | ||
|
||
#include <linux/sched.h> | ||
#include <sys/mman.h> | ||
|
||
TEST(GenericTracepoints, security_file_mprotect) | ||
{ | ||
auto evt_test = get_syscall_event_test(__NR_execve, EXIT_EVENT); | ||
|
||
evt_test->enable_capture(); | ||
|
||
/*=============================== TRIGGER SYSCALL ===========================*/ | ||
|
||
char buffer[1024]; | ||
int ret = syscall(__NR_mprotect, buffer, 1024, PROT_READ); | ||
if (ret < 0) | ||
{ | ||
exit(EXIT_FAILURE); | ||
} | ||
assert_syscall_state(SYSCALL_SUCCESS, "mprotect", ret, NOT_EQUAL, -1); | ||
|
||
evt_test->disable_capture(); | ||
|
||
evt_test->assert_event_presence(ret); | ||
|
||
/*=============================== TRIGGER SYSCALL ===========================*/ | ||
|
||
evt_test->disable_capture(); | ||
|
||
/* We search for a child event. */ | ||
evt_test->assert_event_presence(ret); | ||
|
||
if(HasFatalFailure()) | ||
{ | ||
return; | ||
} | ||
|
||
evt_test->parse_event(); | ||
|
||
evt_test->assert_header(); | ||
|
||
/*=============================== ASSERT PARAMETERS ===========================*/ | ||
|
||
/* Please note here we cannot assert all the params, we check only the possible ones. */ | ||
|
||
/* Parameter 1: res (type: PT_ERRNO)*/ | ||
evt_test->assert_numeric_param(1, (int64_t)0); | ||
|
||
/* Parameter 2: addr_start (type: PT_UINT64) */ | ||
evt_test->assert_only_param_len(2, sizeof(uint64_t)); | ||
|
||
/* Parameter 3: addr_end (type: PT_UINT64) */ | ||
evt_test->assert_only_param_len(3, sizeof(uint64_t)); | ||
|
||
/* Parameter 4: reqprot (type: PT_FLAGS32) */ | ||
evt_test->assert_numeric_param(4, (int32_t)PROT_READ); | ||
|
||
/* Parameter 5: prot (type: PT_FLAGS32) */ | ||
evt_test->assert_numeric_param(5, (int32_t)PROT_READ); | ||
|
||
/*=============================== ASSERT PARAMETERS ===========================*/ | ||
|
||
evt_test->assert_num_params_pushed(5); | ||
} | ||
|
||
#endif |
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.
The auxmap API is wrong (we should be using fixed-size ringbuf), but to illustrate the problem I'm facing, let's just go with this for now.
If this line is not commented out, the verifier fails:
Rather than digging deeper into this now, could I get a sanity check to see if this is the correct approach generally given the guidance in #963? @FedeDP
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.
I agree with this approach; i don't know why this is failing though ;)
Anyway, as shared privately, we surely need more work to understand how to integrate LSM/kprobes inside current libs architecture:
In the end, there are multiple questions looking for a good answer before we can start.
Hopefully maintainers will share some proposals soonish :)