diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2023-12-12 15:44:01 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2023-12-12 15:44:01 +0000 |
commit | f1d2913a468e249e77296842966f52cc23c28449 (patch) | |
tree | f61d2061ce04b167cfcec506457ee226fdf05ac2 | |
parent | eafe8b3ade13e74b25747a7c9b92e9d6044e2a33 (diff) |
To avoid kbind(2) becoming a powerful gadget, it is called inline to a
function. Therefore we cannot create a precise pinsyscall label. Instead
create a duplicate entry (using inline asm) to force the kernel's pinsyscall
code to skip validation, rather than labelling it illegal. kbind(2) remains
safe because it self-protects by checking its calling address.
ok kettenis
-rw-r--r-- | libexec/ld.so/loader.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index 52e7b03e945..016bfa33633 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.214 2023/08/15 06:26:34 guenther Exp $ */ +/* $OpenBSD: loader.c,v 1.215 2023/12/12 15:44:00 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -467,6 +467,29 @@ _dl_self_relro(long loff) (((X) & PF_X) ? PROT_EXEC : 0)) /* + * To avoid kbind(2) becoming a powerful gadget, it is called inline to a + * function. Therefore we cannot create a precise pinsyscall label. Instead + * create a duplicate entry to force the kernel's pinsyscall code to skip + * validation, rather than labelling it illegal. kbind(2) remains safe + * because it self-protects by checking its calling address. + */ +#define __STRINGIFY(x) #x +#define STRINGIFY(x) __STRINGIFY(x) +#ifdef __arm__ +__asm__(".pushsection openbsd.syscalls,\"\",%progbits;" + ".p2align 2;" + ".long 0;" + ".long " STRINGIFY(SYS_kbind) ";" + ".popsection"); +#else +__asm__(".pushsection openbsd.syscalls,\"\",@progbits;" + ".long 0;" + ".p2align 2;" + ".long " STRINGIFY(SYS_kbind) ";" + ".popsection"); +#endif + +/* * This is the dynamic loader entrypoint. When entering here, depending * on architecture type, the stack and registers are set up according * to the architectures ABI specification. The first thing required |