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

RFE: Use a binary tree for large filters #152

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions include/seccomp.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ enum scmp_filter_attr {
SCMP_FLTATR_API_TSKIP = 5, /**< allow rules with a -1 syscall */
SCMP_FLTATR_CTL_LOG = 6, /**< log not-allowed actions */
SCMP_FLTATR_CTL_SSB = 7, /**< disable SSB mitigation */
SCMP_FLTATR_CTL_OPTIMIZE = 8, /**< filter optimization level: (DEFAULT = 1)
* 0 - currently unused
* 1 - rules weighted by priority and complexity
* 2 - binary tree sorted by syscall number
*/
_SCMP_FLTATR_MAX,
};

Expand Down
17 changes: 17 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ static void _db_reset(struct db_filter *db)
}
db->syscalls = NULL;
}
db->syscall_cnt = 0;

/* free any rules */
if (db->rules != NULL) {
Expand Down Expand Up @@ -1069,6 +1070,7 @@ int db_col_reset(struct db_filter_col *col, uint32_t def_action)
col->attr.api_tskip = 0;
col->attr.log_enable = 0;
col->attr.spec_allow = 0;
col->attr.optimize = 1;

/* set the state */
col->state = _DB_STA_VALID;
Expand Down Expand Up @@ -1311,6 +1313,9 @@ int db_col_attr_get(const struct db_filter_col *col,
case SCMP_FLTATR_CTL_SSB:
*value = col->attr.spec_allow;
break;
case SCMP_FLTATR_CTL_OPTIMIZE:
*value = col->attr.optimize;
break;
default:
rc = -EEXIST;
break;
Expand Down Expand Up @@ -1386,6 +1391,17 @@ int db_col_attr_set(struct db_filter_col *col,
rc = -EOPNOTSUPP;
}
break;
case SCMP_FLTATR_CTL_OPTIMIZE:
switch (value) {
case 1:
drakenclimber marked this conversation as resolved.
Show resolved Hide resolved
case 2:
col->attr.optimize = value;
break;
default:
rc = -EOPNOTSUPP;
break;
}
break;
default:
rc = -EEXIST;
break;
Expand Down Expand Up @@ -2052,6 +2068,7 @@ int db_rule_add(struct db_filter *db, const struct db_api_rule_list *rule)
s_new->next = db->syscalls;
db->syscalls = s_new;
}
db->syscall_cnt++;
return 0;
} else if (s_iter->chains == NULL) {
if (rm_flag || !s_iter->valid) {
Expand Down
3 changes: 3 additions & 0 deletions src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ struct db_filter_attr {
uint32_t log_enable;
/* SPEC_ALLOW related attributes */
uint32_t spec_allow;
/* SCMP_FLTATR_CTL_OPTIMIZE related attributes */
uint32_t optimize;
};

struct db_filter {
Expand All @@ -126,6 +128,7 @@ struct db_filter {

/* syscall filters, kept as a sorted single-linked list */
struct db_sys_list *syscalls;
unsigned int syscall_cnt;

/* list of rules used to build the filters, kept in order */
struct db_api_rule_list *rules;
Expand Down
Loading