Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Security Software Linux

Exec Shield for the Linux Kernel 266

DarkOx writes "There is a new patch from Ingo Molnar which can prevent overflow attacks. The scoop from KernelTrap is as follows: Ingo Molnar has announced a new kernel-based security feature for Linux/x86 called 'Exec Shield'. He describes the patch, which is against the 2.4.20-rc1 kernel, as: 'The exec-shield feature provides protection against stack, buffer or function pointer overflows, and against other types of exploits that rely on overwriting data structures and/or putting code into those structures. The patch also makes it harder to pass in and execute the so-called 'shell-code' of exploits. The patch works transparently, ie. no application recompilation is necessary.'"
This discussion has been archived. No new comments can be posted.

Exec Shield for the Linux Kernel

Comments Filter:
  • grsec ? (Score:5, Interesting)

    by destiney ( 149922 ) on Saturday May 03, 2003 @10:51PM (#5872177) Homepage

    Sounds like much of the same security that's been available from grsecurity.net [grsecurity.net] for quite a while now.

    • Re:grsec ? (Score:3, Informative)

      by groomed ( 202061 )
      I'm not familiar with grsec, but from a brief glance at the grsec site I don't see how they are alike. grsec appears to be an ACL based security model, whereas exec-shield just makes it a lot harder for the CPU to execute code that was never meant to be executed (from the owner of the machine's point of view...).
      • Re:grsec ? (Score:2, Informative)

        by destiney ( 149922 )

        All I can say is try it. There's a lot more to it than just an ACL. In fact I don't even use the ACL, I use all the _other_ security enhancements it offers.

    • Re:grsec ? (Score:5, Informative)

      by cras ( 91254 ) on Sunday May 04, 2003 @12:04AM (#5872484) Homepage

      Yes, grsecurity includes equilevant protection to this. It uses PAX [virtualave.net] kernel patch for this. It has existed for years, and Ingo really should have mentioned that in his announcement, assuming he even knew about it?

      Difference is that PAX uses some weird x86 kludges to do this and it causes slight speed difference (max. 10% IIRC), but I think that's a very small penalty for very good protection against buffer overflows. It also reduces the maximum memory available to process by .. was it 1-2GB, but there's not many processes that really need that much. And Ingo's patch seems to limit at least number of executable pages even more so.

    • OpenBSD recently announced something similar. Are they in fact actually similar? Or are they just different approaches to the same problem?
  • by Anonymous Coward on Saturday May 03, 2003 @10:54PM (#5872195)
    prevent people from logging into X as root and screwing up their system.

    A cure for stupidity is a many-splendored thing - Publius Julius Caesar on the day before the ides of March ## B.C.
  • WOW! (Score:4, Interesting)

    by benna ( 614220 ) * <mimenarrator@g m a i l .com> on Saturday May 03, 2003 @10:54PM (#5872199) Journal
    Two stories today with reasons to switch to linux. First IE dies with simple HTML (But really is it any surprise that this is possible) and now a sweet knewe patch for linux. Could it be any better?
    • Re:WOW! (Score:5, Funny)

      by geddes ( 533463 ) on Sunday May 04, 2003 @12:01AM (#5872474)
      Two stories today with reasons to switch to linux
      You don't browse here often do you?
  • Ingo's announcement (Score:3, Informative)

    by steveha ( 103154 ) on Saturday May 03, 2003 @10:56PM (#5872208) Homepage
    http://people.redhat.com/mingo/exec-shield/ANNOUNC E-exec-shield [redhat.com]
    _____________________________________________

    [Announcement] "Exec Shield", new Linux security feature

    We are pleased to announce the first publically available source code
    release of a new kernel-based security feature called the "Exec Shield",
    for Linux/x86. The kernel patch (against 2.4.21-rc1, released under the
    GPL/OSL) can be downloaded from:

    http://redhat.com/~mingo/exec-shield/

    The exec-shield feature provides protection against stack, buffer or
    function pointer overflows, and against other types of exploits that rely
    on overwriting data structures and/or putting code into those structures.
    The patch also makes it harder to pass in and execute the so-called
    'shell-code' of exploits. The patch works transparently, ie. no
    application recompilation is necessary.

    Background:
    -----------

    It is commonly known that x86 pagetables do not support the so-called
    executable bit in the pagetable entries - PROT_EXEC and PROT_READ are
    merged into a single 'read or execute' flag. This means that even if an
    application marks a certain memory area non-executable (by not providing
    the PROT_EXEC flag upon mapping it) under x86, that area is still
    executable, if the area is PROT_READ.

    Furthermore, the x86 ELF ABI marks the process stack executable, which
    requires that the stack is marked executable even on CPUs that support an
    executable bit in the pagetables.

    This problem has been addressed in the past by various kernel patches,
    such as Solar Designer's excellent "non-exec stack patch". These patches
    mostly operate by using the x86 segmentation feature to set the code
    segment 'limit' value to a certain fixed value that points right below the
    stack frame. The exec-shield tries to cover as much virtual memory via the
    code segment limit as possible - not just the stack.

    Implementation:
    ---------------

    The exec-shield feature works via the kernel transparently tracking
    executable mappings an application specifies, and maintains a 'maximum
    executable address' value. This is called the 'exec-limit'. The scheduler
    uses the exec-limit to update the code segment descriptor upon each
    context-switch. Since each process (or thread) in the system can have a
    different exec-limit, the scheduler sets the user code segment dynamically
    so that always the correct code-segment limit is used.

    the kernel caches the user segment descriptor value, so the overhead in
    the context-switch path is a very cheap, unconditional 6-byte write to the
    GDT, costing 2-3 cycles at most.

    Furthermore, the kernel also remaps all PROT_EXEC mappings to the
    so-called ASCII-armor area, which on x86 is the addresses 0-16MB. These
    addresses are special because they cannot be jumped to via ASCII-based
    overflows. E.g. if a buggy application can be overflown via a long URL:

    http://somehost/buggy.app?realyloooooooooooooooooo oong.123489719875

    then only ASCII (ie. value 1-255) characters can be used by attackers. If
    all executable addresses are in the ASCII-armor, then no attack URL can be
    used to jump into the executable code - ie. the attack cannot be
    successful. (because no URL string can contain the \0 character.) E.g. the
    recent sendmail remote root attack was an ASCII-based overflow as well.

    With the exec-shield activated, and the 'cat' binary relinked into the the
    ASCII-armor, the following layout is created:

    $ ./cat-lowaddr /proc/self/maps
    00101000-00116000 r-xp 00000000 03:01 319365 /lib/ld-2.3.2.so
    00116000-00117000 rw-p 00014000 03:01 319365 /lib/ld-2.3.2.so
    00117000-0024a000 r-xp 00000000 03:01 319439 /lib/libc-2.3.2.so
    0024a000-00
  • How is this different from the buffer overflow protection offered by LIDS? Just asking...
    • LIDS doesn't offer stack overflow protection whereas this patch does. LIDS addresses different security areas as far as I know.
  • This is good. (Score:5, Interesting)

    by dracocat ( 554744 ) on Saturday May 03, 2003 @11:08PM (#5872273)
    While of course all of our software should be correct, using the Operating System to make software more robust is almost always a good thing.

    Assuming their claims of extremely low over-head are true, why would we not want this?

    In fact, a lot of security issues could be stopped before they ever happen if we look more closely at the Operating System instead of all the software! Think how much easier it would be to work on isolating software and protecting the system from itself than trying to make every single app ever written secure. Yes, focusing attention to the Operating System for vulerabilites is a good step--even though we can't ignore our applications.
  • Uh Oh... (Score:5, Funny)

    by Cylix ( 55374 ) * on Saturday May 03, 2003 @11:12PM (#5872293) Homepage Journal
    You do realise this kind of advancement would not be possible with out assistance from highly successful companies like SC...

    Hrm...

    "Shit, spaceballs, there goes the planet" --apes

  • by steveha ( 103154 ) on Saturday May 03, 2003 @11:18PM (#5872328) Homepage
    I'm trying to understand this fully, but I don't have all the background to do so.

    From the announcement:

    It is commonly known that x86 pagetables do not support the so-called executable bit in the pagetable entries - PROT_EXEC and PROT_READ are merged into a single 'read or execute' flag. This means that even if an application marks a certain memory area non-executable (by not providing the PROT_EXEC flag upon mapping it) under x86, that area is still executable, if the area is PROT_READ.

    Is this limitation in the x86 processor MMU, or in the Linux kernel?

    Is anyone working to fix this limitation? (E.g. AMD fixing it in 64-bit mode on the Opteron, or someone reworking the Linux kernel)

    Furthermore, the x86 ELF ABI marks the process stack executable, which requires that the stack is marked executable even on CPUs that support an executable bit in the pagetables.

    Does this statement imply that some x86 processors do the right thing with PROT_EXEC?

    If Linus is willing to create a new ELF standard, could this problem be fixed? Would it be worth the pain of a new incompatible ELF standard? Are there any other problems that can only be fixed with a new version of ELF, so we can fix them together?

    It would be sort of cool to get a new ELF standard, so that Linus can call the new kernel "3.0"! :-)

    steveha
    • by Anonymous Coward on Saturday May 03, 2003 @11:34PM (#5872381)
      The limitation is with most x86 processors. The new AMD x86-64 architecture does not suffer from this problem, and I believe linux on it defaults to nonexecutable stack (at least that's what was said on the LKML).
      • by Anonymous Coward
        The problem exists in all x86-32 processors, and always has. AMD's Opteron x86-64 does have the ability to mark such code as non-executable while readable, but only in x86-64 mode. 32-bit applications will still suffer.

        While I applaud the effort made for this product, I still believe that the only way to completely shield ourselves from such attacks is to enforce it in hardware.
    • by mark-t ( 151149 ) <markt AT nerdflat DOT com> on Sunday May 04, 2003 @01:30AM (#5872735) Journal
      Is this a limitation of the x86? No, not really.

      The problem is the way that people use x86's paging mechanism. Each page can, in fact, be distinctly assigned to being either code or data, but because each page requires a distinct entry in the page table, if each process had to have separate code and data pages, then it would stand to double the number of page table entries.

      So why did they do it this way, if it was so simple to avoid? Back in the early 90's, when Linux was first written, it was highly desirable (with protected mode code in general) to minimize distinct page table entries in the x86 because page tables could take up so much space. So protected mode programs (and operating systems) were typically designed so that the code and data segment descriptors could end up mapping to the same pages in the x86's paging mechanism to reduce overall page count.

      Indeed, if the x86 had not allowed a page to be both writeable and executable, then this would never have been an issue. Although it would have had the memory overhead in the page table entries that I described earlier, since we wouldn't have even had a choice in the matter, we would have just had to settle for what we got (although back then the design would have likely been criticized as being wasteful of memory).

      • by mark-t ( 151149 ) <markt AT nerdflat DOT com> on Sunday May 04, 2003 @01:43AM (#5872759) Journal
        I realized after I had clicked submit that I had forgotten to point out how it all comes together.

        If and when different pages are used for code and data, since both already use different segment descriptors, the code and data have their own completely isolated address spaces, so trying to invoke a buffer overflow that would cause a "return" to some point in the user-supplied data would actually simply cause a return to the corresponding point in the code page, which is, of course, not actually modified by the application. At best, a buffer overflow could cause a branch to a particular section of the existing program, but would not permit the execution of arbitrary code since in the ideal case, even the kernel code resides in an address space that is invisible to any running application. The most probable upshot of trying to "return" in this fashion would be a segmentation fault, which should result in no more than the application simply terminating with a core dump.

    • by HidingMyName ( 669183 ) on Sunday May 04, 2003 @01:37AM (#5872751)
      Read or execute may only be a problem because when we want to allow stack access with read/write permissions, we wind up granting execute/write permissions. I think OpenBSD is working on getting rid of having both write and execute permissions on the same memory region. However, Linux may not be able to follow suit due to the use of trampoline functions (as described here [linuxjournal.com]). How OpenBSD plans to get around this, I'm not sure, it is possible that I have a faulty memory regarding OpenBSD's avoidance of write/execute in the kernel.
      • Trampolines (Score:4, Insightful)

        by Vlad_the_Inhaler ( 32958 ) on Sunday May 04, 2003 @07:16AM (#5873691)
        My 'day job' is programming on a mainframe. This is how they go about handling this.

        16 'segments' (call them what you will) can be based (pointed to) at any one time, each by one base-register.
        B0 points to code
        B1 points to the stack
        B2-B15 point to data segments.
        If you want to point B0 to another executable segment, you have to execute CALL, GOTO or RTN (return :-). A code segment does not have to be read-only, but normally is. The only other 'trampolining' permitted is by using the EXecute instruction which allows you to execute one instruction in any segment. Executing (for example) a Jump instruction would be of little use to a cracker because the target address would automatically be in the segment referenced by B0.

        Yes, we can have buffer-overflows, but 'all' that happens is that other data is overwritten. This will usually cause the program to abort. It is even possible to organise things so that every routine has it's own discrete data-segments. If a routine then starts accessing data outside of the routine, it gets the equivalent of a Segfault. Obviously parameters/arguments are excepted from this, although there would also be a Segfault if a routine went outside it's caller's data-area.
        Actually, the hardware allows a caller to restrict a subroutine's access to only the n bytes it actually passed over as an argument. The HLL implementations do not enforce this setting in any of the languages I use.

        Segment attributes are from Owner-Read, Owner-Write, Owner-Execute, Other-Read, Other-W and Other-X. Segments also have a Sharing-Level which is: Activity, Program, Application and Exec/System. Exec/System is normally combined with Other-Access: None, Application is normally combined with Read+Execute.

        How much damage is caused each year because the 32-bit I386 architecture cannot supply a reasonable security framework at a reasonable overhead? If the AMD 64-bit processors are capable of fixing this mess, then the GLIBC maintainers could start looking at (optionally?) allowing a safer implementation by separating Code and Data. If this incurs memory-overhead, server farms should be migrating to 64-bit processors anyway by the time such a feature became available. They could also always compile the libraries without that feature.
    • by IkeTo ( 27776 ) on Sunday May 04, 2003 @02:04AM (#5872832)

      This means that even if an application marks a certain memory area non-executable (by not providing the PROT_EXEC flag upon mapping it) under x86, that area is still executable, if the area is PROT_READ.

      Does this statement imply that some x86 processors do the right thing with PROT_EXEC?

      No. The x86 page table has 12 bits per page table entry for storing page information. It contains a bit for R/W (read/write) which you can force a page read-only; and it contains a bit U/S (user/supervisor) which you can force a page usable only by the kernel. There is nothing which says "this page must not be executed as code". So Linux kernel actually has an interface that only some hardware provides. I don't think now it still has spare bit to give for executable bit.

      Furthermore, the x86 ELF ABI marks the process stack executable, which requires that the stack is marked executable even on CPUs that support an executable bit in the pagetables.

      Does this statement imply that some x86 processors do the right thing with PROT_EXEC?

      It is not about "do the right thing". The processor simply has no such bit, so there is no new "right thing" for it to do---it is already doing the right thing. The processor assumes that segmentation is used to enforce execute permission, so that each library code should be allocated a segment and inter-segment jumps and calls should be used to access them. In such way only read-only code segments are executable. Linux simply decided at the very beginning not to employ this facility.

      If Linus is willing to create a new ELF standard, could this problem be fixed?
      ELF is not designed by Linus. And even if ELF is changed so that stack is not assumed executable by default (which probably break some programs that rely on executable stack), all computers from 386 to P4 will not benefit from it.
      • Intel did not designed it correctly. They should have put 2 bits for Read, 2 bits for Write and 2 bits for eXecute access. These 2 bits per type of access should be the maximum ring number allowed to touch the page.

        For example, a page could be data only if the Read and Write ring was 3, but the eXecute ring was 0. Then, only the kernel would be able to execute code in that page.

        This scheme is very flexible: there can be read-only pages, write-only pages, exec-only pages, or any combination of the three. F
  • by Anonymous Coward on Saturday May 03, 2003 @11:19PM (#5872330)

    Another saturday night spent on /. When I look back, this is what I'll remember.
  • easier on x86-64 (Score:5, Informative)

    by ceswiedler ( 165311 ) * <chris@swiedler.org> on Saturday May 03, 2003 @11:23PM (#5872345)
    Someone on lkml asked:

    Slightly off-topic, but does anybody know whether IA64 or x86-64 allow you to make the stack non-executable in the same way you can on SPARC?

    and hpa replied to this:

    x86-64 definitely does, and it's the default on Linux/x86-64.

    Up to now, x86 chips have not been able to separate Read from Execute privileges for memory segments, which makes it hard to make stacks non-executable. This is excellent news for anyone looking forward to AMD's x86-64 chips...it keeps looking like they've done the Right Things.
    • IA-64 Allows for it as well. It also has region support, so that executable and stack regions of memory can be completely separate.

      adam
    • Up to now, x86 chips have not been able to separate Read from Execute privileges for memory segments

      On x86, the stack segment can be a different area of memory than the app's memory space. It is just Linux that implements it that way.

      A long time ago I proposed that the SS register should point to another area of memory which is not executable. People replied by pointing out that the way GCC implements trampolines requires code to be executable from the stack. I strongly disagree with trampolines, as I

  • by Fefe ( 6964 ) on Saturday May 03, 2003 @11:25PM (#5872354) Homepage
    The page says they are mapping all the code in the lower 16 MB of the address space. And they keep the first MB unmapped for NULL pointer protection.

    That leaves us with only 15 MB of space for code!

    Are they really trying to say that they have not hit that limit yet? No program on earth has more than 15 MB code?! I can hardly believe that.

    I was going to cite Emacs on this one, but Emacs is an interpreter, so the actual interpreter code might be small enough. Mhh. What about Mozilla?

    Heck, what about WINE?! ;) They are emulating Windoze, you can't be serious about those 15 MB! That'll hardly contain GDI.DLL!
  • Possible Problem (Score:5, Interesting)

    by Sunlighter ( 177996 ) on Saturday May 03, 2003 @11:26PM (#5872356)

    I've written a few pieces of code which take advantage of the executability of the stack and the heap. For example if you want to write a just-in-time compiler for some language, an easy way to do it is allocate an area on the heap, let the JIT compiler write the appropriate x86 machine code into that area, and then typecast the area pointer to a function pointer and execute it.

    With this patch, that won't work...

    • Couldn't there be some sort of syscall to allow executing your stack, with the default set to "no"?
    • Re:Possible Problem (Score:5, Informative)

      by Soko ( 17987 ) on Saturday May 03, 2003 @11:50PM (#5872436) Homepage
      Would a memcopy from the heap into executeable space be a fix?

      Perhaps even better would be to have your own "private" heap in userland. That would protect the OS, and you get to use your trick still.

      I'm not a coder by trade, so I can't really critisize what you're doing. I do understand operating systems and memory allocation therein though, so my admittedly uninformed opinion is that you're employing a somewhat dangerous hack here. The heap was not intended to hold executeable programs - you'd be broken on x86-64 as well. Using what amounts to a design flaw in a program isn't what I would be willing to call "good design". Might be better to come up with a different method - Ingo Molnar seems to think you do at any rate.

      Soko
      • by dvdeug ( 5033 )
        you're employing a somewhat dangerous hack here.

        Dynamically writing code is not a dangerous hack. The more correct way of solving this problem is for people not to use unchecked arrays that can overflow - C, C++ and a few other really low level languages about the only languages that have unchecked arrays as a standard data type. Most of these problems don't show up in programs written in other languages.
        • What I hate most about the C family of languages, is that the only terminator for a string is a binary zero.
          It is not possible (at least in the implemention available to me) to ask 'how big is that string, physically'?

          The language I use on a day-to-day basis is (shock, horror) Cobol.
          Given a 50-byte field FIELD-50 and a 100-byte field FIELD-100,
          • MOVE FIELD-50 TO FIELD-100
            copies FIELD-50 to the first 50 bytes of FIELD-100 and fills the rest with spaces.
          • MOVE FIELD-100 TO FIELD-50
            copies the first 50 bytes of
    • Will work fine ... (Score:5, Informative)

      by DarkMan ( 32280 ) on Sunday May 04, 2003 @12:02AM (#5872477) Journal
      ... assuming that the stack memory is marked as executable in the binary - which will have the net effect of turning off the Exec-shield.

      In other words, ELF format has flags to indicate if the stack should be readable and/or executable. If your doing that sort of thing, make sure that the flag is set, and you'll have no problems [0].

      It your doing those sort of tricks, your probably being very careful with what goes where, and buffer lengths and such. The problems come in when people don't realise that there could be a problem, and don't audit the buffer handling code properly.

      So, don't worry, just use the ELF flags.

      [0] Well, you could set the feature to ignore what the binary says, and implement the security anyway. But that's not a good idea, and very much not default.
    • Sunlighter says:

      I've written a few pieces of code which take advantage of the executability of the stack and the heap. [...] With this patch, that won't work...

      Fear not my friend :-) . Please read the announcement from Ingo:

      Applications that need to rely on gcc trampolines will have to use the per-binary ELF flag to make the stack executable again.

      [...]

      There is a new boot-time kernel command line option called exec-shield=,
      which has 4 values. Each value represents a different level of security

    • Not entirely accurate. The patch has 4 modes of operation. Always-on and always-off, as well as "on unless the app says so" or "off unless the app says so" modes. The patch can easily be told not to step on any application's toes.
    • Re:Possible Problem (Score:3, Interesting)

      by sgifford ( 9982 )
      Instead of allocating from the heap with malloc, just create an anonymous memory map using mmap, setting PROT_EXEC to allow execution. Something like:

      m = mmap(NULL,
      1000000,
      PROT_READ|PROT_WRITE|PROT_EXEC,
      MAP_PRIVATE|MAP_ANON,
      -1,
      0);

      will allocate 1000000 bytes of memory which can contain executable code on Linux and BSD. On some other Unices you have to use /dev/zero, but the technique is pretty much the same.
    • That's the only point that code and data are interchangeable, methinks. On-the-fly production of machine code should be treated by an interface provided by the OS to copy the heap object to the app's exec memory or map the page to the exec memory. Right now, you're in trouble.
  • by Farley Mullet ( 604326 ) on Saturday May 03, 2003 @11:31PM (#5872371)

    (As I'm sure you can tell) I don't claim to know much about any of this at all, but I did read the kerneltrap post, for what it was worth, and as a non-x86 user, I have a few questions. Ingo's patch is only for x86; is equivalent protection for other architectures possible, or even necessary? To what extent are buffer-overflow exploits architecture specific?

    Sorry if I'm missing something simple here.

    • by DarkMan ( 32280 ) on Sunday May 04, 2003 @12:15AM (#5872528) Journal
      Yes you could do this for other hardware plaforms.

      However ... most other CPU's have had the ability to use writable but not executable and executable but not writable heaps for a while. x86 does not. This is why you get a whole bundle of problems with it, as buffer overruns write code in the heap, then get it executed. The patch is an atempt to mitigate the adverse effects of that hardware weakness.

      It's not perfect (nor is the better hardware solution). However, it will make many exploits an order of magnitude more complex, making writing and utilising them a much more complex task.

      The part about locating code inside the ASCII armour is, however, zero overhead, and will, I think, get wrapped into mainline on all archtectures (although possbily not till 2.7)
  • openwall patch (Score:4, Informative)

    by wotevah ( 620758 ) on Saturday May 03, 2003 @11:34PM (#5872383) Journal
    This feature looks similar to what the openwall patch does since the 2.0 kernels ( http://www.openwall.com/linux/ ).

    Quoting from the README: Non-executable user stack area.

    Most buffer overflow exploits are based on overwriting a function's return address on the stack to point to some arbitrary code, which is also put onto the stack. If the stack area is non-executable, buffer overflow vulnerabilities become harder to exploit.

    Another way to exploit a buffer overflow is to point the return address to a function in libc, usually system(). This patch also changes the default address that shared libraries are mmap()'ed at to make it always contain a zero byte. This makes it impossible to specify any more data (parameters to the function, or more copies of the return address when filling with a pattern), -- in many exploits that have to do with ASCIIZ strings.

    However, note that this patch is by no means a complete solution, it just adds an extra layer of security. Many buffer overflow vulnerabilities will remain exploitable a more complicated way, and some will even remain unaffected by the patch. The reason for using such a patch is to protect against some of the buffer overflow vulnerabilities that are yet unknown.

  • Silly me (Score:4, Funny)

    by MHV ( 547208 ) on Saturday May 03, 2003 @11:42PM (#5872408)
    And I thought it was a kernel patch to
    prevent stupid business executives to
    ask questions about Linux mindshare and
    the like...
  • by CoolVibe ( 11466 ) on Saturday May 03, 2003 @11:46PM (#5872418) Journal
    what about local attacks using the global offset table or return-into-libc function pointer overwriting attacks? With those you can put executable code somewhere else and use another trampoline instead of a return address.

    Sure, this will nullify most remotely exploitable vulnerabilities, but what about local ones that are vulnerable in the manners I just described?

    • Well apparently it deals with that as well, by moving system libraries to an "ASCII-armor" area from 0x00000000-0x00ffffff. This is supposed to be safe since ASCIIZ strings can't contain 0s. ...but I think there's a flaw with that, ASCIIz strings will always contain *one* 0, the terminating one. Since x86 stores addresses as little endian, the high byte in the address will be the last byte in memory. If you arrange for the terminating NULL to be at the last byte of the return address, you can jump to tha
  • by Anonymous Coward on Saturday May 03, 2003 @11:57PM (#5872456)
    My name is Igno Molnar
    You kill -9 my ppid
    prepare to die!
  • Typo in post (Score:5, Informative)

    by localghost ( 659616 ) <dleblanc@gmail.com> on Saturday May 03, 2003 @11:58PM (#5872461)
    It's against the 2.4.21-rc1 kernel, not 2.4.20-rc1.
  • by Indy1 ( 99447 ) on Sunday May 04, 2003 @12:12AM (#5872520)
    is this a patch i should have installed on my various linux servers? I understand any new code should be tested on a development server before being moved to production, but assuming this patch doesnt cause any problems, is it something thats worth the time and effort to help reduce buffer overflows ?
    • is this a patch i should have installed on my various linux servers?

      Yes. Everyone should have installed grsecurity [grsecurity.net] long time ago for their servers, which provides this protection and much more. It includes ACLs which requires some work to get working, but you don't have to use them. Non-exec stack+heap and address space randomizations require nothing but upgrading the kernel and possibly disabling them for a few binaries that don't like them. I'd guess grsec will include Ingo's patch with it as alternativ

  • by larryjoe ( 135075 ) on Sunday May 04, 2003 @12:30AM (#5872570)
    Reading the announcement for Exec Shield, I can see that the author is aware of the work of Solar Designer, who released the first non-execuable stack solution many years ago. However, I don't see any mention of PaX [virtualave.net], which extends the the Openwall solution to other memory regions.

    It should also be pointed out that while most buffer overflow exploits do indeed simultaneously overwrite the return address and inject the shellcode onto the stack, a certain class of buffer overflow exploits called return-into-libc attacks do not require executable stacks and are not too difficult to construct. These attacks overwrite the return address with the starting address for one of the libc exec*() functions. At the same time, the parameters for executing /bin/sh are pushed onto the stack. The execution of the corresponding return instruction then causes the exec*() function to execute /bin/sh. See this paper [securityfocus.com] for a more detailed analysis of some buffer overflow solutions.

    I think that it's interesting that in the past few weeks, several solutions for buffer overflows have been announced (e.g., the OpenBSD announcements). Each of these solutions are good solutions, but they heavily borrow from earlier solutions. Unfortunately, the previous work has often not been properly acknowledged. Since the masses are generally not aware of the current state of the art, these supposedly new solutions are given more credit than due. Still, I suppose it's a good thing if general awareness of the buffer overflow problem is raised, even if the pioneers of the technology do not receive their due credit.

    Tim Tsai

  • by Theovon ( 109752 ) on Sunday May 04, 2003 @01:15AM (#5872695)
    Maybe I'm missing something really simple, but here's my understanding:

    1) x86 stack grows from high addresses to lower ones, allowing for a string allocated on the stack to overflow such that it overwrites the return address.

    2) x86 is little-endian which means that the return address (in this case, on the stack) starts with the low byte and stops with the high byte.

    3) In C programs, strings are null-terminated.

    The ASCII shield relies on ASCII not being able to represent certain addresses, namely 0x00000000 to 0x0100ffff.

    Well, here's what I don't get. Assuming all three above, there are five possibilities we can generate for overwriting an address:

    1) All four address bytes are overwritten by ASCII characters generating an address greater than 0x01010101.

    2) The first three bytes are overwritten by ASCII characters, and the last one is overwritten by the null terminator. This results in an address between 0x00010101 and 0x00ffffff. This certainly looks like an address within the 16M "armor"

    3-5) For (3), we only overwrite three of the address bytes, the first two being ASCII, and the last being NUL, resulting in an address something like 0x??00AAAA, where AAAA is greater than 0x0101. This would require that the attacker know what the upper byte of the address is, which is possible. (4) and (5) represent similar situations.

    As far as I can see, this 16M protected region doesn't exist. WHAT AM I MISSING?

    Thank you.
    • You know.. you may be right.. consider this little program. It is a series of characters in an array.. the characters are 0x01,0x01,0x01,0x00 (as was your case (2)). When you print this out as an int, you get 65793. This is certainly less than 16 million.

      #include <stdio.h>
      #include <string.h>

      int main(void)
      {
      char arr[sizeof(int)] = { 0x01, 0x01, 0x01, 0x00 };

      printf("%d\n", *((int *)arr));
      return 0;
      }

      So I don't get what Ingo means when he says that this region is somehow ASCII-shielded
    • The exec*() and system() calls need parameters, which need to follow the return address. Since the return address is necessarily the last part of the attack, it is not possible to write these parameters.

      So unless spawn_shell(void) exists, the armoring is quite effective.

  • Even though this Exec Shield Owerflow Protection is great; where is the Executive owerflow protection that will protect me from my boss when he wants to execute me?
  • Windows (Score:5, Informative)

    by thalakan ( 14668 ) <jspence AT lightconsulting DOT com> on Sunday May 04, 2003 @01:17AM (#5872700) Homepage
    I've been screwing around with mprotect() and friends lately to write a exploit delivery system that can't be read by memory inspection tools on the target machine. While checking to see if similar techniques are possible on Windows, I found that the default addresses for PE/i386 executables' stack and text sections are all below 0x00ffffff. .text begins at 0x00400000, for example, and the stack is located below it.

    So it looks like Microsoft beat Ingo to it :) I was wondering for the longest time why they chose those mappings by default until I saw this article today.
    • If you use linux with BIG_MEM (3GB/1GB split) enabled in the kernel, your .text segment is allocated starting at 0x00010000. I forget why but there was some simplicity to using the 1GB/1GB split otherwise on linux (.text starting at 0x80000000, kernel mem at 0xc0000000). Windows uses a default 2GB/2GB split, so it makes sense it would start at 0x0. I don't think they were thinking about ASCII armor when they made that decision in the NT 3.x days.

  • i hope this gets included into the vanilla kernel - i was quite shocked to learn initially that while e.g. true 64 (formerly known as digital unix formerly known as osf/1) had a non-executable stack and linux didn't (which i now understand was a problem with x86 vs. alpha hardware, not linux in particular).

    and i sure hope that the non-exec flag has been implemented on amd's and intel's 64 bit cpus.
  • ASCII-Armor area (Score:3, Interesting)

    by 42forty-two42 ( 532340 ) <bdonlan@NoSpAM.gmail.com> on Sunday May 04, 2003 @10:08AM (#5874118) Homepage Journal
    What happens if an executable maps in more than 16mb of shared libraries? Will one of these libraries get mapped to NULL? Or will it forgoe security for actually working?
  • by g4dget ( 579145 ) on Sunday May 04, 2003 @04:18PM (#5876250)
    The exec-shield feature works via the kernel transparently tracking executable mappings an application specifies, and maintains a 'maximum executable address' value. This is called the 'exec-limit'. The scheduler uses the exec-limit to update the code segment descriptor upon each context-switch. Since each process (or thread) in the system can have a different exec-limit, the scheduler sets the user code segment dynamically so that always the correct code-segment limit is used.

    Programs compiled for the x86 architecture may well assume that they don't have to set the executable bit on pages because the hardware doesn't support it anyway. Whether such programs are "correct" or not, this patch may break applications.

It's a naive, domestic operating system without any breeding, but I think you'll be amused by its presumption.

Working...