Read only syscall tables for x86_64 and i386
Quoted 4 lines · Christoph Lameter
Place
x86_64and i386 syscall table into the read only section.Remove the syscall tables from the data section and place them into the readonly section (like IA64).
It's unfortunately useless because all the kernel is mapped in the same 2 or 4MB page has to be writable because it overlaps with real direct mapped memory.
On x86-64 there is a separate kernel mapping which could be made read only. But that would be useless again because the memory is aliased in the real direct mapping which has the same overlapping problem.
The only way to write protect the kernel would be to pad it to 2MB (or 4MB on i386/non PAE) which would be a big waste of memory or use significantly more TLB entries in normal operation.
Both is probably not worth the modest safety increase you get from such a change.
-Andi
Quoted 3 lines · Andi Kleen
It's unfortunately useless because all the kernel is mapped in the same 2 or 4MB page has to be writable because it overlaps with real direct mapped memory.
The question is: Are syscall tables are supposed to be writable? If no then this patch should go in. If yes then forget about it. On IA64 they are readonly and so I thought they should also be readonly on i386 and x86_64.
The ability to protect a readonly section may be another issue.
Quoted 1 line · Christoph Lameter
The ability to protect a readonly section may be another issue.
Exactly. Mapping the readonly section readonly adds a nice way to check that constant data is handled correctly by all of the code. Otherwise, there might be some surprises if gcc performs constant folding and we incorrectly rely on one copy to be writable.
A read-only text segment also raises the bar for authors of rootkits or other evil hacks that patch the running kernel code.
Right now, s390 (and I believe arm, maybe others as well) is already able to map in the readonly sections of the kernel from ROM, in order to have more available RAM for other purposes.
Arnd <><
Quoted 8 lines · Christoph Lameter
Quoted 3 lines · Andi Kleen
It's unfortunately useless because all the kernel is mapped in the same 2 or 4MB page has to be writable because it overlaps with real direct mapped memory.
The question is: Are syscall tables are supposed to be writable? If no then this patch should go in. If yes then forget about it.
I think it would make sense in theory to write protect them together with the kernel code and the modules (just to make root kit writing slightly harder)
It is just that it is not practical on i386/x86-64 right now without undue performance impact for the main kernel. TLB pressure is unfortunately quite performance critical and we cannot goof off on this.
Write protecting the modules would be possible right now because they're vmalloced, but might be a problem later if we move them to the direct mapping again (that was a beneficial 2.4 optimization), so I am not sure it would be a good idea.
BTW the kernel actually needs to write to code once to apply alternative(), but it would't be a problem to use a temporary mapping for this.
Quoted 4 lines
On IA64 they are readonly and so I thought they should also be readonly on i386 and
x86_64.The ability to protect a readonly section may be another issue.
Well, it's the overriding issue here. Just pretending it's readonly when it isn't doesn't seem useful.
-Andi
Quoted 7 lines · Andi Kleen
Quoted 6 lines · Christoph Lameter
Quoted 3 lines · Andi Kleen
It's unfortunately useless because all the kernel is mapped in the same 2 or 4MB page has to be writable because it overlaps with real direct mapped memory.
Quoted 6 lines
Quoted 2 lines
The question is: Are syscall tables are supposed to be writable? If no then this patch should go in. If yes then forget about it.
I think it would make sense in theory to write protect them together with the kernel code and the modules (just to make root kit writing slightly harder)
Seems that you are evading the question that I asked. Are syscall tables supposed to be writable?
Quoted 3 lines
BTW the kernel actually needs to write to code once to apply
alternative(), but it would't be a problem to use a temporary mapping for this.
What does this have to do with the syscall table???
Quoted 4 lines
Quoted 1 line
The ability to protect a readonly section may be another issue.
Well, it's the overriding issue here. Just pretending it's readonly when it isn't doesn't seem useful.
This is all are off-topic talking about a different issue. And we are already "pretending" that lots of other stuff in the readonly section is readonly.
The issue is correct placement of variables. Read only variables are placed in a different section and the syscall tables are read only and need to be place in the correct section.
Quoted 6 lines · Christoph Lameter
Quoted 3 lines
I think it would make sense in theory to write protect them together with the kernel code and the modules (just to make root kit writing slightly harder)
Seems that you are evading the question that I asked. Are syscall tables supposed to be writable?
I did answer it. But again: yes I think it makes sense in theory to make them read only.
Just we cannot do it right now on i386/x86-64 due to the reasons I lined out in my previous mail.
Quoted 6 lines
Quoted 4 lines
BTW the kernel actually needs to write to code once to apply
alternative(), but it would't be a problem to use a temporary mapping for this.What does this have to do with the syscall table???
It is directly related to writable .text.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The ability to protect a readonly section may be another issue.
Well, it's the overriding issue here. Just pretending it's readonly when it isn't doesn't seem useful.
This is all are off-topic talking about a different issue. And we are already "pretending" that lots of other stuff in the readonly section is readonly.
Putting it into a "ro section" when it isn't actually read only is completely useless and does not do anything useful. So unless you figure out a way to make a true ro section without performance penalty I wouldn't bother.
If you really want it for cosmetic reasons you can still do it, but it is about at the same usefullness level as shuffling white space in the source around.
-Andi
Quoted 30 lines · Christoph Lameter
Quoted 7 lines · Andi Kleen
Quoted 6 lines · Christoph Lameter
Quoted 3 lines · Andi Kleen
It's unfortunately useless because all the kernel is mapped in the same 2 or 4MB page has to be writable because it overlaps with real direct mapped memory.
Quoted 6 lines
Quoted 2 lines
The question is: Are syscall tables are supposed to be writable? If no then this patch should go in. If yes then forget about it.
I think it would make sense in theory to write protect them together with the kernel code and the modules (just to make root kit writing slightly harder)
Seems that you are evading the question that I asked. Are syscall tables supposed to be writable?
Quoted 3 lines
BTW the kernel actually needs to write to code once to apply
alternative(), but it would't be a problem to use a temporary mapping for this.What does this have to do with the syscall table???
Quoted 4 lines
Quoted 1 line
The ability to protect a readonly section may be another issue.
Well, it's the overriding issue here. Just pretending it's readonly when it isn't doesn't seem useful.
Quoted 7 lines
This is all are off-topic talking about a different issue. And we are already "pretending" that lots of other stuff in the readonly section is readonly.
The issue is correct placement of variables. Read only variables are placed in a different section and the syscall tables are read only and need to be place in the correct section.
I modified my sycall table to put it in ".section .rodata". It appears as though read-only is not enforced in the kernel. I don't know why because, at least with ix86, both data and code can be made read- only.
You just write to it with a segment descriptor that allows R/W, then use another for R/O. It is true that kernel code can create any segment descriptor it wants, dynamically, thus a properly-written program can ultimately write to what was once R/O data. However, I think it should default to R/O which should cut down on the number of cheap hacks that can damage it.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.12 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
Quoted 39 lines · Andi Kleen
Quoted 6 lines · Christoph Lameter
Quoted 3 lines
I think it would make sense in theory to write protect them together with the kernel code and the modules (just to make root kit writing slightly harder)
Seems that you are evading the question that I asked. Are syscall tables supposed to be writable?
I did answer it. But again: yes I think it makes sense in theory to make them read only.
Just we cannot do it right now on i386/x86-64 due to the reasons I lined out in my previous mail.
Quoted 6 lines
Quoted 4 lines
BTW the kernel actually needs to write to code once to apply
alternative(), but it would't be a problem to use a temporary mapping for this.What does this have to do with the syscall table???
It is directly related to writable .text.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The ability to protect a readonly section may be another issue.
Well, it's the overriding issue here. Just pretending it's readonly when it isn't doesn't seem useful.
This is all are off-topic talking about a different issue. And we are already "pretending" that lots of other stuff in the readonly section is readonly.
Putting it into a "ro section" when it isn't actually read only is completely useless and does not do anything useful. So unless you figure out a way to make a true ro section without performance penalty I wouldn't bother.
Quoted 5 lines
If you really want it for cosmetic reasons you can still do it, but it is about at the same usefullness level as shuffling white space in the source around.
-Andi
The fact that the syscall table is R/W can be used to an advantage for security. Yes!
After all modules are loaded, you (startup) loads a module that makes the module-loader stuff return -ENOSYS. Then, nobody can load any new modules. The running kernel is (more) secure.
You just need to make sure that all modules that you will need are loaded before you do this. Also, you don't need to disable auto module unloading because, nothing can be unloaded as well.
Script started on Fri 01 Jul 2005 04:43:17 PM EDT [root@chaos driver]# insmod LastDev.ko
[root@chaos driver]# insmod LastDev.ko
insmod: error inserting 'LastDev.ko': -1 Function not implemented [root@chaos driver]# insmod LastDev.ko
insmod: error inserting 'LastDev.ko': -1 Function not implemented [root@chaos driver]# insmod LastDev.ko
insmod: error inserting 'LastDev.ko': -1 Function not implemented [root@chaos driver]# exit
Script done on Fri 01 Jul 2005 04:44:29 PM EDT
Cheers,
Dick Johnson
Penguin : Linux version 2.6.12 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
Quoted 3 lines · Richard B. Johnson
After all modules are loaded, you (startup) loads a module that makes the module-loader stuff return
-ENOSYS. Then, nobody can load any new modules. The running kernel is (more) secure.
Just use an SELinux policy like everyone else 8). You need to block more otherwise I can load a module by hand through /dev/mem etc
Alan
--
" If knowledge does not have owners, then intellectual property
is a trap set by neo-liberalism." -- Hugo Chavez