Skip to content

Commit 37ebfe4

Browse files
authored
Merge pull request systemd#22926 from bluca/analyze_offline_filter
analyze: fix offline checks for syscall filter and 'native' architecture
2 parents 356ad32 + dd51e72 commit 37ebfe4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/analyze/analyze-security.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,23 +530,28 @@ static int assess_restrict_namespaces(
530530
return 0;
531531
}
532532

533+
#if HAVE_SECCOMP
534+
533535
static int assess_system_call_architectures(
534536
const struct security_assessor *a,
535537
const SecurityInfo *info,
536538
const void *data,
537539
uint64_t *ret_badness,
538540
char **ret_description) {
539541

542+
uint32_t native = 0;
540543
char *d;
541544
uint64_t b;
542545

543546
assert(ret_badness);
544547
assert(ret_description);
545548

549+
assert_se(seccomp_arch_from_string("native", &native) >= 0);
550+
546551
if (set_isempty(info->system_call_architectures)) {
547552
b = 10;
548553
d = strdup("Service may execute system calls with all ABIs");
549-
} else if (set_contains(info->system_call_architectures, "native") &&
554+
} else if (set_contains(info->system_call_architectures, UINT32_TO_PTR(native + 1)) &&
550555
set_size(info->system_call_architectures) == 1) {
551556
b = 0;
552557
d = strdup("Service may execute system calls only with native ABI");
@@ -564,8 +569,6 @@ static int assess_system_call_architectures(
564569
return 0;
565570
}
566571

567-
#if HAVE_SECCOMP
568-
569572
static bool syscall_names_in_filter(Hashmap *s, bool allow_list, const SyscallFilterSet *f, const char **ret_offending_syscall) {
570573
const char *syscall;
571574

@@ -587,7 +590,7 @@ static bool syscall_names_in_filter(Hashmap *s, bool allow_list, const SyscallFi
587590
if (id < 0)
588591
continue;
589592

590-
if (hashmap_contains(s, syscall) == allow_list) {
593+
if (hashmap_contains(s, syscall) != allow_list) {
591594
log_debug("Offending syscall filter item: %s", syscall);
592595
if (ret_offending_syscall)
593596
*ret_offending_syscall = syscall;
@@ -1476,6 +1479,7 @@ static const struct security_assessor security_assessor_table[] = {
14761479
.assess = assess_bool,
14771480
.offset = offsetof(SecurityInfo, restrict_address_family_other),
14781481
},
1482+
#if HAVE_SECCOMP
14791483
{
14801484
.id = "SystemCallArchitectures=",
14811485
.json_field = "SystemCallArchitectures",
@@ -1484,7 +1488,6 @@ static const struct security_assessor security_assessor_table[] = {
14841488
.range = 10,
14851489
.assess = assess_system_call_architectures,
14861490
},
1487-
#if HAVE_SECCOMP
14881491
{
14891492
.id = "SystemCallFilter=~@swap",
14901493
.json_field = "SystemCallFilter_swap",

test/units/testsuite-65.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,14 @@ systemd-analyze security --threshold=90 --offline=true \
575575
--root=/tmp/img/ testfile.service
576576

577577
# The strict profile adds a lot of sanboxing options
578-
systemd-analyze security --threshold=20 --offline=true \
578+
systemd-analyze security --threshold=25 --offline=true \
579579
--security-policy=/tmp/testfile.json \
580580
--profile=strict \
581581
--root=/tmp/img/ testfile.service
582582

583583
set +e
584584
# The trusted profile doesn't add any sanboxing options
585-
systemd-analyze security --threshold=20 --offline=true \
585+
systemd-analyze security --threshold=25 --offline=true \
586586
--security-policy=/tmp/testfile.json \
587587
--profile=/usr/lib/systemd/portable/profile/trusted/service.conf \
588588
--root=/tmp/img/ testfile.service \

0 commit comments

Comments
 (0)