Skip to content

Commit f83fef9

Browse files
committed
api: Add 2 fltatrs for managing unknown syscalls
Add two new filter attributes, SCMP_FLTATR_ACT_ENOSYS and SCMP_FLTATR_CTL_KVER. When SCMP_FLTATR_CTL_KVERMAX is set, then libseccomp will handle syscalls as follows: * syscalls with explicit actions set by the user will behave as before * syscalls that are not explicitly called out by the user's filter but are valid for the specified kernel version will return the default filter action (SCMP_FLTATR_ACT_DEFAULT). * syscalls that are newer than the specified kernel version will return the unknown filter action (SCMP_FLTATR_ACT_ENOSYS) Note that setting the SCMP_FLTATR_CTL_KVERMAX can result in large seccomp BPF filters. It's recommended to also enable the binary tree optimization (SCMP_FLTATR_CTL_OPTIMIZE = 2) to speed up filter traversal in the kernel. Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
1 parent 386149e commit f83fef9

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

include/seccomp.h.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ enum scmp_filter_attr {
7979
*/
8080
SCMP_FLTATR_API_SYSRAWRC = 9, /**< return the system return codes */
8181
SCMP_FLTATR_CTL_WAITKILL = 10, /**< request wait killable semantics */
82+
SCMP_FLTATR_ACT_ENOSYS = 11, /**< action to take when an unknown
83+
* (newer than this filter) syscall is
84+
* invoked. Must be used in conjunction
85+
* with SCMP_FLTATR_CTL_KVER
86+
*/
87+
SCMP_FLTATR_CTL_KVERMAX = 12, /**< maximum kernel version understood
88+
* by the user application. syscalls
89+
* from newer kernel versions will
90+
* return with the action in
91+
* SCMP_FLTATR_ACT_UNKNOWN
92+
*/
8293
_SCMP_FLTATR_MAX,
8394
};
8495

src/db.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,8 @@ int db_col_reset(struct db_filter_col *col, uint32_t def_action)
10731073
col->attr.optimize = 1;
10741074
col->attr.api_sysrawrc = 0;
10751075
col->attr.wait_killable_recv = 0;
1076+
col->attr.act_enosys = SCMP_ACT_ERRNO(38);
1077+
col->attr.kvermax = SCMP_KV_UNDEF;
10761078

10771079
/* set the state */
10781080
col->state = _DB_STA_VALID;
@@ -1333,6 +1335,12 @@ int db_col_attr_get(const struct db_filter_col *col,
13331335
case SCMP_FLTATR_CTL_WAITKILL:
13341336
*value = col->attr.wait_killable_recv;
13351337
break;
1338+
case SCMP_FLTATR_ACT_ENOSYS:
1339+
*value = col->attr.act_enosys;
1340+
break;
1341+
case SCMP_FLTATR_CTL_KVERMAX:
1342+
*value = col->attr.kvermax;
1343+
break;
13361344
default:
13371345
rc = -EINVAL;
13381346
break;
@@ -1449,6 +1457,18 @@ int db_col_attr_set(struct db_filter_col *col,
14491457
case SCMP_FLTATR_CTL_WAITKILL:
14501458
col->attr.wait_killable_recv = (value ? 1 : 0);
14511459
break;
1460+
case SCMP_FLTATR_ACT_ENOSYS:
1461+
if (db_col_action_valid(col, value) == 0)
1462+
col->attr.act_enosys = value;
1463+
else
1464+
return -EINVAL;
1465+
db_col_precompute_reset(col);
1466+
break;
1467+
case SCMP_FLTATR_CTL_KVERMAX:
1468+
if (value <= SCMP_KV_UNDEF || value >=__SCMP_KV_MAX)
1469+
return -EINVAL;
1470+
col->attr.kvermax = value;
1471+
break;
14521472
default:
14531473
rc = -EINVAL;
14541474
break;

src/db.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ struct db_filter_attr {
126126
uint32_t api_sysrawrc;
127127
/* request SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV */
128128
uint32_t wait_killable_recv;
129+
/*
130+
* action to take if an unknown (newer than this filter) syscall is
131+
* invoked
132+
*/
133+
uint32_t act_enosys;
134+
/* maximum kernel version understood by the userspace program */
135+
uint32_t kvermax;
129136
};
130137

131138
struct db_filter {

src/python/libseccomp.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ cdef extern from "seccomp.h":
6666
SCMP_FLTATR_CTL_OPTIMIZE
6767
SCMP_FLTATR_API_SYSRAWRC
6868
SCMP_FLTATR_CTL_WAITKILL
69+
SCMP_FLTATR_ACT_ENOSYS
70+
SCMP_FLTATR_CTL_KVERMAX
6971

7072
cdef enum scmp_compare:
7173
SCMP_CMP_NE

src/python/seccomp.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ cdef class Attr:
334334
2: binary tree sorted by syscall number
335335
API_SYSRAWRC - return the raw syscall codes
336336
CTL_WAITKILL - request wait killable semantics
337+
ACT_ENOSYS - set the action to take for unknown (too new) syscalls
338+
CTL_KVERMAX - the newest kernel version understood by the user application
337339
"""
338340
ACT_DEFAULT = libseccomp.SCMP_FLTATR_ACT_DEFAULT
339341
ACT_BADARCH = libseccomp.SCMP_FLTATR_ACT_BADARCH
@@ -345,6 +347,8 @@ cdef class Attr:
345347
CTL_OPTIMIZE = libseccomp.SCMP_FLTATR_CTL_OPTIMIZE
346348
API_SYSRAWRC = libseccomp.SCMP_FLTATR_API_SYSRAWRC
347349
CTL_WAITKILL = libseccomp.SCMP_FLTATR_CTL_WAITKILL
350+
ACT_ENOSYS = libseccomp.SCMP_FLTATR_ACT_ENOSYS
351+
CTL_KVERMAX = libseccomp.SCMP_FLTATR_CTL_KVERMAX
348352

349353
cdef class Arg:
350354
""" Python object representing a SyscallFilter syscall argument.

0 commit comments

Comments
 (0)