-
Notifications
You must be signed in to change notification settings - Fork 188
RFE: expose improved kernel logging features through libseccomp #92
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
Changes from all commits
5e4906f
3ecc145
f9caff0
a1fbec2
01bce1b
9ae3954
91558fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ cdef extern from "seccomp.h": | |
| SCMP_FLTATR_CTL_NNP | ||
| SCMP_FLTATR_CTL_TSYNC | ||
| SCMP_FLTATR_API_TSKIP | ||
| SCMP_FLTATR_CTL_LOG | ||
|
|
||
| cdef enum scmp_compare: | ||
| SCMP_CMP_NE | ||
|
|
@@ -70,6 +71,7 @@ cdef extern from "seccomp.h": | |
| cdef enum: | ||
| SCMP_ACT_KILL | ||
| SCMP_ACT_TRAP | ||
| SCMP_ACT_LOG | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you looked at the golang bindings?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and I will be submitting a PR against libseccomp-golang once the dust settles on this PR. |
||
| SCMP_ACT_ALLOW | ||
| unsigned int SCMP_ACT_ERRNO(int errno) | ||
| unsigned int SCMP_ACT_TRACE(int value) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,8 @@ | |
| static int _nr_seccomp = -1; | ||
| static int _support_seccomp_syscall = -1; | ||
| static int _support_seccomp_flag_tsync = -1; | ||
| static int _support_seccomp_flag_log = -1; | ||
| static int _support_seccomp_action_log = -1; | ||
|
|
||
| /** | ||
| * Check to see if the seccomp() syscall is supported | ||
|
|
@@ -111,6 +113,78 @@ void sys_set_seccomp_syscall(bool enable) | |
| _support_seccomp_syscall = (enable ? 1 : 0); | ||
| } | ||
|
|
||
| /** | ||
| * Check to see if a seccomp action is supported | ||
| * @param action the seccomp action | ||
| * | ||
| * This function checks to see if a seccomp action is supported by the system. | ||
| * Return one if the action is supported, zero otherwise. | ||
| * | ||
| */ | ||
| int sys_chk_seccomp_action(uint32_t action) | ||
| { | ||
| if (action == SCMP_ACT_KILL) { | ||
| return 1; | ||
| } else if (action == SCMP_ACT_TRAP) { | ||
| return 1; | ||
| } else if ((action == SCMP_ACT_ERRNO(action & 0x0000ffff)) && | ||
| ((action & 0x0000ffff) < MAX_ERRNO)) { | ||
| return 1; | ||
| } else if (action == SCMP_ACT_TRACE(action & 0x0000ffff)) { | ||
| return 1; | ||
| } else if (action == SCMP_ACT_LOG) { | ||
| if (_support_seccomp_action_log < 0) { | ||
| if (sys_chk_seccomp_syscall() == 1 && | ||
| syscall(_nr_seccomp, SECCOMP_GET_ACTION_AVAIL, 0, | ||
| &action) == 0) | ||
| _support_seccomp_action_log = 1; | ||
| else | ||
| _support_seccomp_action_log = 0; | ||
| } | ||
|
|
||
| return _support_seccomp_action_log; | ||
| } else if (action == SCMP_ACT_ALLOW) { | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Force a seccomp action support setting | ||
| * @param action the seccomp action | ||
| * @param enable the intended support state | ||
| * | ||
| * This function overrides the current seccomp action support setting; this | ||
| * is very much a "use at your own risk" function. | ||
| */ | ||
| void sys_set_seccomp_action(uint32_t action, bool enable) | ||
| { | ||
| if (action == SCMP_ACT_LOG) | ||
| _support_seccomp_action_log = (enable ? 1 : 0); | ||
| } | ||
|
|
||
| /** | ||
| * Check to see if a seccomp() flag is supported by the kernel | ||
| * @param flag the seccomp() flag | ||
| * | ||
| * This function checks to see if a seccomp() flag is supported by the kernel. | ||
| * Return one if the flag is supported, zero otherwise. | ||
| * | ||
| */ | ||
| static int _sys_chk_seccomp_flag_kernel(int flag) | ||
| { | ||
| /* this is an invalid seccomp(2) call because the last argument | ||
| * is NULL, but depending on the errno value of EFAULT we can | ||
| * guess if the filter flag is supported or not */ | ||
| if (sys_chk_seccomp_syscall() == 1 && | ||
| syscall(_nr_seccomp, SECCOMP_SET_MODE_FILTER, flag, NULL) == -1 && | ||
| errno == EFAULT) | ||
| return 1; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Check to see if a seccomp() flag is supported | ||
| * @param flag the seccomp() flag | ||
|
|
@@ -122,15 +196,17 @@ void sys_set_seccomp_syscall(bool enable) | |
| */ | ||
| int sys_chk_seccomp_flag(int flag) | ||
| { | ||
| int rc; | ||
|
|
||
| switch (flag) { | ||
| case SECCOMP_FILTER_FLAG_TSYNC: | ||
| if (_support_seccomp_flag_tsync < 0) { | ||
| rc = sys_chk_seccomp_syscall(); | ||
| _support_seccomp_flag_tsync = (rc == 1 ? 1 : 0); | ||
| } | ||
| if (_support_seccomp_flag_tsync < 0) | ||
| _support_seccomp_flag_tsync = _sys_chk_seccomp_flag_kernel(flag); | ||
|
|
||
| return _support_seccomp_flag_tsync; | ||
| case SECCOMP_FILTER_FLAG_LOG: | ||
| if (_support_seccomp_flag_log < 0) | ||
| _support_seccomp_flag_log = _sys_chk_seccomp_flag_kernel(flag); | ||
|
|
||
| return _support_seccomp_flag_log; | ||
| } | ||
|
|
||
| return -EOPNOTSUPP; | ||
|
|
@@ -151,6 +227,9 @@ void sys_set_seccomp_flag(int flag, bool enable) | |
| case SECCOMP_FILTER_FLAG_TSYNC: | ||
| _support_seccomp_flag_tsync = (enable ? 1 : 0); | ||
| break; | ||
| case SECCOMP_FILTER_FLAG_LOG: | ||
| _support_seccomp_flag_log = (enable ? 1 : 0); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -184,7 +263,9 @@ int sys_filter_load(const struct db_filter_col *col) | |
| if (sys_chk_seccomp_syscall() == 1) { | ||
| int flgs = 0; | ||
| if (col->attr.tsync_enable) | ||
| flgs = SECCOMP_FILTER_FLAG_TSYNC; | ||
| flgs |= SECCOMP_FILTER_FLAG_TSYNC; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just merge this patch into the other patch, there really is no reason for this to be a standalone commit. |
||
| if (col->attr.log_enable) | ||
| flgs |= SECCOMP_FILTER_FLAG_LOG; | ||
| rc = syscall(_nr_seccomp, SECCOMP_SET_MODE_FILTER, flgs, prgm); | ||
| if (rc > 0 && col->attr.tsync_enable) | ||
| /* always return -ESRCH if we fail to sync threads */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,15 +102,28 @@ typedef struct sock_filter bpf_instr_raw; | |
| #ifndef SECCOMP_SET_MODE_FILTER | ||
| #define SECCOMP_SET_MODE_FILTER 1 | ||
| #endif | ||
| #ifndef SECCOMP_GET_ACTION_AVAIL | ||
| #define SECCOMP_GET_ACTION_AVAIL 2 | ||
| #endif | ||
|
|
||
| /* flags for the seccomp() syscall */ | ||
| #ifndef SECCOMP_FILTER_FLAG_TSYNC | ||
| #define SECCOMP_FILTER_FLAG_TSYNC 1 | ||
| #endif | ||
| #ifndef SECCOMP_FILTER_FLAG_LOG | ||
| #define SECCOMP_FILTER_FLAG_LOG 2 | ||
| #endif | ||
|
|
||
| #ifndef SECCOMP_RET_LOG | ||
| #define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */ | ||
| #endif | ||
|
|
||
| int sys_chk_seccomp_syscall(void); | ||
| void sys_set_seccomp_syscall(bool enable); | ||
|
|
||
| int sys_chk_seccomp_action(uint32_t action); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also wondering if we need a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do need one. It gets added in the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ha, found it later in the patchset. It probably should be included here, but not the end of the world.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like you're not requiring the patchset surgery needed to move |
||
| void sys_set_seccomp_action(uint32_t action, bool enable); | ||
|
|
||
| int sys_chk_seccomp_flag(int flag); | ||
| void sys_set_seccomp_flag(int flag, bool enable); | ||
|
|
||
|
|
||
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.
Another
make check-syntaxquestion, does it allow these curly braces?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.
Yes, it does.