Skip to content

Commit e59394a

Browse files
committed
cheribsdtest: Fix malloc cheribsdtest when revocation is disabled.
- Skip additional tests when security.cheri.runtime_revocation_default=0 - Skip malloc_double_free test when revocation is disabled. - Fix rallocx_aligned test to never pass NULL to rallocx. This is not allowed by the upstream rallocx() interface and it is an mrs-specific extension. Add an assertion to MRS to catch this if used.
1 parent f3ad7f8 commit e59394a

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

bin/cheribsdtest/cheribsdtest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ extern ptraddr_t find_address_space_gap(size_t len, size_t align);
349349
extern pid_t cheribsdtest_spawn_child(enum spawn_child_mode mode);
350350

351351
const char *skip_need_cheri_revoke(const struct cheri_test *ctp);
352+
const char *skip_need_default_cheri_revoke(const struct cheri_test *ctp);
352353

353354
const char *cheribsdtest_get_helper_path(void);
354355
const char *cheribsdtest_skip_no_helper(const struct cheri_test *ctp);

bin/cheribsdtest/cheribsdtest_malloc.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@
4545
extern volatile void *eptr;
4646
volatile void *eptr;
4747

48+
static const char *
49+
skip_malloc_revocation_disabled(const struct cheri_test *ctp __unused)
50+
{
51+
if (malloc_revoke_enabled())
52+
return (NULL);
53+
return ("malloc quarantine disabled");
54+
}
55+
4856
CHERIBSDTEST(malloc_double_free, "malloc aborts on double free",
4957
.ct_flags = CT_FLAG_SIGEXIT,
50-
.ct_signum = SIGABRT)
58+
.ct_signum = SIGABRT,
59+
.ct_check_skip = skip_malloc_revocation_disabled)
5160
{
5261
volatile void *ptr;
5362

@@ -60,14 +69,6 @@ CHERIBSDTEST(malloc_double_free, "malloc aborts on double free",
6069
cheribsdtest_failure_errx("malloc() did not abort");
6170
}
6271

63-
static const char *
64-
skip_malloc_revocation_disabled(const struct cheri_test *ctp __unused)
65-
{
66-
if (malloc_revoke_enabled())
67-
return (NULL);
68-
return ("malloc quarantine disabled");
69-
}
70-
7172
CHERIBSDTEST(malloc_revoke_basic,
7273
"verify that a free'd pointer is revoked by malloc_revoke",
7374
.ct_check_skip = skip_malloc_revocation_disabled)
@@ -257,7 +258,7 @@ malloc_revocation_ctl_common(const char *progname, bool should_be_revoking)
257258

258259
CHERIBSDTEST(malloc_revocation_ctl_baseline,
259260
"A base binary reports revocation is enabled",
260-
.ct_check_skip = skip_need_cheri_revoke)
261+
.ct_check_skip = skip_need_default_cheri_revoke)
261262
{
262263
malloc_revocation_ctl_common("malloc_revoke_enabled", true);
263264
}
@@ -300,7 +301,7 @@ CHERIBSDTEST(malloc_revocation_ctl_elfnote_enable_protctl_disable,
300301

301302
CHERIBSDTEST(malloc_revocation_ctl_suid_baseline,
302303
"A suid binary reports revocation is enabled",
303-
.ct_check_skip = skip_need_cheri_revoke)
304+
.ct_check_skip = skip_need_default_cheri_revoke)
304305
{
305306
malloc_revocation_ctl_common("malloc_revoke_enabled_suid", true);
306307
}
@@ -396,7 +397,7 @@ CHERIBSDTEST(mallocx_alignment, "Check that mallocx aligns allocations")
396397
static void
397398
check_rallocx(size_t size)
398399
{
399-
static void *data = NULL;
400+
void *data = malloc(1);
400401

401402
data = rallocx(data, size, MALLOCX_ALIGN(size));
402403
CHERIBSDTEST_VERIFY2(__builtin_is_aligned(data, size),

bin/cheribsdtest/cheribsdtest_util.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,19 @@ skip_need_cheri_revoke(const struct cheri_test *ctp __unused)
135135
return ("Kernel does not support revocation");
136136
return (NULL);
137137
}
138+
139+
const char *
140+
skip_need_default_cheri_revoke(const struct cheri_test *ctp __unused)
141+
{
142+
int value = 0;
143+
size_t len = sizeof(value);
144+
145+
if (sysctlbyname("security.cheri.runtime_revocation_default",
146+
&value, &len, NULL, 0)) {
147+
return (NULL);
148+
}
149+
if (value == 0) {
150+
return ("System disables revocation");
151+
}
152+
return (NULL);
153+
}

lib/libc/stdlib/malloc/mrs/mrs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ mrs_rallocx(void *ptr, size_t size, int flags)
18241824
if (!quarantining)
18251825
return (mrs_real_rallocx(ptr, size, flags));
18261826

1827+
assert(ptr != NULL);
18271828
old_size = cheri_getlen(ptr);
18281829

18291830
mrs_debug_printf("%s: called ptr %p ptr size %zu new size %zu\n",

0 commit comments

Comments
 (0)