Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch > #31185 > unrolled thread
| Started by | Quadibloc <jsavard@ecn.ab.ca> |
|---|---|
| First post | 2015-11-24 06:44 -0800 |
| Last post | 2015-11-24 16:39 -0800 |
| Articles | 20 on this page of 53 — 13 participants |
Back to article view | Back to comp.arch
Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-24 06:44 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-24 06:59 -0800
Re: Fractal Variable-Length Instructions? Ivan Godard <ivan@millcomputing.com> - 2015-11-24 16:42 -0800
Re: Fractal Variable-Length Instructions? mrs@kithrup.com (Mike Stump) - 2015-11-24 22:27 +0000
Re: Fractal Variable-Length Instructions? Terje Mathisen <terje.mathisen@tmsw.no> - 2015-11-25 07:48 +0100
Re: Fractal Variable-Length Instructions? mrs@kithrup.com (Mike Stump) - 2015-11-26 18:21 +0000
Re: Fractal Variable-Length Instructions? MitchAlsup <MitchAlsup@aol.com> - 2015-11-24 15:01 -0800
Re: Fractal Variable-Length Instructions? mrs@kithrup.com (Mike Stump) - 2015-11-24 23:33 +0000
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-24 16:44 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-27 18:07 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-27 18:11 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-12-04 22:56 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-28 08:30 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-24 17:35 -0800
Re: Fractal Variable-Length Instructions? Terje Mathisen <terje.mathisen@tmsw.no> - 2015-11-25 08:21 +0100
Re: Fractal Variable-Length Instructions? Ivan Godard <ivan@millcomputing.com> - 2015-11-24 23:31 -0800
Re: Fractal Variable-Length Instructions? Terje Mathisen <terje.mathisen@tmsw.no> - 2015-11-25 08:38 +0100
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-11-25 03:23 -0800
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-25 06:20 -0800
Re: Fractal Variable-Length Instructions? Walter Banks <walter@bytecraft.com> - 2015-11-25 11:50 -0500
Re: Fractal Variable-Length Instructions? Megol <golem960@gmail.com> - 2015-11-25 12:30 -0800
Re: Fractal Variable-Length Instructions? MitchAlsup <MitchAlsup@aol.com> - 2015-11-25 17:53 -0800
Re: Fractal Variable-Length Instructions? George Neuner <gneuner2@comcast.net> - 2015-11-25 20:35 -0500
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-11-26 00:34 -0800
Re: Fractal Variable-Length Instructions? George Neuner <gneuner2@comcast.net> - 2015-11-26 12:53 -0500
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-11-26 10:32 -0800
Re: Fractal Variable-Length Instructions? Stefan Monnier <monnier@iro.umontreal.ca> - 2015-12-01 14:45 -0500
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-01 12:12 -0800
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-05 14:19 +0000
Re: Fractal Variable-Length Instructions? nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-05 14:56 +0000
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-05 16:48 +0000
Re: Fractal Variable-Length Instructions? nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-05 17:38 +0000
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-06 15:21 +0000
Re: Fractal Variable-Length Instructions? nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-06 16:43 +0000
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-08 13:55 +0000
Re: Fractal Variable-Length Instructions? Chris Gray <cg@GraySage.COM> - 2015-12-05 11:05 -0700
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-06 14:04 +0000
Re: Fractal Variable-Length Instructions? Chris Gray <cg@GraySage.COM> - 2015-12-06 11:09 -0700
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-06 09:15 -0800
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-08 13:43 +0000
Re: Fractal Variable-Length Instructions? nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-08 14:01 +0000
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-08 16:57 +0000
Re: Fractal Variable-Length Instructions? nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-08 18:02 +0000
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-08 06:11 -0800
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-08 16:08 +0000
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-12-08 10:43 -0800
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-12 17:06 +0000
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-08 11:29 -0800
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-12 18:10 +0000
Re: Fractal Variable-Length Instructions? Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-12 15:00 -0800
Re: Fractal Variable-Length Instructions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-13 16:12 +0000
Re: Fractal Variable-Length Instructions? George Neuner <gneuner2@comcast.net> - 2015-12-01 21:27 -0500
Re: Fractal Variable-Length Instructions? Quadibloc <jsavard@ecn.ab.ca> - 2015-11-24 16:39 -0800
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Megol <golem960@gmail.com> |
|---|---|
| Date | 2015-11-25 12:30 -0800 |
| Message-ID | <79d7740c-3475-4dab-b1af-1081560dd550@googlegroups.com> |
| In reply to | #31210 |
On Wednesday, November 25, 2015 at 12:23:09 PM UTC+1, Bruce Hoult wrote: > On Wednesday, November 25, 2015 at 10:21:22 AM UTC+3, Terje Mathisen wrote: > > With the continously increasing gap between streaming bandwidth and > > random access, it is pretty obvious that you would want immediates of > > almost arbitrary size as long as you knew they would be accessed each > > time the code came this way. > > How often (outside perhaps of FP code) do you have a large literal with a lot of significant bits? > > ARM64 lets you load or merge a 16 bit literal within the 32 bit instruction into any quarter of a 64 bit register. If you use two such instructions it's no worse than a hypothetical opcode that is followed by a 32 bit literal. Even loading all four quarters of the register like this is only 16 bytes, vs 12 bytes for a hypothetical opcode that is followed by a 64 bit literal. > > Even in Thumb1, it's usually pretty convenient and fast to load a large literal placed after the next unconditional branch (at worst, the end of the function, but in any case within 1 KB), using PC-relative addressing. We are talking of a new design so why not assume good support for immediate values: all (or at least most) instructions can replace one source operand with a 32 or 64 bit value. A special load-immediate instruction can store either a 24 bit (from instruction word) or 56 bit (24+following 32 bits) value sign-extended into any integer register. Then in comparison to AARCH64 only one instruction of 64 bits (8 bytes) is needed to load most 64 bit constants. If that isn't possible the absolutely worst case would use something like: ADD R1, ZERO, #IMM64 which would be one instruction of 96 bits (12 bytes).
[toc] | [prev] | [next] | [standalone]
| From | MitchAlsup <MitchAlsup@aol.com> |
|---|---|
| Date | 2015-11-25 17:53 -0800 |
| Message-ID | <86547279-8739-4974-a616-113dd8e10854@googlegroups.com> |
| In reply to | #31219 |
On Wednesday, November 25, 2015 at 2:30:47 PM UTC-6, Megol wrote: > > We are talking of a new design so why not assume good support for immediate values: all (or at least most) instructions can replace one source operand with a 32 or 64 bit value. A special load-immediate instruction can store either a 24 bit (from instruction word) or 56 bit (24+following 32 bits) value sign-extended into any integer register. My ISA allows 16-bit immediates in the std instruction word, and 32-bit and 64-bit immediates in successive instruction words. It also supports 16-bit, 32-bit, and 64 bit displacements in memory references. And finally supports 32-bit and 32-bit store data immediates along with 32-bit and 64-bit displacements all in one instruction. Mitch
[toc] | [prev] | [next] | [standalone]
| From | George Neuner <gneuner2@comcast.net> |
|---|---|
| Date | 2015-11-25 20:35 -0500 |
| Message-ID | <k6nc5bpndc5d0rk7sak5fhemtabhvsb3uv@4ax.com> |
| In reply to | #31210 |
Reformatted long lines. On Wed, 25 Nov 2015 03:23:06 -0800 (PST), Bruce Hoult <bruce.hoult@gmail.com> wrote: >How often (outside perhaps of FP code) do you have a large literal with a lot >of significant bits? Depending on the CPU, any time you load a pointer literal. >ARM64 lets you load or merge a 16 bit literal within the 32 bit instruction into >any quarter of a 64 bit register. If you use two such instructions it's no worse >than a hypothetical opcode that is followed by a 32 bit literal. Even loading all >four quarters of the register like this is only 16 bytes, vs 12 bytes for a hypothetical > opcode that is followed by a 64 bit literal. MIPs does similar. ISAs that permit - or worse, encourage - piece wise loading of immediate values cause major headaches for GC trying to locate heap references embedded into code - which is a relatively common practice for JIT compiling. A particularly nasty case of "derived" pointers. George
[toc] | [prev] | [next] | [standalone]
| From | Bruce Hoult <bruce.hoult@gmail.com> |
|---|---|
| Date | 2015-11-26 00:34 -0800 |
| Message-ID | <d2a99686-de20-4cc1-b6c5-a724abce892b@googlegroups.com> |
| In reply to | #31222 |
On Thursday, November 26, 2015 at 4:35:25 AM UTC+3, George Neuner wrote: > Reformatted long lines. > > On Wed, 25 Nov 2015 03:23:06 -0800 (PST), Bruce Hoult > <bruce.hoult@gmail.com> wrote: > > >How often (outside perhaps of FP code) do you have a large literal with a lot > >of significant bits? > > Depending on the CPU, any time you load a pointer literal. That sounds like "practically never" in normal code. Static addresses are usually either PC relative, or at least in the top or bottom 2 GB of address space. Either way, you're talking 32 bits which is not "large" in the context of this discussion. i.e. can be loaded embedded in two instructions, which is the same code size as one instruction followed by a literal. > >ARM64 lets you load or merge a 16 bit literal within the 32 bit instruction into > >any quarter of a 64 bit register. If you use two such instructions it's no worse > >than a hypothetical opcode that is followed by a 32 bit literal. Even loading all > >four quarters of the register like this is only 16 bytes, vs 12 bytes for a hypothetical > > opcode that is followed by a 64 bit literal. > > MIPs does similar. > > ISAs that permit - or worse, encourage - piece wise loading of > immediate values cause major headaches for GC trying to locate heap > references embedded into code - which is a relatively common practice > for JIT compiling. A particularly nasty case of "derived" pointers. As a GC specialist from time to time working with JITs, I'd say that is bogus. If you're embedding some object reference into JIT code then you by definition already have a pointer to that object elsewhere. It's trivial to ensure a copy of that pointer hangs around -- usually it's going to happen anyway.
[toc] | [prev] | [next] | [standalone]
| From | George Neuner <gneuner2@comcast.net> |
|---|---|
| Date | 2015-11-26 12:53 -0500 |
| Message-ID | <acce5b5u4pevjg4nhn531l1rk0cvg9qobe@4ax.com> |
| In reply to | #31225 |
On Thu, 26 Nov 2015 00:34:36 -0800 (PST), Bruce Hoult <bruce.hoult@gmail.com> wrote: >On Thursday, November 26, 2015 at 4:35:25 AM UTC+3, George Neuner wrote: > >> ISAs that permit - or worse, encourage - piece wise loading of >> immediate values cause major headaches for GC trying to locate heap >> references embedded into code - which is a relatively common practice >> for JIT compiling. A particularly nasty case of "derived" pointers. > >As a GC specialist from time to time working with JITs, I'd say that is bogus. > >If you're embedding some object reference into JIT code then you by definition >already have a pointer to that object elsewhere. It's trivial to ensure a copy of >that pointer hangs around -- usually it's going to happen anyway. If you think it's "bogus", then it's likely you hav never tried to compile a language that has 1st class closures. In many cases the storage allocated for the free variables doesn't exist prior to compiling - i.e. an interpreted version never existed (or it never ran to allocate storage). Once transient data structures of the compiler are gone, the pointer to the heap object may not exist anywhere other than in the generated code. It isn't always feasible to embed static data into a code block and do IP relative loads. Nor is it always convenient to pass the context from calling code [maybe have to recompile that], or to pass around "wide" pointers that carry the context with the entry point. Embedding pointers as immediates in the function itself works on any CPU and allows references to closure functions to be simple normal width pointers - which by itself has a number of advantages. Where there are full width pointer immediates, extracting pointers from code is no different than extracting them from any data structure. When the pointer are being pieced together from parts of multiple instructions, extracting them from code becomes more complicated. When you have MB or GB to play with, you will JIT compile function by function and there will be a linkage table apart from the code. That isn't necessarily so on a small(ish) system. There you might very well JIT some whole portion of the call tree, save only the top level entry point and throw away the portable code. Then there may be many heap object pointers embedded deep in the code. I'm not a GC "specialist" per se, but I'm pretty well versed in it, and I have experience implementing compilers and GC runtimes for Lisp-like and FP languages. (including on some unconventional architectures - e.g., on DSPs). Everything is not (yet) an ARM or an x86. YMMV, George
[toc] | [prev] | [next] | [standalone]
| From | Bruce Hoult <bruce.hoult@gmail.com> |
|---|---|
| Date | 2015-11-26 10:32 -0800 |
| Message-ID | <bdc15b5c-6022-4ca0-bc3b-20214bd814c7@googlegroups.com> |
| In reply to | #31249 |
On Thursday, November 26, 2015 at 8:53:28 PM UTC+3, George Neuner wrote: > On Thu, 26 Nov 2015 00:34:36 -0800 (PST), Bruce Hoult > <bruce.hoult@gmail.com> wrote: > > >If you're embedding some object reference into JIT code then you by definition > >already have a pointer to that object elsewhere. It's trivial to ensure a copy of > >that pointer hangs around -- usually it's going to happen anyway. > > If you think it's "bogus", then it's likely you hav never tried to > compile a language that has 1st class closures. Does Dylan count? As I recall, my very first commit in the Gwydion Dylan project, back in 2001 or so, was a patch for PowerPC to create thunks at runtime to enable closures to be passed as callback functions to regular C code. > It isn't always feasible to embed static data into a code block and do > IP relative loads. Perhaps there are ISAs which can ONLY assemble pointer literals piece-wise rather than doing a PC-relative load (or having them embedded with an immediate addressing mode), but I haven't yet been unfortunate enough to come across one. I'm not even sure what it would take. Not only no PC-relative loads, but a complete inability to transfer the PC to a base register? On the 6502 we often did a JSR to the next instruction and then popped the saved PC off the stack. Ok, that would screw up modern call/return prediction hardware. But you could call an actual function that copied the saved PC from the stack or link register and returned it as the function result as well as returning to it. Another possibility is if code and data are in different address spaces not accessible from other load instructions. AVR for example has different address spaces. But you can load literals from code space (by default the standard Arduino runtime copies literals into data space at program startup to make generic C work, but you can prevent that). Of course different address spaces and code in flash makes JIT pretty inconvenient and high latency in the first place. While Aarch64, for example, provides quite a nice way to assemble a constant 16 bits at a time from the instruction stream, it also provides a PC-relative load. If the next unconditional branch/return is too far away (even maybe simply too far to have been prefetched) then you can always insert one to branch around the literal, with I'd think a lot less performance cost than a cache miss.
[toc] | [prev] | [next] | [standalone]
| From | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| Date | 2015-12-01 14:45 -0500 |
| Message-ID | <jwv4mg2uf8a.fsf-monnier+comp.arch@gnu.org> |
| In reply to | #31225 |
> If you're embedding some object reference into JIT code then you by
> definition already have a pointer to that object elsewhere. It's trivial to
> ensure a copy of that pointer hangs around -- usually it's going to
> happen anyway.
Keeping an extra reference somewhere else can be a good solution, but it
may be inconvenient to do it right if you want to handle the case where
the code gets GC'd.
And of course, it's no solution to the problem where the GC wants to
*move* the object.
Stefan
[toc] | [prev] | [next] | [standalone]
| From | Bruce Hoult <bruce.hoult@gmail.com> |
|---|---|
| Date | 2015-12-01 12:12 -0800 |
| Message-ID | <4cd8f419-13f3-4622-a78c-dda8e57508dd@googlegroups.com> |
| In reply to | #31344 |
On Tuesday, December 1, 2015 at 10:45:27 PM UTC+3, Stefan Monnier wrote: > > If you're embedding some object reference into JIT code then you by > > definition already have a pointer to that object elsewhere. It's trivial to > > ensure a copy of that pointer hangs around -- usually it's going to > > happen anyway. > > Keeping an extra reference somewhere else can be a good solution, but it > may be inconvenient to do it right if you want to handle the case where > the code gets GC'd. > And of course, it's no solution to the problem where the GC wants to > *move* the object. Updating pointers in JIT'd code is problematic for a whole other set of reasons! At the very least it's likely to need a pair of mprotect() calls as a lot of OSes now don't want the same memory to be both writable and executable at the same time. It would not surprise me if some even start to allow a writable -> executable transition but not the reverse!
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-12-05 14:19 +0000 |
| Message-ID | <2015Dec5.151936@mips.complang.tuwien.ac.at> |
| In reply to | #31345 |
Bruce Hoult <bruce.hoult@gmail.com> writes: >On Tuesday, December 1, 2015 at 10:45:27 PM UTC+3, Stefan Monnier wrote: >> > If you're embedding some object reference into JIT code then you by >> > definition already have a pointer to that object elsewhere. It's trivi= >al to >> > ensure a copy of that pointer hangs around -- usually it's going to >> > happen anyway. >>=20 >> Keeping an extra reference somewhere else can be a good solution, but it >> may be inconvenient to do it right if you want to handle the case where >> the code gets GC'd. >> And of course, it's no solution to the problem where the GC wants to >> *move* the object. > >Updating pointers in JIT'd code is problematic for a whole other set of rea= >sons! At the very least it's likely to need a pair of mprotect() calls as a= > lot of OSes now don't want the same memory to be both writable and executa= >ble at the same time. Which ones? It's certainly possible to have such memory in Linux, Windows, MacOS X, and all the Unices we used when testing Gforth portability. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
| From | nmm@wheeler.UUCP (Nick Maclaren) |
|---|---|
| Date | 2015-12-05 14:56 +0000 |
| Message-ID | <n3utuq$3am$1@dont-email.me> |
| In reply to | #31442 |
In article <2015Dec5.151936@mips.complang.tuwien.ac.at>, Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote: >Bruce Hoult <bruce.hoult@gmail.com> writes: >> >>Updating pointers in JIT'd code is problematic for a whole other set of rea= >>sons! At the very least it's likely to need a pair of mprotect() calls as a= >> lot of OSes now don't want the same memory to be both writable and executa= >>ble at the same time. > >Which ones? It's certainly possible to have such memory in Linux, >Windows, MacOS X, and all the Unices we used when testing Gforth >portability. There was a phase where such usages were blocked on security grounds, at least as an option. Unfortunately, as you say, the rise of JIT compilers has reversed the trend. However, any system/compiler combination that gives a damn about security would use some mechanism to block spoof code attacks. Regards, Nick Maclaren.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-12-05 16:48 +0000 |
| Message-ID | <2015Dec5.174823@mips.complang.tuwien.ac.at> |
| In reply to | #31444 |
nmm@wheeler.UUCP (Nick Maclaren) writes: > However, any system/compiler >combination that gives a damn about security would use some mechanism >to block spoof code attacks. Thanks to return-oriented programming, you do not need writable executable memory to get the attacked process to do arbitrary things. Writing to arbitrary memory is sufficient (and if you can prevent that, you don't need to worry about writes to executable memory). In particular, in Gforth you can fall back to plain threaded code (with a factor 2 speed penalty on a number of CPUs) and no longer need writable executable memory, but the program can still do the same things, and an attacker who can write to arbitrary places can do everything the programmer can do, because Gforth is full of code addresses that are used to jump to native code. I would be (and have been) very careful when using Gforth for network-facing applications, even without native-code generation. So W^X is more security theatre than security. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
| From | nmm@wheeler.UUCP (Nick Maclaren) |
|---|---|
| Date | 2015-12-05 17:38 +0000 |
| Message-ID | <n3v7e9$l1e$1@dont-email.me> |
| In reply to | #31449 |
In article <2015Dec5.174823@mips.complang.tuwien.ac.at>, Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote: > >> However, any system/compiler >>combination that gives a damn about security would use some mechanism >>to block spoof code attacks. > >Thanks to return-oriented programming, you do not need writable >executable memory to get the attacked process to do arbitrary things. >Writing to arbitrary memory is sufficient (and if you can prevent >that, you don't need to worry about writes to executable memory). Well, no, but it forces an extra level of indirection into the attacks, and the difficulty of attacking a system from outside goes up very fast (more-or-less exponentially) with the number of levels you need to subvert. >So W^X is more security theatre than security. Not at all. It's still a useful tool. Security is best viewed in military terms, and it has always been the case that the side with more ingenuity and resources will win. Even protection against arbitrary write locations will not save you, because you can change a program's behaviour by simply ensuring that its data goes out of domain. But that's damn hard to use as an attack, in general, without arbitrary write locations .... Regards, Nick Maclaren.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-12-06 15:21 +0000 |
| Message-ID | <2015Dec6.162135@mips.complang.tuwien.ac.at> |
| In reply to | #31455 |
nmm@wheeler.UUCP (Nick Maclaren) writes:
>In article <2015Dec5.174823@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>
>>> However, any system/compiler
>>>combination that gives a damn about security would use some mechanism
>>>to block spoof code attacks.
>>
>>Thanks to return-oriented programming, you do not need writable
>>executable memory to get the attacked process to do arbitrary things.
>>Writing to arbitrary memory is sufficient (and if you can prevent
>>that, you don't need to worry about writes to executable memory).
>
>Well, no, but it forces an extra level of indirection into the attacks,
>and the difficulty of attacking a system from outside goes up very
>fast (more-or-less exponentially) with the number of levels you need
>to subvert.
In this case, not really. In particular, in Gforth you can just
program in Forth if you have write access, even without execute
access; it will run slower by a factor of about 2, but that's probably
of little concern to the attacker. More generally, there are tools
for finding useful program fragments ("gadgets") for return-oriented
programming, and even a compiler, which the attacker may find more
comfortable than writing assembly language or Forth.
>>So W^X is more security theatre than security.
>
>Not at all. It's still a useful tool.
Useful for what? The benefit/cost ratio seems to be very small for
this one, and its rightfully not applied as generally as Bruce Hoult
claimed.
- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
| From | nmm@wheeler.UUCP (Nick Maclaren) |
|---|---|
| Date | 2015-12-06 16:43 +0000 |
| Message-ID | <n41oiu$6n1$1@dont-email.me> |
| In reply to | #31491 |
In article <2015Dec6.162135@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>
>>>> However, any system/compiler
>>>>combination that gives a damn about security would use some mechanism
>>>>to block spoof code attacks.
>>>
>>>Thanks to return-oriented programming, you do not need writable
>>>executable memory to get the attacked process to do arbitrary things.
>>>Writing to arbitrary memory is sufficient (and if you can prevent
>>>that, you don't need to worry about writes to executable memory).
>>
>>Well, no, but it forces an extra level of indirection into the attacks,
>>and the difficulty of attacking a system from outside goes up very
>>fast (more-or-less exponentially) with the number of levels you need
>>to subvert.
>
>In this case, not really. In particular, in Gforth you can just
>program in Forth if you have write access, even without execute
>access; it will run slower by a factor of about 2, but that's probably
>of little concern to the attacker. More generally, there are tools
>for finding useful program fragments ("gadgets") for return-oriented
>programming, and even a compiler, which the attacker may find more
>comfortable than writing assembly language or Forth.
Most applications are in languages that do not have that feature.
Yes, there are tools - I did something comparable back in the 1970s,
for a different reason, and my hit rate of finding something that
did what I wanted was not high. That is why I say that it's an
extra level of indirection. And it's really very difficult unless
you can identify your target application well enough to replicate
the binary.
>>>So W^X is more security theatre than security.
>>
>>Not at all. It's still a useful tool.
>
>Useful for what? The benefit/cost ratio seems to be very small for
>this one, and its rightfully not applied as generally as Bruce Hoult
>claimed.
There is no cost in the vast majority of cases, and negligible cost
in almost all of the remainder; almost all languages are either
compiled or interpreted, and most interpreted ones that have dynamic
recompilation could easily include a page property switch in their
code to do that. Forth may be an exception, but they are rare.
And, for both compiled and interpreted languages, it provides a
useful level of security by blocking an important class of attacks.
No, it's not a panacea, but nothing is.
Regards,
Nick Maclaren.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-12-08 13:55 +0000 |
| Message-ID | <2015Dec8.145504@mips.complang.tuwien.ac.at> |
| In reply to | #31494 |
nmm@wheeler.UUCP (Nick Maclaren) writes:
>>More generally, there are tools
>>for finding useful program fragments ("gadgets") for return-oriented
>>programming, and even a compiler, which the attacker may find more
>>comfortable than writing assembly language or Forth.
>
>Most applications are in languages that do not have that feature.
Actually the gadget-finding stuff is language-independent.
>>Useful for what? The benefit/cost ratio seems to be very small for
>>this one, and its rightfully not applied as generally as Bruce Hoult
>>claimed.
>
>There is no cost in the vast majority of cases, and negligible cost
>in almost all of the remainder; almost all languages are either
>compiled or interpreted, and most interpreted ones that have dynamic
>recompilation could easily include a page property switch in their
>code to do that. Forth may be an exception, but they are rare.
Forth is very similar in that respect to other JITed languages. It
would cost extra system calls and buy nothing.
>And, for both compiled and interpreted languages, it provides a
>useful level of security by blocking an important class of attacks.
Just like installing and enforcing the use of another lock on the front
door of a house while having no side walls blocks an important class
of attacks, but does not give any real benefit.
- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
| From | Chris Gray <cg@GraySage.COM> |
|---|---|
| Date | 2015-12-05 11:05 -0700 |
| Message-ID | <87fuzgojol.fsf@GraySage.COM> |
| In reply to | #31442 |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes: > Which ones? It's certainly possible to have such memory in Linux, > Windows, MacOS X, and all the Unices we used when testing Gforth > portability. A couple of years ago when I was first fiddling with native code for my Zed system, I found I couldn't allocate write/exec pages under Windows 8.1, so had to allocate as writeable, then mprotect as executable. Now, this was doing it via CygWin, so perhaps it was an artifact of that. Or, as Nick says later, it is now allowed to have write/exec. -- Chris Gray
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-12-06 14:04 +0000 |
| Message-ID | <2015Dec6.150409@mips.complang.tuwien.ac.at> |
| In reply to | #31459 |
Chris Gray <cg@GraySage.COM> writes: >anton@mips.complang.tuwien.ac.at (Anton Ertl) writes: > >> Which ones? It's certainly possible to have such memory in Linux, >> Windows, MacOS X, and all the Unices we used when testing Gforth >> portability. > >A couple of years ago when I was first fiddling with native code for my >Zed system, I found I couldn't allocate write/exec pages under Windows >8.1, so had to allocate as writeable, then mprotect as executable. Now, >this was doing it via CygWin, so perhaps it was an artifact of that. Or, >as Nick says later, it is now allowed to have write/exec. malloc()ed memory stopped being executable a long time ago, but allocating with mmap(... PROT_EXEC|PROT_READ|PROT_WRITE ...) works directly in all OSs we have tested; and if it did not work in (Cygwin on) Windows 8.1, we would have heard about it; Windows 8.1 is not that exotic. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
| From | Chris Gray <cg@GraySage.COM> |
|---|---|
| Date | 2015-12-06 11:09 -0700 |
| Message-ID | <878u57o3d7.fsf@GraySage.COM> |
| In reply to | #31486 |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> malloc()ed memory stopped being executable a long time ago, but
> allocating with mmap(... PROT_EXEC|PROT_READ|PROT_WRITE ...) works
> directly in all OSs we have tested; and if it did not work in (Cygwin
> on) Windows 8.1, we would have heard about it; Windows 8.1 is not that
> exotic.
Curious. Unfortunately, I started keeping revisions *after* I had done the
fix, so can't see what I did before. I wouldn't have used malloc. Current
code is:
arbptr const page :=
Sys/MMap(nil, MMan/PAGE_SIZE, MMan/Prot_t{PROT_WRITE},
MMan/Flags_t{MAP_ANONYMOUS, MMan/MAP_PRIVATE}, -1, 0);
if toUint(page) = MMan/MAP_FAILED then
Sys/ShowErrno();
Sys/Abort("MMap failed");
fi;
assert assign arbptr const pageNN := page;
*bits8 nonNil p := pretend(pageNN, *bits8);
con data := ctx->ctx_buf->buf_data;
for i from 0 upto byteCount - 1 do
p* := data[i];
p := p + 1;
od;
if Sys/MProtect(page, MMan/PAGE_SIZE,
MMan/Prot_t{PROT_EXEC, PROT_READ}) ~= 0
then
Sys/ShowErrno();
Sys/Abort("MProtect failed");
fi;
Fmt("page = ", pageNN, " bytes = ", byteCount, ", instructions = ",
ctx->ctx_insCount);
Proc/SetNativeCode(pr, pageNN);
(Privileged-mode Zed code, but I expect its comprehensible.) My recollection
is that the fix for me was in not putting PROT_EXEC in the mmap call, and
adding the mprotect after copying in the instructions. It would take me a
while to get out the Win 8.1 system and retry, so likely not worth it at
this point.
--
Chris Gray
[toc] | [prev] | [next] | [standalone]
| From | Bruce Hoult <bruce.hoult@gmail.com> |
|---|---|
| Date | 2015-12-06 09:15 -0800 |
| Message-ID | <b563f684-3846-47e3-83d2-706226d409ed@googlegroups.com> |
| In reply to | #31442 |
On Saturday, December 5, 2015 at 5:21:20 PM UTC+3, Anton Ertl wrote: > Bruce Hoult <bruce.hoult@gmail.com> writes: > >On Tuesday, December 1, 2015 at 10:45:27 PM UTC+3, Stefan Monnier wrote: > >> > If you're embedding some object reference into JIT code then you by > >> > definition already have a pointer to that object elsewhere. It's trivi= > >al to > >> > ensure a copy of that pointer hangs around -- usually it's going to > >> > happen anyway. > >>=20 > >> Keeping an extra reference somewhere else can be a good solution, but it > >> may be inconvenient to do it right if you want to handle the case where > >> the code gets GC'd. > >> And of course, it's no solution to the problem where the GC wants to > >> *move* the object. > > > >Updating pointers in JIT'd code is problematic for a whole other set of rea= > >sons! At the very least it's likely to need a pair of mprotect() calls as a= > > lot of OSes now don't want the same memory to be both writable and executa= > >ble at the same time. > > Which ones? It's certainly possible to have such memory in Linux, > Windows, MacOS X, and all the Unices we used when testing Gforth > portability. I'd say that on most OSes now your application's code is not writable, and your stack and malloc()'d memory is not executable. Of course usually the application can call mprotect() explicitly to change this, but an attacker can't call mprotect() to do this because they can't inject code to do it in the first place. If the application contains an mprotect() call then there is logically a possibility that the attacker could set up arguments for it and put that call's address in place of the current function's return address. That's probably going to have to be a highly-targetted white box attack. iOS is an extremely widespread OS that simply won't allow normal applications to have pages both writable and executable, and in fact it won't even let you use mprotect() to change memory to executable. This is a situation that causes me personally a lot of annoyance in stopping me from doing things I'd quite like to do, but it does in fact do quite a lot to protect naieve users from people with less honourable intentions than my good self.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-12-08 13:43 +0000 |
| Message-ID | <2015Dec8.144301@mips.complang.tuwien.ac.at> |
| In reply to | #31497 |
Bruce Hoult <bruce.hoult@gmail.com> writes: >On Saturday, December 5, 2015 at 5:21:20 PM UTC+3, Anton Ertl wrote: >> Bruce Hoult <bruce.hoult@gmail.com> writes: >> >a=3D >> > lot of OSes now don't want the same memory to be both writable and exec= >uta=3D >> >ble at the same time. >>=20 >> Which ones? It's certainly possible to have such memory in Linux, >> Windows, MacOS X, and all the Unices we used when testing Gforth >> portability. > >I'd say that on most OSes now your application's code is not writable, and = >your stack and malloc()'d memory is not executable. > >Of course usually the application can call mprotect() explicitly to change = >this, Or the application can allocate the memory with the desired permissions to begin with. In either case, the OS allows having pages writable and executable at the same time. >but an attacker can't call mprotect() to do this because they can't i= >nject code to do it in the first place. Injecting code is unnecessary, the code is already there. >iOS is an extremely widespread OS that simply won't allow normal applicatio= >ns to have pages both writable and executable, and in fact it won't even le= >t you use mprotect() to change memory to executable. One OS is not "a lot", as you claimed. And the reason for iOS is probably due to the business model, but it's always good if you can feed people other explanations, and they swallow it. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.arch
csiph-web