diff options
Diffstat (limited to 'src/fseccomp/syscall.c')
-rw-r--r-- | src/fseccomp/syscall.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/src/fseccomp/syscall.c b/src/fseccomp/syscall.c index 08ae5953d..8c18b2d14 100644 --- a/src/fseccomp/syscall.c +++ b/src/fseccomp/syscall.c | |||
@@ -492,10 +492,15 @@ int syscall_check_list(const char *slist, void (*callback)(int fd, int syscall, | |||
492 | fprintf(stderr, "Warning fseccomp: syscall \"%s\" not available on this platform\n", ptr); | 492 | fprintf(stderr, "Warning fseccomp: syscall \"%s\" not available on this platform\n", ptr); |
493 | } | 493 | } |
494 | else if (callback != NULL) { | 494 | else if (callback != NULL) { |
495 | if (error_nr != -1) | 495 | if (error_nr != -1 && fd != 0) { |
496 | filter_add_errno(fd, syscall_nr, error_nr, ptrarg); | 496 | filter_add_errno(fd, syscall_nr, error_nr, ptrarg); |
497 | else | 497 | } |
498 | else if (error_nr != -1 && fd == 0) { | ||
499 | callback(fd, syscall_nr, error_nr, ptrarg); | ||
500 | } | ||
501 | else { | ||
498 | callback(fd, syscall_nr, arg, ptrarg); | 502 | callback(fd, syscall_nr, arg, ptrarg); |
503 | } | ||
499 | } | 504 | } |
500 | } | 505 | } |
501 | ptr = strtok_r(NULL, ",", &saveptr); | 506 | ptr = strtok_r(NULL, ",", &saveptr); |
@@ -523,20 +528,34 @@ static void syscall_in_list(int fd, int syscall, int arg, void *ptrarg) { | |||
523 | sl.syscall = syscall; | 528 | sl.syscall = syscall; |
524 | syscall_check_list(ptr->slist, find_syscall, fd, 0, &sl); | 529 | syscall_check_list(ptr->slist, find_syscall, fd, 0, &sl); |
525 | // if found in the problem list, add to post-exec list | 530 | // if found in the problem list, add to post-exec list |
526 | if (sl.found) | 531 | if (sl.found) { |
527 | if (ptr->postlist) { | 532 | if (ptr->postlist) { |
528 | if (asprintf(&ptr->postlist, "%s,%s", ptr->postlist, syscall_find_nr(syscall)) == -1) | 533 | if (asprintf(&ptr->postlist, "%s,%s", ptr->postlist, syscall_find_nr(syscall)) == -1) |
529 | errExit("asprintf"); | 534 | errExit("asprintf"); |
530 | } | 535 | } |
531 | else | 536 | else |
532 | ptr->postlist = strdup(syscall_find_nr(syscall)); | 537 | ptr->postlist = strdup(syscall_find_nr(syscall)); |
533 | else // no problem, add to pre-exec list | 538 | } |
539 | else { // no problem, add to pre-exec list | ||
540 | // build syscall:error_no | ||
541 | char *newcall; | ||
542 | if (arg != 0) { | ||
543 | if (asprintf(&newcall, "%s:%s", syscall_find_nr(syscall), errno_find_nr(arg)) == -1) | ||
544 | errExit("asprintf"); | ||
545 | } | ||
546 | else { | ||
547 | newcall = strdup(syscall_find_nr(syscall)); | ||
548 | if (!newcall) | ||
549 | errExit("strdup"); | ||
550 | } | ||
551 | |||
534 | if (ptr->prelist) { | 552 | if (ptr->prelist) { |
535 | if (asprintf(&ptr->prelist, "%s,%s", ptr->prelist, syscall_find_nr(syscall)) == -1) | 553 | if (asprintf(&ptr->prelist, "%s,%s", ptr->prelist, newcall) == -1) |
536 | errExit("asprintf"); | 554 | errExit("asprintf"); |
537 | } | 555 | } |
538 | else | 556 | else |
539 | ptr->prelist = strdup(syscall_find_nr(syscall)); | 557 | ptr->prelist = newcall; |
558 | } | ||
540 | } | 559 | } |
541 | 560 | ||
542 | // go through list and find matches for syscalls in list @default-keep | 561 | // go through list and find matches for syscalls in list @default-keep |
@@ -548,8 +567,16 @@ void syscalls_in_list(const char *list, const char *slist, int fd, char **prelis | |||
548 | sl.prelist = NULL; | 567 | sl.prelist = NULL; |
549 | sl.postlist = NULL; | 568 | sl.postlist = NULL; |
550 | syscall_check_list(list, syscall_in_list, 0, 0, &sl); | 569 | syscall_check_list(list, syscall_in_list, 0, 0, &sl); |
551 | if (!arg_quiet) | 570 | if (!arg_quiet) { |
552 | printf("list in: %s, check list: %s prelist: %s, postlist: %s\n", list, sl.slist, sl.prelist, sl.postlist); | 571 | printf("Seccomp list in: %s,", list); |
572 | if (sl.slist) | ||
573 | printf(" check list: %s,", sl.slist); | ||
574 | if (sl.prelist) | ||
575 | printf(" prelist: %s,", sl.prelist); | ||
576 | if (sl.postlist) | ||
577 | printf(" postlist: %s", sl.postlist); | ||
578 | printf("\n"); | ||
579 | } | ||
553 | *prelist = sl.prelist; | 580 | *prelist = sl.prelist; |
554 | *postlist = sl.postlist; | 581 | *postlist = sl.postlist; |
555 | } | 582 | } |