Re: [PATCH] elf-load: Respect PT_GNU_STACK

2024-03-27 Thread Sergey Bugaev
On Wed, Mar 27, 2024 at 9:37 PM Samuel Thibault wrote: > But it's not getting used anywhere? Indeed, I forgot to extract the kern/bootstrap.c part of the change. Ooops :) Thanks for pointing it out. Sergey -- >8 -- If a bootstrap ELF contains a PT_GNU_STACK phdr, take stack protection from the

Re: [PATCH 17/17] tests: Create tests/ in the build tree before trying to use it

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:41 +0300, a ecrit: > --- > tests/user-qemu.mk | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/tests/user-qemu.mk b/tests/user-qemu.mk > index fd5ae1ab..4f8390b6 100644 > --- a/tests/user-qemu.mk > +++ b/tests/user-qemu.mk > @@ -

Re: [PATCH 16/17] tests: Don't ask for executable stack

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:40 +0300, a ecrit: > --- > tests/start.S| 2 ++ > tests/syscalls.S | 2 ++ > 2 files changed, 4 insertions(+) > > diff --git a/tests/start.S b/tests/start.S > index b795bfbd..15970fb9 100644 > --- a/tests/start.S > +++ b/tests/start.

Re: [PATCH 15/17] tests: Make exception subcode a long

2024-03-27 Thread Samuel Thibault
Applied, thansks! Sergey Bugaev, le mer. 27 mars 2024 19:18:39 +0300, a ecrit: > --- > tests/test-syscalls.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tests/test-syscalls.c b/tests/test-syscalls.c > index 63c2690a..fbfecd9c 100644 > --- a/tests/test-syscalls.c > ++

Re: [PATCH 14/17] tests: Use vm_page_size

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:38 +0300, a ecrit: > --- > tests/testlib_thread_start.c | 19 +++ > 1 file changed, 11 insertions(+), 8 deletions(-) > > diff --git a/tests/testlib_thread_start.c b/tests/testlib_thread_start.c > index fa8af0ea..df4b19ab

Re: [PATCH 13/17] tests: Add vm_page_size

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:37 +0300, a ecrit: > --- > tests/include/testlib.h | 2 ++ > tests/testlib.c | 13 + > 2 files changed, 15 insertions(+) > > diff --git a/tests/include/testlib.h b/tests/include/testlib.h > index d2367124..035fdc28 1

Re: [PATCH 12/17] tests: Add a more serious mach_msg_server() routine

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:36 +0300, a ecrit: > --- > tests/include/testlib.h | 16 ++ > tests/test-syscalls.c | 40 + > tests/testlib.c | 123 > 3 files changed, 142 insertions(+), 37 deletions(-

Re: [PATCH 11/17] tests: Fix halt()

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:35 +0300, a ecrit: > Mark it as noreturn, and make sure to halt, not reboot. > --- > tests/include/testlib.h | 2 +- > tests/testlib.c | 3 ++- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/tests/include/tes

Re: [PATCH 10/17] Make -fno-PIE etc. architecture-dependent

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:34 +0300, a ecrit: > There might be good reasons why Mach on x86 shouldn't be built as PIC/ > PIE, but there are also very good reasons to support PIE on other > architectures. Potentially implementing KASLR is one such reason; but > also

Re: [PATCH 09/17] Move copy{in,out}msg declarations to copy_user.h

2024-03-27 Thread Samuel Thibault
Sergey Bugaev, le mer. 27 mars 2024 19:18:33 +0300, a ecrit: > Since they are implemented in copy_user.c > --- > i386/i386/locore.h | 4 > ipc/copy_user.h| 15 +++ > kern/exception.c | 1 + > 3 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/i386/i386/loc

Re: [PATCH 08/17] ipc: Turn ipc_entry_lookup_failed() into a macro

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:32 +0300, a ecrit: > ipc_entry_lookup_failed() is used with both mach_msg_user_header_t and > mach_msg_header_t arguments, which are different types. Make it into a > macro, so it works with both. > --- > ipc/ipc_space.h | 22

Re: [PATCH 07/17] kern/rdxtree: Fix undefined behavior

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:31 +0300, a ecrit: > Initializing a variable with itself is undefined, and GCC 14 rightfully > produces a warning about the variable being used (to initialize itself) > prior to initialization. X15 sets the variables to 0 instead, so do th

Re: [PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user memory

2024-03-27 Thread Samuel Thibault
Sergey Bugaev, le mer. 27 mars 2024 19:18:30 +0300, a ecrit: > It's not always possible to directly access user memory from kernel > mode. While it's in theory a lot more expensive to fetch each character > to be printed separately, mach_print() is only a debugging facility, and > it's not supposed

Re: [PATCH 05/17] gsync: Use copyin()/copyout() to access user memory

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:29 +0300, a ecrit: > Depending on the architecture and setup, it may not be possible to > access user memory directly, for example, due to user mode mappings not > being accessible from kernel mode (x86 SMAP, AArch64 PAN). There are > dedi

Re: [PATCH 04/17] Load 64-bit ELFs on all 64-bit ports

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:28 +0300, a ecrit: > Not only on x86_64. > --- > include/mach/exec/elf.h | 4 ++-- > kern/exception.c| 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/mach/exec/elf.h b/include/mach/exec/elf.h >

Re: [PATCH 03/17] Use the x86_64 message ABI on all 64-bit ports

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:27 +0300, a ecrit: > --- > include/mach/message.h | 10 +- > ipc/ipc_kmsg.c | 4 ++-- > 2 files changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/mach/message.h b/include/mach/message.h > index 9790ef98..

Re: [PATCH 02/17] Disable host_kernel_version() everywhere but on i386

2024-03-27 Thread Samuel Thibault
Applied, thanks! Sergey Bugaev, le mer. 27 mars 2024 19:18:26 +0300, a ecrit: > It's not only x86_64, none of new architectures are going to have it. > --- > include/mach/mach_host.defs | 6 +++--- > kern/host.c | 4 ++-- > 2 files changed, 5 insertions(+), 5 deletions(-) > > dif

Re: [PATCH 01/17] elf-load: Respect PT_GNU_STACK

2024-03-27 Thread Samuel Thibault
Hello, Sergey Bugaev, le mer. 27 mars 2024 19:18:25 +0300, a ecrit: > diff --git a/include/mach/exec/exec.h b/include/mach/exec/exec.h > index 94b234b0..29fa897d 100644 > --- a/include/mach/exec/exec.h > +++ b/include/mach/exec/exec.h > @@ -51,6 +51,8 @@ typedef struct exec_info > /* (ELF) A

[PATCH 16/17] tests: Don't ask for executable stack

2024-03-27 Thread Sergey Bugaev
--- tests/start.S| 2 ++ tests/syscalls.S | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/start.S b/tests/start.S index b795bfbd..15970fb9 100644 --- a/tests/start.S +++ b/tests/start.S @@ -26,3 +26,5 @@ _start: movq%rsp,%rdi callq c_start #endif /* __x86_

[PATCH 00/17] Preparatory patches

2024-03-27 Thread Sergey Bugaev
These are generic, relatively independent patches from the AArch64 branch. I've done a quick build for i386-gnu and things still seem to build, but please test! Sergey

[PATCH 04/17] Load 64-bit ELFs on all 64-bit ports

2024-03-27 Thread Sergey Bugaev
Not only on x86_64. --- include/mach/exec/elf.h | 4 ++-- kern/exception.c| 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mach/exec/elf.h b/include/mach/exec/elf.h index 42920e25..55304496 100644 --- a/include/mach/exec/elf.h +++ b/include/mach/exec/elf.h @@

[PATCH 02/17] Disable host_kernel_version() everywhere but on i386

2024-03-27 Thread Sergey Bugaev
It's not only x86_64, none of new architectures are going to have it. --- include/mach/mach_host.defs | 6 +++--- kern/host.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/mach/mach_host.defs b/include/mach/mach_host.defs index a8c40af6..8fd9d6b3

[PATCH 01/17] elf-load: Respect PT_GNU_STACK

2024-03-27 Thread Sergey Bugaev
If a bootstrap ELF contains a PT_GNU_STACK phdr, take stack protection from there. Otherwise, default to VM_PROT_ALL. --- include/mach/exec/elf.h | 1 + include/mach/exec/exec.h | 2 ++ kern/elf-load.c | 7 +++ 3 files changed, 10 insertions(+) diff --git a/include/mach/exec/elf.h

[PATCH 17/17] tests: Create tests/ in the build tree before trying to use it

2024-03-27 Thread Sergey Bugaev
--- tests/user-qemu.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/user-qemu.mk b/tests/user-qemu.mk index fd5ae1ab..4f8390b6 100644 --- a/tests/user-qemu.mk +++ b/tests/user-qemu.mk @@ -130,6 +130,7 @@ SRC_TESTLIB= \ $(MIG_GEN_CC) tests/errlist.c: $(addprefix $(srcdir)/in

[PATCH 05/17] gsync: Use copyin()/copyout() to access user memory

2024-03-27 Thread Sergey Bugaev
Depending on the architecture and setup, it may not be possible to access user memory directly, for example, due to user mode mappings not being accessible from kernel mode (x86 SMAP, AArch64 PAN). There are dedicated machine-specific copyin()/copyout() routines that know how to access user memory

[PATCH 07/17] kern/rdxtree: Fix undefined behavior

2024-03-27 Thread Sergey Bugaev
Initializing a variable with itself is undefined, and GCC 14 rightfully produces a warning about the variable being used (to initialize itself) prior to initialization. X15 sets the variables to 0 instead, so do the same in Mach. --- kern/rdxtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 dele

[PATCH 12/17] tests: Add a more serious mach_msg_server() routine

2024-03-27 Thread Sergey Bugaev
--- tests/include/testlib.h | 16 ++ tests/test-syscalls.c | 40 + tests/testlib.c | 123 3 files changed, 142 insertions(+), 37 deletions(-) diff --git a/tests/include/testlib.h b/tests/include/testlib.h index cdb2ce13..d236712

[PATCH 11/17] tests: Fix halt()

2024-03-27 Thread Sergey Bugaev
Mark it as noreturn, and make sure to halt, not reboot. --- tests/include/testlib.h | 2 +- tests/testlib.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/include/testlib.h b/tests/include/testlib.h index a3f3a6a8..cdb2ce13 100644 --- a/tests/include/testlib.

[PATCH 15/17] tests: Make exception subcode a long

2024-03-27 Thread Sergey Bugaev
--- tests/test-syscalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-syscalls.c b/tests/test-syscalls.c index 63c2690a..fbfecd9c 100644 --- a/tests/test-syscalls.c +++ b/tests/test-syscalls.c @@ -34,7 +34,7 @@ static struct { mach_port_t task; integer_t ex

[PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user memory

2024-03-27 Thread Sergey Bugaev
It's not always possible to directly access user memory from kernel mode. While it's in theory a lot more expensive to fetch each character to be printed separately, mach_print() is only a debugging facility, and it's not supposed to be used for printing large amounts of data. --- kern/syscall_sub

[PATCH 09/17] Move copy{in,out}msg declarations to copy_user.h

2024-03-27 Thread Sergey Bugaev
Since they are implemented in copy_user.c --- i386/i386/locore.h | 4 ipc/copy_user.h| 15 +++ kern/exception.c | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/i386/i386/locore.h b/i386/i386/locore.h index 217e6dec..8ff587ed 100644 --- a/i386/i386/lo

[PATCH 13/17] tests: Add vm_page_size

2024-03-27 Thread Sergey Bugaev
--- tests/include/testlib.h | 2 ++ tests/testlib.c | 13 + 2 files changed, 15 insertions(+) diff --git a/tests/include/testlib.h b/tests/include/testlib.h index d2367124..035fdc28 100644 --- a/tests/include/testlib.h +++ b/tests/include/testlib.h @@ -70,6 +70,8 @@ thread_t

[PATCH 14/17] tests: Use vm_page_size

2024-03-27 Thread Sergey Bugaev
--- tests/testlib_thread_start.c | 19 +++ 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/testlib_thread_start.c b/tests/testlib_thread_start.c index fa8af0ea..df4b19ab 100644 --- a/tests/testlib_thread_start.c +++ b/tests/testlib_thread_start.c @@ -30,30 +30,

[PATCH 10/17] Make -fno-PIE etc. architecture-dependent

2024-03-27 Thread Sergey Bugaev
There might be good reasons why Mach on x86 shouldn't be built as PIC/ PIE, but there are also very good reasons to support PIE on other architectures. Potentially implementing KASLR is one such reason; but also the Linux AArch64 boot protocol (that the AArch64 port will use for booting) lets the b

[PATCH 08/17] ipc: Turn ipc_entry_lookup_failed() into a macro

2024-03-27 Thread Sergey Bugaev
ipc_entry_lookup_failed() is used with both mach_msg_user_header_t and mach_msg_header_t arguments, which are different types. Make it into a macro, so it works with both. --- ipc/ipc_space.h | 22 +- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ipc/ipc_space.

[PATCH 03/17] Use the x86_64 message ABI on all 64-bit ports

2024-03-27 Thread Sergey Bugaev
--- include/mach/message.h | 10 +- ipc/ipc_kmsg.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/mach/message.h b/include/mach/message.h index 9790ef98..87b83951 100644 --- a/include/mach/message.h +++ b/include/mach/message.h @@ -240,7 +240,7 @@