muta...@gmail.com
2021-03-26 12:39:47 UTC
Assuming an application is riddled with gets() or
other problematic code that allows the injection
of machine code by a hacker, is it possible to take
advantage of segmentation to fix this problem?
And perhaps this solution can be carried forward
to the S/380 segmentation.
First assume you only allow these executables onto
your PDOS/86 system:
https://wiki.osdev.org/MZ
If both the minimum and maximum allocation fields are cleared, MS-DOS will attempt to load the executable as high as possible in memory.
This allows you to have all your executables in high
memory, and all your data and stack in low memory.
The 8086+ supports setting an upper and lower
segment number for ds and ss to be set to. Any
attempt to load ds above that value (which would
reach into where the executables are stored) is
greeted with an exception.
You can assume that all data in the protected area
has been completely trashed by hackers taking
advantage of buffer overruns. It all contains deadly
machine code that can exploit bugs in the OS itself
if it is ever executed. The goal then is to ensure this
code is never executed.
So the above protection mechanism also prevents
code from being executed in the data area.
That just leaves function pointers. Segment register
fs: can (and must) point to the protected area, and
when a function is called, and function pointers are
pushed onto the stack, the first thing the called
function does is put those function pointer values
into a crude stack pointed to by fs:. The beginning
of fs: includes a current fs stack pointer and a
maximum stack pointer. Compiler-generated code
will take care of checking those values.
The application does need to be correctly coded
such that function pointers are subject to prototype
checking so that you can't accidentally pass a
random data pointer as a function pointer.
Simple function pointers that are stored in global
variables or whatever are collected into the fs:
area at program initialization.
I can't see any way code in the data area can be
executed, no matter how trashed the data area is
by hackers.
Is that useful?
BFN. Paul.
other problematic code that allows the injection
of machine code by a hacker, is it possible to take
advantage of segmentation to fix this problem?
And perhaps this solution can be carried forward
to the S/380 segmentation.
First assume you only allow these executables onto
your PDOS/86 system:
https://wiki.osdev.org/MZ
If both the minimum and maximum allocation fields are cleared, MS-DOS will attempt to load the executable as high as possible in memory.
This allows you to have all your executables in high
memory, and all your data and stack in low memory.
The 8086+ supports setting an upper and lower
segment number for ds and ss to be set to. Any
attempt to load ds above that value (which would
reach into where the executables are stored) is
greeted with an exception.
You can assume that all data in the protected area
has been completely trashed by hackers taking
advantage of buffer overruns. It all contains deadly
machine code that can exploit bugs in the OS itself
if it is ever executed. The goal then is to ensure this
code is never executed.
So the above protection mechanism also prevents
code from being executed in the data area.
That just leaves function pointers. Segment register
fs: can (and must) point to the protected area, and
when a function is called, and function pointers are
pushed onto the stack, the first thing the called
function does is put those function pointer values
into a crude stack pointed to by fs:. The beginning
of fs: includes a current fs stack pointer and a
maximum stack pointer. Compiler-generated code
will take care of checking those values.
The application does need to be correctly coded
such that function pointers are subject to prototype
checking so that you can't accidentally pass a
random data pointer as a function pointer.
Simple function pointers that are stored in global
variables or whatever are collected into the fs:
area at program initialization.
I can't see any way code in the data area can be
executed, no matter how trashed the data area is
by hackers.
Is that useful?
BFN. Paul.