Skip to content
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

(RHEL-5991) Do not assign badness to filtered-out syscalls #399

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions src/analyze/analyze-security.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,35 +476,36 @@ static int assess_system_call_architectures(
return 0;
}

static bool syscall_names_in_filter(Set *s, bool whitelist, const SyscallFilterSet *f) {
static bool syscall_names_in_filter(Set *s, bool whitelist, const SyscallFilterSet *f, const char **ret_offending_syscall) {
const char *syscall;

NULSTR_FOREACH(syscall, f->value) {
bool b;
int id;

if (syscall[0] == '@') {
const SyscallFilterSet *g;
assert_se(g = syscall_filter_set_find(syscall));
b = syscall_names_in_filter(s, whitelist, g);
} else {
#if HAVE_SECCOMP
int id;

/* Let's see if the system call actually exists on this platform, before complaining */
id = seccomp_syscall_resolve_name(syscall);
if (id < 0)
continue;
#endif
assert_se(g = syscall_filter_set_find(syscall));
if (syscall_names_in_filter(s, whitelist, g, ret_offending_syscall))
return true; /* bad! */

b = set_contains(s, syscall);
continue;
}

if (whitelist == b) {
/* Let's see if the system call actually exists on this platform, before complaining */
id = seccomp_syscall_resolve_name(syscall);
if (id < 0)
continue;

if (set_contains(s, syscall) == whitelist) {
log_debug("Offending syscall filter item: %s", syscall);
if (ret_offending_syscall)
*ret_offending_syscall = syscall;
return true; /* bad! */
}
}

*ret_offending_syscall = NULL;
return false;
}

Expand All @@ -515,43 +516,47 @@ static int assess_system_call_filter(
uint64_t *ret_badness,
char **ret_description) {

const SyscallFilterSet *f;
char *d = NULL;
uint64_t b;

assert(a);
assert(info);
assert(ret_badness);
assert(ret_description);

assert(a->parameter < _SYSCALL_FILTER_SET_MAX);
f = syscall_filter_sets + a->parameter;
const SyscallFilterSet *f = syscall_filter_sets + a->parameter;

char *d = NULL;
uint64_t b;

if (!info->system_call_filter_whitelist && set_isempty(info->system_call_filter)) {
d = strdup("Service does not filter system calls");
b = 10;
} else {
bool bad;
const char *offender = NULL;

log_debug("Analyzing system call filter, checking against: %s", f->name);
bad = syscall_names_in_filter(info->system_call_filter, info->system_call_filter_whitelist, f);
bad = syscall_names_in_filter(info->system_call_filter, info->system_call_filter_whitelist, f, &offender);
log_debug("Result: %s", bad ? "bad" : "good");

if (info->system_call_filter_whitelist) {
if (bad) {
(void) asprintf(&d, "System call whitelist defined for service, and %s is included", f->name);
(void) asprintf(&d, "System call whitelist defined for service, and %s is included "
"(e.g. %s is allowed)",
f->name, offender);
b = 9;
} else {
(void) asprintf(&d, "System call whitelist defined for service, and %s is not included", f->name);
b = 0;
}
} else {
if (bad) {
(void) asprintf(&d, "System call blacklist defined for service, and %s is not included", f->name);
(void) asprintf(&d, "System call blacklist defined for service, and %s is not included "
"(e.g. %s is allowed)",
f->name, offender);
b = 10;
} else {
(void) asprintf(&d, "System call blacklist defined for service, and %s is included", f->name);
b = 5;
b = 0;
}
}
}
Expand Down