Skip to content

Commit 702434c

Browse files
committed
api: add the SCMP_FLTATR_CTL_WAITKILL filter attribute
The SCMP_FLTATR_CTL_WAITKILL attribute requests that the SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV flag be passed to the seccomp(2) system call when possible, which is currently only when the SECCOMP_FILTER_FLAG_NEW_LISTENER flag is also set. Signed-off-by: Paul Moore <[email protected]>
1 parent e797591 commit 702434c

File tree

10 files changed

+49
-1
lines changed

10 files changed

+49
-1
lines changed

doc/man/man3/seccomp_attr_set.3

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "seccomp_attr_set" 3 "06 June 2020" "[email protected]" "libseccomp Documentation"
1+
.TH "seccomp_attr_set" 3 "21 September 2022" "[email protected]" "libseccomp Documentation"
22
.\" //////////////////////////////////////////////////////////////////////////
33
.SH NAME
44
.\" //////////////////////////////////////////////////////////////////////////
@@ -132,6 +132,12 @@ A flag to specify if libseccomp should pass system error codes back to the
132132
caller instead of the default -ECANCELED. Defaults to off
133133
.RI ( value
134134
== 0).
135+
.TP
136+
.B SCMP_FLTATR_CTL_WAITKILL
137+
A flag to specify if libseccomp should request wait killable semantics when
138+
possible. Defaults to off
139+
.RI ( value
140+
== 0).
135141
.\" //////////////////////////////////////////////////////////////////////////
136142
.SH RETURN VALUE
137143
.\" //////////////////////////////////////////////////////////////////////////

include/seccomp.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum scmp_filter_attr {
7878
* number
7979
*/
8080
SCMP_FLTATR_API_SYSRAWRC = 9, /**< return the system return codes */
81+
SCMP_FLTATR_CTL_WAITKILL = 10, /**< request wait killable semantics */
8182
_SCMP_FLTATR_MAX,
8283
};
8384

src/db.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ int db_col_reset(struct db_filter_col *col, uint32_t def_action)
10721072
col->attr.spec_allow = 0;
10731073
col->attr.optimize = 1;
10741074
col->attr.api_sysrawrc = 0;
1075+
col->attr.wait_killable_recv = 0;
10751076

10761077
/* set the state */
10771078
col->state = _DB_STA_VALID;
@@ -1331,6 +1332,9 @@ int db_col_attr_get(const struct db_filter_col *col,
13311332
case SCMP_FLTATR_API_SYSRAWRC:
13321333
*value = col->attr.api_sysrawrc;
13331334
break;
1335+
case SCMP_FLTATR_CTL_WAITKILL:
1336+
*value = col->attr.wait_killable_recv;
1337+
break;
13341338
default:
13351339
rc = -EINVAL;
13361340
break;
@@ -1444,6 +1448,9 @@ int db_col_attr_set(struct db_filter_col *col,
14441448
case SCMP_FLTATR_API_SYSRAWRC:
14451449
col->attr.api_sysrawrc = (value ? 1 : 0);
14461450
break;
1451+
case SCMP_FLTATR_CTL_WAITKILL:
1452+
col->attr.wait_killable_recv = (value ? 1 : 0);
1453+
break;
14471454
default:
14481455
rc = -EINVAL;
14491456
break;

src/db.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ struct db_filter_attr {
124124
uint32_t optimize;
125125
/* return the raw system return codes */
126126
uint32_t api_sysrawrc;
127+
/* request SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV */
128+
uint32_t wait_killable_recv;
127129
};
128130

129131
struct db_filter {

src/python/libseccomp.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ cdef extern from "seccomp.h":
6363
SCMP_FLTATR_CTL_SSB
6464
SCMP_FLTATR_CTL_OPTIMIZE
6565
SCMP_FLTATR_API_SYSRAWRC
66+
SCMP_FLTATR_CTL_WAITKILL
6667

6768
cdef enum scmp_compare:
6869
SCMP_CMP_NE

src/python/seccomp.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ cdef class Attr:
325325
1: rules weighted by priority and complexity (DEFAULT)
326326
2: binary tree sorted by syscall number
327327
API_SYSRAWRC - return the raw syscall codes
328+
CTL_WAITKILL - request wait killable semantics
328329
"""
329330
ACT_DEFAULT = libseccomp.SCMP_FLTATR_ACT_DEFAULT
330331
ACT_BADARCH = libseccomp.SCMP_FLTATR_ACT_BADARCH
@@ -335,6 +336,7 @@ cdef class Attr:
335336
CTL_SSB = libseccomp.SCMP_FLTATR_CTL_SSB
336337
CTL_OPTIMIZE = libseccomp.SCMP_FLTATR_CTL_OPTIMIZE
337338
API_SYSRAWRC = libseccomp.SCMP_FLTATR_API_SYSRAWRC
339+
CTL_WAITKILL = libseccomp.SCMP_FLTATR_CTL_WAITKILL
338340

339341
cdef class Arg:
340342
""" Python object representing a SyscallFilter syscall argument.

src/system.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct task_state {
5858
int sup_flag_new_listener;
5959
int sup_user_notif;
6060
int sup_flag_tsync_esrch;
61+
int sup_flag_wait_kill;
6162
};
6263
static struct task_state state = {
6364
.nr_seccomp = -1,
@@ -73,6 +74,7 @@ static struct task_state state = {
7374
.sup_flag_new_listener = -1,
7475
.sup_user_notif = -1,
7576
.sup_flag_tsync_esrch = -1,
77+
.sup_flag_wait_kill = -1,
7678
};
7779

7880
/**
@@ -307,6 +309,10 @@ int sys_chk_seccomp_flag(int flag)
307309
if (state.sup_flag_tsync_esrch < 0)
308310
state.sup_flag_tsync_esrch = _sys_chk_flag_kernel(flag);
309311
return state.sup_flag_tsync_esrch;
312+
case SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV:
313+
if (state.sup_flag_wait_kill < 0)
314+
state.sup_flag_wait_kill = _sys_chk_flag_kernel(flag);
315+
return state.sup_flag_wait_kill;
310316
}
311317

312318
return -EOPNOTSUPP;
@@ -339,6 +345,9 @@ void sys_set_seccomp_flag(int flag, bool enable)
339345
case SECCOMP_FILTER_FLAG_TSYNC_ESRCH:
340346
state.sup_flag_tsync_esrch = (enable ? 1 : 0);
341347
break;
348+
case SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV:
349+
state.sup_flag_wait_kill = (enable ? 1 : 0);
350+
break;
342351
}
343352
}
344353

@@ -394,6 +403,9 @@ int sys_filter_load(struct db_filter_col *col, bool rawrc)
394403
flgs |= SECCOMP_FILTER_FLAG_TSYNC;
395404
} else if (listener_req)
396405
flgs |= SECCOMP_FILTER_FLAG_NEW_LISTENER;
406+
if ((flgs & SECCOMP_FILTER_FLAG_NEW_LISTENER) &&
407+
col->attr.wait_killable_recv)
408+
flgs |= SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV;
397409
if (col->attr.log_enable)
398410
flgs |= SECCOMP_FILTER_FLAG_LOG;
399411
if (col->attr.spec_allow)

src/system.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ typedef struct sock_filter bpf_instr_raw;
138138
#ifndef SECCOMP_FILTER_FLAG_TSYNC_ESRCH
139139
#define SECCOMP_FILTER_FLAG_TSYNC_ESRCH (1UL << 4)
140140
#endif
141+
#ifndef SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV
142+
#define SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV (1UL << 5)
143+
#endif
141144

142145
#ifndef SECCOMP_RET_LOG
143146
#define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */

tests/13-basic-attrs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ int main(int argc, char *argv[])
142142
goto out;
143143
}
144144

145+
rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_WAITKILL, 1);
146+
if (rc != 0)
147+
goto out;
148+
rc = seccomp_attr_get(ctx, SCMP_FLTATR_CTL_WAITKILL, &val);
149+
if (rc != 0)
150+
goto out;
151+
if (val != 1) {
152+
rc = -1;
153+
goto out;
154+
}
155+
145156
rc = 0;
146157
out:
147158
seccomp_release(ctx);

tests/13-basic-attrs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def test():
6161
f.set_attr(Attr.API_SYSRAWRC, 1)
6262
if f.get_attr(Attr.API_SYSRAWRC) != 1:
6363
raise RuntimeError("Failed getting Attr.API_SYSRAWRC")
64+
f.set_attr(Attr.CTL_WAITKILL, 1)
65+
if f.get_attr(Attr.CTL_WAITKILL) != 1:
66+
raise RuntimeError("Failed getting Attr.CTL_WAITKILL")
6467

6568
test()
6669

0 commit comments

Comments
 (0)