Skip to content

Commit 035121d

Browse files
berrangeotubo
authored andcommitted
seccomp: report more useful errors from seccomp
Most of the seccomp functions return errnos as a negative return value. The code is currently ignoring these and reporting a generic error message for all seccomp failure scenarios making debugging painful. Report a more precise error from each failed call and include errno if it is available. Signed-off-by: Daniel P. Berrangé <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Signed-off-by: Eduardo Otubo <[email protected]>
1 parent 9a1565a commit 035121d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

qemu-seccomp.c

+13-7
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,22 @@ static uint32_t qemu_seccomp_get_action(int set)
155155
}
156156

157157

158-
static int seccomp_start(uint32_t seccomp_opts)
158+
static int seccomp_start(uint32_t seccomp_opts, Error **errp)
159159
{
160-
int rc = 0;
160+
int rc = -1;
161161
unsigned int i = 0;
162162
scmp_filter_ctx ctx;
163163

164164
ctx = seccomp_init(SCMP_ACT_ALLOW);
165165
if (ctx == NULL) {
166-
rc = -1;
166+
error_setg(errp, "failed to initialize seccomp context");
167167
goto seccomp_return;
168168
}
169169

170170
rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_TSYNC, 1);
171171
if (rc != 0) {
172+
error_setg_errno(errp, -rc,
173+
"failed to set seccomp thread synchronization");
172174
goto seccomp_return;
173175
}
174176

@@ -182,15 +184,21 @@ static int seccomp_start(uint32_t seccomp_opts)
182184
rc = seccomp_rule_add_array(ctx, action, blacklist[i].num,
183185
blacklist[i].narg, blacklist[i].arg_cmp);
184186
if (rc < 0) {
187+
error_setg_errno(errp, -rc,
188+
"failed to add seccomp blacklist rules");
185189
goto seccomp_return;
186190
}
187191
}
188192

189193
rc = seccomp_load(ctx);
194+
if (rc < 0) {
195+
error_setg_errno(errp, -rc,
196+
"failed to load seccomp syscall filter in kernel");
197+
}
190198

191199
seccomp_return:
192200
seccomp_release(ctx);
193-
return rc;
201+
return rc < 0 ? -1 : 0;
194202
}
195203

196204
#ifdef CONFIG_SECCOMP
@@ -260,9 +268,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
260268
}
261269
}
262270

263-
if (seccomp_start(seccomp_opts) < 0) {
264-
error_setg(errp, "failed to install seccomp syscall filter "
265-
"in the kernel");
271+
if (seccomp_start(seccomp_opts, errp) < 0) {
266272
return -1;
267273
}
268274
}

0 commit comments

Comments
 (0)