Skip to content

Commit cef35d4

Browse files
committed
Add support for PR_{GET,SET}_TAGGED_ADDR_CTRL prctls
1 parent aaed29d commit cef35d4

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ set(BASIC_TESTS
14041404
x86/sysfs
14051405
sysinfo
14061406
syslog
1407+
arm/tagged_addr_ctrl
14071408
tgkill
14081409
thread_yield
14091410
timer

src/record_syscall.cc

+17
Original file line numberDiff line numberDiff line change
@@ -4736,6 +4736,23 @@ static Switchable rec_prepare_syscall_arch(RecordTask* t,
47364736
case PR_SET_THP_DISABLE:
47374737
case PR_SET_SECUREBITS:
47384738
case PR_GET_SECUREBITS:
4739+
case PR_GET_TAGGED_ADDR_CTRL:
4740+
break;
4741+
4742+
case PR_SET_TAGGED_ADDR_CTRL:
4743+
if (regs.arg2() & ~PR_TAGGED_ADDR_ENABLE) {
4744+
// For now we only support enabling the tagged address ABI which
4745+
// only affects the semantics of syscalls. We don't support setting
4746+
// any of the MTE-related bits because they affect the semantics of
4747+
// normal load/store instructions (implying replay is required) as
4748+
// well as exposing non-determinism in the following ways:
4749+
// 1) With a non-empty tag inclusion mask, the tag computed by the
4750+
// IRG instruction will be effectively random.
4751+
// 2) It is indeterminate when a SIGSEGV/SEGV_MTEAERR signal will
4752+
// be raised if an asynchronous tag check fault is taken.
4753+
// Both of these issues should be fixable with some kernel changes.
4754+
syscall_state.emulate_result(-EINVAL);
4755+
}
47394756
break;
47404757

47414758
case PR_SET_DUMPABLE:

src/test/arm/tagged_addr_ctrl.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "util.h"
2+
3+
#include <linux/prctl.h>
4+
#include <sys/prctl.h>
5+
#include <errno.h>
6+
7+
int main(void) {
8+
int ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
9+
// Skip the test on pre-5.4 kernels which predate the prctl.
10+
if (ret == -1 && errno == EINVAL) {
11+
atomic_puts("EXIT-SUCCESS");
12+
return 0;
13+
}
14+
test_assert(ret == 0);
15+
16+
ret = prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0);
17+
test_assert(ret == 0);
18+
19+
ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
20+
test_assert(ret == PR_TAGGED_ADDR_ENABLE);
21+
22+
// We don't support MTE yet.
23+
ret = prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_ASYNC,
24+
0, 0, 0);
25+
test_assert(ret == -1 && errno == EINVAL);
26+
27+
atomic_puts("EXIT-SUCCESS");
28+
}

0 commit comments

Comments
 (0)