bzt wrote:It's just the lazy and careless thing to do. If you do the linking in user-space, then you must provide a way to allocate executable pages from user-space, otherwise the dynamic linker can't load text segments of shared libraries. This is the best way to open doors to viruses and gov spyware without being too direct about it. Just give it a thought. A system in which user-space can't modify it's own code segments is far less vulnerable (but also harder to implement). A dynamic linker in exec syscall requires more thinking and more designing, that's all, but perfectly doable.
Of course it's "perfectly doable" and I don't believe it takes very much extra work at all. I could very easily move my dynamic linker into the kernel if I wanted to (despite running in userspace, it's built with "-nostdlib -ffreestanding" on my OS, since it can't use any libraries itself). It's not "laziness" or "carelessness" that made me decide to put it in userspace, it was a conscious and deliberate design decision. I deliberately wanted to design a system where the kernel services userspace, not the other way around; thus, things like the memory layout of a process and even the executable format (the loader is required to be ELF, but there's no reason it couldn't load something else in principle) are decisions for userspace.
Your idea doesn't prevent anything. It just makes it marginally harder. You just force programs that want/need to generate code at runtime to round-trip it via the disk. JIT techniques are very common in modern software, so forcing what's effectively a "Harvard Architecture" on all programs does almost nothing for security, but does make many common software tasks (everything from web browsers to game console emulators) slower.
The common way to prevent running of code from writable memory is the "W^X" concept; in short, memory is
either writable or executable, but never both. You can even make the process of moving from writable to executable strictly one-way for improved security. You could design your permissions system so that programs that don't generate code at runtime can irrevocably "opt-out" of the ability to do so (or require it to be "opt-in"). Maybe even warn the user (although I expect you'd struggle to word such a warning in such a way that any "normal" user would understand) the first time they run a program that requires such an ability.
Putting the dynamic linker in kernelspace is a huge violation of the principle of least privilege; it only needs access to the userspace memory of one process and the files that the current user has access to*. In kernelspace it has access to kernel memory, other processes, all files, etc. It's a complex bit of code that takes complex user-controlled inputs, which makes it a large, difficult to control, attack surface. A simple static ELF loader (which is all my kernel contains) is, by contrast, a tiny piece of code and if, as in my system**, that's only ever used to load the real program loader/dynamic linker, it's not got
any truly "user-controlled" inputs at all (you'd need to be a high-privileged user to change the loader; at which point you've already got more than enough privilege to do far worse things).
In short, having no way for programs to easily generate executable code at runtime has more downsides than upsides and is completely unnecessary for a "secure" system. A dynamic linker in kernelspace is most definitely worse for security.
bzt wrote:
I'm anticipating not everybody will like that I have said the real reason, just watch
Sure, the "real" reason we think your idea is bad is because we're all secretly building viruses or working for repressive governments... Gone off your meds?
* Ok, if you're implementing UNIX permissions you need some special handling so the loader can read executable files that have execute but not read permission. That's not how I intend my OS permission scheme to work.
** In actuality, the same loader code is also used for kernel modules, but if you have the privilege to load them you're already on the other side of the "airtight hatchway".