Collecting NX information
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greetings.
Currently I'm in need of some information about both vanilla and Exec Shield kernels in regards to markings emitted by the toolchain, specifically PT_GNU_STACK. I'd like to check my assumptions, in preparation for possibly making a non-intrusive change which would allow the PT_PAX_FLAGS from PaX to be used in a more finegrained way than PT_GNU_STACK is used now to control mainline and exec shield memory protections.
As I understand, PT_GNU_STACK uses a single marking to control whether a task gets an executable stack and whether ASLR is applied to the executable. I would like more information on this. To start, I'll supply some background on why I need this information.
PaX uses its own markings, PT_PAX_FLAGS, to control the way PaX applies protections to processes. In particular, PaX supplies the following markings:
P - PAGEEXEC (NX bit or emulated NX bit) S - SEGMEXEC (NX emulation on x86, ignored for our purposes) E - EMUTRAMP (Trampoline emulation, to avoid giving an executable stack
in situations where nested functions are used)
M - MPROTECT (mprotect() restrictions, to control kernel policy on how
memory protections may be applied in userspace)
R - RANDMMAP (mmap() base randomization, for libraries, PIEs, anonymous
segments, etc; also controls all other randomization except RANDEXEC)
X - RANDEXEC (random ET_EXEC base)
Each marking has three states: On, Off, and Neutral. The Neutral marking takes the most restrictive setting by default, except in the case of RANDEXEC, in which it's off because RANDEXEC can crash things easily. A sysctl in PaX can switch the Neutral logic, except for RANDEXEC.
For our purposes, SEGMEXEC is completely ignored; aside from x86 PaX, SEGMEXEC has no impact on anything. PAGEEXEC is equivalent to using the processor supplied facilities to enforce PROT_EXEC (or emulation to do such on x86).
I believe that these could map easily to PT_GNU_STACK's functionality:
P - Page-based PROT_EXEC enforcement. With this off, PROT_EXEC has no
effect. This is slightly different than normal PT_GNU_STACK (executable stack).
R - Randomization. With this off, the ASLR for stack, heap, mmap(),
etc are disabled.
E - Trampoline Emulation, port this from PaX in the future
If PT_PAX_FLAGS exists (the logic to check and read it can be derived from PaX), these markings should be used; else, PT_GNU_STACK should be fallen back to. This would have no effect on any current distributions; however, future development could mark for any situation and potentially have one marking which simultaneously make the program work under PaX, Exec Shield, and Vanilla.
The default state (when these are Neutral) would be the more restrictive, of course; that is, PRe would be equal to ---.
Trampoline emulation would allow for a task to use nested functions with a non-executable stack. This would allow some PT_GNU_STACK markings to come off for i.e. x86-64 and for Exec Shield.
Currently my understanding of how PT_GNU_STACK affects mainline and exec shield kernels is very limited. The above is what I came up under the assumption that it simply allows the stack to be made executable and allows ASLR to be turned off with one setting, rather than individual fine-grained settings; I may need more information. If anyone has any suggestions, comments, etc, I'd like to hear them.
To do this, I'd pretty much simply have to port over the part of PaX which checks for PT_PAX_FLAGS and if it can't find it falls back to EI_PAX, changing that to falling back to PT_GNU_STACK and appropriate code; and tweak the code to reflect mainline rather than a PaX kernel. Not sure how I'd do that exactly, but I have a whole week off work and class somehow so maybe I'll learn something.
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSEsThDd4aOud5P8RAnh8AJ9dv11ozerlf5MKGzeFIyvLpucjtACfV+vF Ll8bAJBbTCReRBwToCGVX/c=
=1qEV
-----END PGP SIGNATURE-----
Quoted 4 lines
As I understand,
PT_GNU_STACKuses a single marking to control whether a task gets an executable stack and whether ASLR is applied to the executable.
you understand wrongly.
PT_GNU_STACK just sets the exec permission for the stack (and the heap now mirrors the stack). Nothing more nothing less.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 10 lines · Arjan van de Ven
Quoted 3 lines
As I understand,
PT_GNU_STACKuses a single marking to control whether a task gets an executable stack and whether ASLR is applied to the executable.you understand wrongly.
PT_GNU_STACKjust sets the exec permission for the stack (and the heap now mirrors the stack). Nothing more nothing less.
So then this would be slightly more useful than I had previously thought, bringing control over the randomization as well?
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSFINhDd4aOud5P8RAv36AJ9kFyE4u14CAVvWNu4bl11Gd125agCfVj3I gNPQRd73mWJCLrPd5Ge/EnM=
=jqg0
-----END PGP SIGNATURE-----
Quoted 11 lines · John Richard Moser
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 5 lines · Arjan van de Ven
Quoted 3 lines
As I understand,
PT_GNU_STACKuses a single marking to control whether a task gets an executable stack and whether ASLR is applied to the executable.
Quoted 8 lines
Quoted 5 lines
you understand wrongly.
PT_GNU_STACKjust sets the exec permission for the stack (and the heap now mirrors the stack). Nothing more nothing less.So then this would be slightly more useful than I had previously thought, bringing control over the randomization as well?
actually Linus was really against adding non-related things to this flag. And I think he is right...
Now.. do you have any examples of when you want a binary marked for no- randomisation ?? (eg something the setarch flag won't fix/won't be good enough for)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 20 lines · Arjan van de Ven
Quoted 18 lines · John Richard Moser
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 10 lines · Arjan van de Ven
Quoted 3 lines
As I understand,
PT_GNU_STACKuses a single marking to control whether a task gets an executable stack and whether ASLR is applied to the executable.you understand wrongly.
PT_GNU_STACKjust sets the exec permission for the stack (and the heap now mirrors the stack). Nothing more nothing less.
Quoted 7 lines
Quoted 2 lines
So then this would be slightly more useful than I had previously thought, bringing control over the randomization as well?
actually Linus was really against adding non-related things to this flag. And I think he is right...
I'm not interested in altering and hacking up PT_GNU_STACK; PT_PAX_FLAGS already supplies enough to do what I want. My goal is to have PT_PAX_FLAGS code in mainline and Exec Shield, so that if it exists in the binary it will be used; else PT_GNU_STACK will be fallen back to.
Quoted 3 lines
Now.. do you have any examples of when you want a binary marked for no- randomisation ?? (eg something the setarch flag won't fix/won't be good enough for)
What's setarch do for one? Anyway, ASLR has been known to break some things. Blackdown Java used to break IIRC; also there's the poorly designed Oracle and the poorly designed solution of Oracle on a 32 bit platform; and of course there's Emacs, which I heard was broken due to Exec Shield's randomization. Temporary work-arounds are sometimes needed.
Remember also that I'm not just trying to make a more robust setting for ES and mainline; I'm trying to find a way to make it so that distribution maintainers can set one set of flags and have it assure that the program works in Mainline, Exec Shield, and PaX. Just a little less work for the distribution maintainers, which I think would be a good thing considering that apparently Ubuntu Linux might support both PaX and Exec Shield in the future, if I'm reading this[1] right.
[1] http://thread.gmane.org/gmane.linux.ubuntu.devel/6130
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSFeuhDd4aOud5P8RApQ+AKCPtp5b4/2rw+aRqEUg7r1FlphmQwCfX3Io FUNq9xZlDsoo1poGBo5+zus=
=v0dv
-----END PGP SIGNATURE-----
Quoted 3 lines
Quoted 3 lines
actually Linus was really against adding non-related things to this flag. And I think he is right...
Makes sense to me.
Quoted 8 lines
I'm not interested in altering and hacking up
PT_GNU_STACK;PT_PAX_FLAGSalready supplies enough to do what I want. My goal is to havePT_PAX_FLAGScode in mainline and Exec Shield, so that if it exists in the binary it will be used; elsePT_GNU_STACKwill be fallen back to.Quoted 3 lines
Now.. do you have any examples of when you want a binary marked for no- randomisation ?? (eg something the setarch flag won't fix/won't be good enough for)
I also recall a few oddball cases where PaX randomization broke things, I'll try and dig one up and see if it fails as well on ExecShield.
Quoted 14 lines
What's setarch do for one? Anyway, ASLR has been known to break some things. Blackdown Java used to break IIRC; also there's the poorly designed Oracle and the poorly designed solution of Oracle on a 32 bit platform; and of course there's Emacs, which I heard was broken due to Exec Shield's randomization. Temporary work-arounds are sometimes needed.
Remember also that I'm not just trying to make a more robust setting for ES and mainline; I'm trying to find a way to make it so that distribution maintainers can set one set of flags and have it assure that the program works in Mainline, Exec Shield, and PaX. Just a little less work for the distribution maintainers, which I think would be a good thing considering that apparently Ubuntu Linux might support both PaX and Exec Shield in the future, if I'm reading this[1] right.
Quoted 1 line
IMO you have this backwards, John. Rather than having the majority (ES, mainline NX stuff) respect your less popular branch, it would make sense to have PaX work as well as possible with PT_GNU_STACK, and politely request that any missing functionality be duplicated in ES. PT_GNU_STACK is the most widely available header, and we should leverage that ubiquity as much as possible. Marking our binaries with PT_PAX_FLAGS and then begging everyone else to support our way of doing things will never work.
---
Brandon Hale
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 8 lines · Brandon Hale
Quoted 3 lines
Quoted 3 lines
actually Linus was really against adding non-related things to this flag. And I think he is right...
Makes sense to me.
[...]
Quoted 10 lines
IMO you have this backwards, John. Rather than having the majority (ES, mainline NX stuff) respect your less popular branch, it would make sense to have PaX work as well as possible with
PT_GNU_STACK, and politely request that any missing functionality be duplicated in ES.PT_GNU_STACKis the most widely available header, and we should leverage that ubiquity as much as possible. Marking our binaries withPT_PAX_FLAGSand then begging everyone else to support our way of doing things will never work.
You need to consider that in the end I'd need PT_GNU_STACK to do everything PaX wants, and to make PF_X a tristate (On, Off, Neutral) which mapped to PF_PAGEEXEC in PaX. In other words, I'd have to overhaul and most likely *break* everything else that relied on PT_GNU_STACK, instead of passively adding logic for PT_PAX_FLAGS and letting everyone else catch up at their leisure.
I'd rather not break anything and force everyone to upgrade *now*; but instead add PT_PAX_FLAGS functionality for mainline/ES, let it lay there for a year or so as people start moving over and accepting it, let the kernel devs decide when it's time to depricate PT_GNU_STACK, and see it naturally decay away once it's actually no longer needed. The point is to not break anything, yet to still make things easier for those projects and distributions like Hardened Ubuntu.
Quoted 2 lines
---
Brandon Hale
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSIKKhDd4aOud5P8RAkqEAJwNhFvfDc63qyPrBvMxs6naG1xuAQCfZKHn upzqNI5/XzYVCmDKGM6q8ZY=
=YZkT
-----END PGP SIGNATURE-----
Quoted 4 lines
You need to consider that in the end I'd need
PT_GNU_STACKto do everything PaX wants
why?
Why not have independent flags for independent things?
That way you have both cleanness of design and you don't break anything.
Quoted 3 lines
The point is
to not break anything, yet to still make things easier for those projects and distributions like Hardened Ubuntu.
to achieve that you need to get the toolchain to omit this stuff automatically somehow.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 8 lines · Arjan van de Ven
Quoted 2 lines
You need to consider that in the end I'd need
PT_GNU_STACKto do everything PaX wantswhy?
Why not have independent flags for independent things?
That way you have both cleanness of design and you don't break anything.
In the end I want to fine-tune for what the best behaviors are, and then define exactly what the flags should do.
Right now, my rough sketch is:
MF_PAX_PAGEEXEC
ON: ET_EXEC enforced. Stack NX. Heap NX. Code PROT_EXEC.
OFF: Stack and heap default to +X
The PAGEEXEC flag will basically mandate the automated non-executable setting for the stack and heap. When off, these areas are executable (like when PT_GNU_STACK is on)MF_PAX_EMUTRAMP:
ON: Trampolines (in NX stack) and PLT will be detected and emulated
OFF: Stack needs to be +X for trampolines to work
The EMUTRAMP flag will basically allow certain known exceptional conditions to be trapped and allowed somehow automatically. This includes mainly nested functions on a non-executable stack, and parisc procedural linkage tables (binutils patch can fix these apparently). This is off by default in hardmode, but on by default in soft or compatibility mode if PAGEEXEC is manually on.MF_PAX_RANDMMAP:
ON: stack, heap, mmap() base randomized
OFF: Nothing is randomized in memory
RANDMMAP should probably be called "RANDADDR" instead. When set, the kernel randomizes anything that can be randomized in the address space (support determining).MF_PAX_RANDEXEC:
ON: Fixed-position things are also randomized
OFF: Fixed-position things are at fixed positions
RANDEXEC allows things that normally can't be placed randomly to be placed randomly if hacks exist to do it. Any hacks 100% safe that don't cause excess overhead are for RANDMMAP; any that may cause instability or excessive overhead go under RANDEXEC. OFF BY DEFAULT in any mode.MF_PAX_MPROTECT:
ON: Enforce certain mprotect() restrictions
OFF: Normal mprotect() restrictions
A certain defined set of transitions and creation states are banned when this is on. PaX has these now, nobody else has them and apparently nobody else wants them.MF_PAX_SEGMEXEC:
Absolutely no effect, reserved for PaX or anything else that implements PaX' specific SEGMEXEC emulation method.
Obviously mainline and ES won't do anything with RANDEXEC, MPROTECT, or SEGMEXEC.
RANDMMAP will be useful to control ES and mainline ASLR (on-off switch).
PAGEEXEC being OFF will act exactly like PT_GNU_STACK being ON for mainline and ES.
EMUTRAMP. . . I think I've got a patch for trampoline emulation, which should let red hat use Exec Shield with fewer PT_GNU_STACK markings. Mainline should benefit from this too. It feels like porting this was way too easy, so I'll ask pipacs to give it a quick look.
I also don't have a soft/hard mode for mainline. I expect that mainline will be more into making softmode (compatibility mode) into a personality, which makes sense for softmode shells (which I've needed before, i.e. to compile mono without softmoding my whole system).
Soft/Hard mode controls what flags are set by default. Each flag has ON/OFF/NEUTRAL settings (thus each is 2 bits).
HARDMODE:
MF_PAX_PAGEEXEC, MF_PAX_RANDMMAP, MF_PAX_MPROTECT
SOFTMODE:
(MF_PAX_EMUTRAMP if MF_PAX_PAGEEXEC is ON)
Quoted 9 lines
Quoted 4 lines
The point is
to not break anything, yet to still make things easier for those projects and distributions like Hardened Ubuntu.to achieve that you need to get the toolchain to omit this stuff automatically somehow.
Emit.
And there's a patch for binutils that Gentoo uses. Ubuntu can use it too.
Remember that the way I'm doing it, PT_GNU_STACK is used if there is no PT_PAX_FLAGS header. Distributions not using PT_PAX_FLAGS will not care about the kernel's ability to read PT_PAX_FLAGS, because it will still behave the same with PT_GNU_STACK. In other words, if Red Hat updated the kernel with this stuff today (assuming it's non-buggy), it won't do shit, and Fedora will still work exactly as expected.
Quoted 1 line
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSQlqhDd4aOud5P8RAgCIAJ4hGeiHD/wcB+B6u9up4v37CT0bAwCeKgcA zX00s0dqVkkRhnxmmzQLZq0=
=4EMG
-----END PGP SIGNATURE-----
Quoted 8 lines · John Richard Moser
Right now, my rough sketch is:
MF_PAX_PAGEEXEC
ON:ET_EXECenforced. Stack NX. Heap NX. CodePROT_EXEC.
OFF: Stack and heap default to +X
The PAGEEXEC flag will basically mandate the automated non-executable setting for the stack and heap. When off, these areas are executable (like whenPT_GNU_STACKis on)
how is this one different from PT_GNU_STACK
Quoted 9 lines
MF_PAX_EMUTRAMP:
ON: Trampolines (in NX stack) and PLT will be detected and emulated
OFF: Stack needs to be +X for trampolines to work
The EMUTRAMP flag will basically allow certain known exceptional conditions to be trapped and allowed somehow automatically. This includes mainly nested functions on a non-executable stack, and parisc procedural linkage tables (binutils patch can fix these apparently). This is off by default in hardmode, but on by default in soft or compatibility mode if PAGEEXEC is manually on
do you actually need this? the number of apps that have actual trampolines is *really really* low. At that point you get to a balance between complexity and very limited added security. And the answer is really not straight forward since complexity is a security risk in itself; or more direct, by allowing this at all you in theory can open other security holes. (note the "can" here. I'm not saying the implementation does, but there sure is added complexity which in turn means added chances for bugs. If the number of things that need this is really low (and it should be) the balance isn't so clear).
Quoted 7 lines
.
MF_PAX_RANDMMAP:
ON: stack, heap,mmap()base randomized
OFF: Nothing is randomized in memory
RANDMMAP should probably be called "RANDADDR" instead. When set, the kernel randomizes anything that can be randomized in the address space (support determining).
This one could in theory be useful. However need info on what breaks. I know that if you do full blown ES/PaX level randomisation the build process of some older emacsen, and build process won't benefit from such a flag unless you can make the toolchain insert it automatic (I suspect that will be hard); once it's manual and during build only using setarch is sufficient to cover that one.
Quoted 8 lines
MF_PAX_RANDEXEC:
ON: Fixed-position things are also randomized
OFF: Fixed-position things are at fixed positions RANDEXEC allows things that normally can't be placed randomly to be placed randomly if hacks exist to do it. Any hacks 100% safe that don't cause excess overhead are for RANDMMAP; any that may cause instability or excessive overhead go under RANDEXEC. OFF BY DEFAULT in any mode.
Is this what PIE would be for? Eg if you change binaries why not just change them to be PIE ?
Quoted 9 lines
MF_PAX_MPROTECT:
ON: Enforce certainmprotect()restrictions
OFF: Normalmprotect()restrictions
A certain defined set of transitions and creation states are banned when this is on. PaX has these now, nobody else has them and apparently nobody else wants them.MF_PAX_SEGMEXEC:
Absolutely no effect, reserved for PaX or anything else that implements PaX' specific SEGMEXEC emulation method.
Actually SELinux currently has stuff for this. Does this need to be in the binary or would SELinux policy be enough (I assume that any hardened linux distro nowadays also enables selinux so this question is quite relevant).
Quoted 2 lines
EMUTRAMP. . . I think I've got a patch for trampoline emulation, which should let red hat use Exec Shield with fewer
PT_GNU_STACKmarkings.
actually fc4 and such don't have that many markings so I wonder what the usefulness is. (most of the spurious markings we had in the past were due to assembly files not being correctly marked, not due to recursive functions)
Quoted 5 lines
Quoted 3 lines
to achieve that you need to get the toolchain to omit this stuff automatically somehow.
Emit.
eh yeah need coffee ;)
Quoted 5 lines
And there's a patch for binutils that Gentoo uses. Ubuntu can use it too.
Remember that the way I'm doing it,
PT_GNU_STACKis used if there is noPT_PAX_FLAGSheader.
since you duplicate PT_GNU_STACK exactly it seems (well inverse meaning but a ! in C is cheap) I think there's no point in obsoleting PT_GNU_STACK. I realize some people see PT_GNU_STACK as an Exec-Shield thing and thus evil, but lets ignore all that politics and stick to facts here: No need to obsolete/remove existing things if they're not broken and are good enough.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · John Richard Moser
Quoted 8 lines
Quoted 6 lines
MF_PAX_PAGEEXEC
ON:ET_EXECenforced. Stack NX. Heap NX. CodePROT_EXEC.
OFF: Stack and heap default to +X
The PAGEEXEC flag will basically mandate the automated non-executable setting for the stack and heap. When off, these areas are executable (like whenPT_GNU_STACKis on)
Quoted 6 lines
Quoted 2 lines
how is this one different from
PT_GNU_STACK
PT_GNU_STACKis on/off,PT_PAX_FLAGSsettings are all on/off/neutral. The neutral state becomes on or off depending on whether some kind of compatibility mode is used.
Hmmmm you either need an executable stack or you don't. Can you explain why you think there is a strong advantage for a "neutral" setting on this one?
Quoted 14 lines
Quoted 13 lines
Quoted 2 lines
MF_PAX_EMUTRAMP:do you actually need this? the number of apps that have actual trampolines is *really really* low. At that point you get to a balance between complexity and very limited added security. And the answer is really not straight forward since complexity is a security risk in itself; or more direct, by allowing this at all you in theory can open other security holes. (note the "can" here. I'm not saying the implementation does, but there sure is added complexity which in turn means added chances for bugs. If the number of things that need this is really low (and it should be) the balance isn't so clear).
Quoted 3 lines
- -rw-r--r-- 1 root src 10485 Mar 29 00:47 emu_tramp.diff
I was surprised it wasn't that complex,
10k lines of patch. And you introduce a mechanism to bypass non-exec- stack.... sometimes a 10 line patch can be "complex" in that sense. So I'll repeat my question about the gains of this, you only answered by showing something about the complexity.
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
.
MF_PAX_RANDMMAP:
ON: stack, heap,mmap()base randomized
OFF: Nothing is randomized in memory
RANDMMAP should probably be called "RANDADDR" instead. When set, the kernel randomizes anything that can be randomized in the address space (support determining).
Quoted 8 lines
Quoted 6 lines
This one could in theory be useful. However need info on what breaks. I know that if you do full blown ES/PaX level randomisation the build process of some older emacsen, and build process won't benefit from such a flag unless you can make the toolchain insert it automatic (I suspect that will be hard); once it's manual and during build only using setarch is sufficient to cover that one.
There's a patch that makes the toolchain spit out
PT_PAX_FLAGS.
that's not an answer to what I said though. You propose a new implementation for something, for that you should say why this one is useful, not "because something else does it".
Quoted 1 line
Consider that
PT_PAX_FLAGSare all tristates.
I think that's a bad idea though.
Quoted 4 lines
A compatibility mode
personality (think linux32 for 64 bit systems) could allow for a shell to be spawned (nopax makeor something dumb like that) which puts everything into softmode.
setarch flags are inherited too (not by setuid of course); and that mechanism already exists. What does your proposed solution add value wise to that?
Quoted 6 lines
Anything not marked (binutils with the patch
emits ----x-PT_PAX_FLAGS, hard-disabling RANDEXEC because it's a bad hack) will of course run as if it had psemrx (emutramp is useless anyway with an executable heap/stack) in softmode and PSeMrX (emutramp isn't used by default, near nothing needs it so why risk a "potential security risk" if it even is) in hardmode.
we're talking here about randomisation; I don't see where emutrap comes in at all????
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
MF_PAX_RANDEXEC:
ON: Fixed-position things are also randomized
OFF: Fixed-position things are at fixed positions RANDEXEC allows things that normally can't be placed randomly to be placed randomly if hacks exist to do it. Any hacks 100% safe that don't cause excess overhead are for RANDMMAP; any that may cause instability or excessive overhead go under RANDEXEC. OFF BY DEFAULT in any mode.
Quoted 6 lines
Quoted 3 lines
Is this what PIE would be for? Eg if you change binaries why not just change them to be PIE ?
Not everything (mplayer! And last year KDE really hated it too) compiles PIE.
Hmmm we'd need details in a bug report to investigate, I can't think of a fundamental reason for this...
(other than mplayer doing the wine thing, which indeed means it needs to be very careful to not trump over certain VA regions; but that is a separate problem)
The rest of your comment suggests that you consider this one not too valueable. PIE imo is a pretty nice solution to the problem, and does not have the performance costs that you get with forcing non-PIE binaries to be randomized.
Quoted 11 lines
Quoted 8 lines
Quoted 2 lines
MF_PAX_MPROTECT:Actually SELinux currently has stuff for this. Does this need to be in the binary or would SELinux policy be enough (I assume that any hardened linux distro nowadays also enables selinux so this question is quite relevant).
See my other reply, an LSM hook would be nice for reading
PT_PAX_FLAGS, controlling them just before they're finally applied.
hmm I again might be missing the point here.... if selinux policy is enforcing this behavior, why would the executable need a built-in-the- binary flag for this *in addition* ?
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
EMUTRAMP. . . I think I've got a patch for trampoline emulation, which should let red hat use Exec Shield with fewer
PT_GNU_STACKmarkings.
Quoted 8 lines
Quoted 5 lines
actually fc4 and such don't have that many markings so I wonder what the usefulness is. (most of the spurious markings we had in the past were due to assembly files not being correctly marked, not due to recursive functions)
To get rid of the rest of those few markings? Particularly Alsa used to have TWO nesteds. . . .
Alsa got fixed for one.
Quoted 8 lines
Quoted 7 lines
since you duplicate
PT_GNU_STACKexactly it seems (well inverse meaning but a ! in C is cheap) I think there's no point in obsoletingPT_GNU_STACK. I realize some people seePT_GNU_STACKas an Exec-Shield thing and thus evil, but lets ignore all that politics and stick to facts here: No need to obsolete/remove existing things if they're not broken and are good enough.
Quoted 6 lines
No, it's not that. I have no problem with
PT_GNU_STACKdoing what it does, but it's a whole field where PaX already has a 2 bit tristate. I'm also told thatPT_GNU_STACKis on/off, not tristated. No need to maintain 2 fields; and the tristate is perfectly perfect for making a compatibility mode/personality that actually honors "we definitely know this is good so we marked it hard."
but the stack thing you KNOW. You either need stack exec or you don't. It's like your wife being pregnant, she either is or isn't. Using tristates when there is no real third state just looks odd to me, especially if the third state is the only advantage of something over an existing thing.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 23 lines · John Richard Moser
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 11 lines · Arjan van de Ven
Quoted 9 lines
Quoted 4 lines
Hmmmm you either need an executable stack or you don't. Can you explain why you think there is a strong advantage for a "neutral" setting on this one?
As I said, compatibility mode. The toolchain should not emit *everything*
PT_GNU_STACKand leave it up to you to de-mark it; instead, everything should be emitted withoutPT_GNU_STACKset, in which case violating code would die.Quoted 5 lines
actually right now the toolchain marks things automatically correct. If gcc emits a stack trampoline, it gets marked needing executable stack, if gcc can prove it doesn't need executable stack, it gets marked as such as well.
Quoted 3 lines
And the toolchain emits a -E library with
PT_PAX_FLAGSif there's a stack trampoline :) But it's defficient right now, doesn't inherit when you link to a library with -E. . . you can fix that right? :)
it's inherited for PT_GNU_STACK though.
Not sure how you implemented PT_PAX_FLAGS, but for PT_GNU_STACK it's inherited.
Quoted 6 lines
Quoted 3 lines
I *really* don't understand why you want to get away from automatic marking to something manual, which *has* to be more fragile.
/me shrugs. It's a security blanket for him mostly; he fears automagic security maintainence.
who is "him" ?
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Remember also I'm very much against "let the compiler guess if you need an executable stack"
it's not guessing. the *compiler* emits the stack trampoline. So the *compiler* knows that it needs that stack.
With a trampoline, things like Grub and a few libs need
PT_GNU_STACK.
sure they do. There's about a handful in an entire distro.
Quoted 3 lines
Of course you can't just suddenly say "OH! Well
PT_GNU_STACKshould do this instead!" because you'll break everything.
I'm not a fan of any kind of emutrampoline. At all. But I am open to others making a different tradeoff; for me the option to have a trampoline at all is just a bypass of the non-exec stack... legit bypass one hopes but a bypass regardless. Some time ago we did an eval of how much stuff would need the emutramp (well or something equivalent) and the list was so small that I decided that the added risk and complexity were not worth it and that I rather had those 5 or so apps run with exec stack.
Quoted 10 lines
Quoted 6 lines
again what does tristate mean.. "I don't know" ? But gcc does know, with very very very few exceptions. Eg old mono is the exception because it didn't do a proper mprotect. Saying "I don't know" doesn't solve you anything, since in the end there needs to be a policy enforced anyway, it's just postponing the inevitable to a point with less knowledge.
Remember I'm also thinking of restricted
mprotect()situations as well, because I'm trying to get it to the point where one set of markings has a predictable effect on any kernel, be it vanilla, pax, or ES.
well that is an entirely independent thing again. Really.
I think mixing all these into one big flag is a mistake. (And thats a lesson I learned the hard way, but Linus was right; don't mix independent things into one flag artificially. Extra flags are cheap. Don't complicate the world for a dozen bytes.)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 3 lines · Arjan van de Ven
Quoted 1 line · John Richard Moser
-----BEGIN PGP SIGNED MESSAGE-----
[...]
Quoted 6 lines
Quoted 2 lines
/me shrugs. It's a security blanket for him mostly; he fears automagic security maintainence.
who is "him" ?
me in third person? :)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Remember also I'm very much against "let the compiler guess if you need an executable stack"
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
it's not guessing. the *compiler* emits the stack trampoline. So the *compiler* knows that it needs that stack.
With a trampoline, things like Grub and a few libs need
PT_GNU_STACK.sure they do. There's about a handful in an entire distro.
Right, so it's a toss-up: Do you want to fix these few things, or do you want to let trampolines exist? Are trampolines that useful?
Quoted 6 lines
Quoted 4 lines
Of course you can't just suddenly say "OH! Well
PT_GNU_STACKshould do this instead!" because you'll break everything.
Quoted 9 lines
I'm not a fan of any kind of emutrampoline. At all. But I am open to others making a different tradeoff; for me the option to have a trampoline at all is just a bypass of the non-exec stack... legit bypass one hopes but a bypass regardless. Some time ago we did an eval of how much stuff would need the emutramp (well or something equivalent) and the list was so small that I decided that the added risk and complexity were not worth it and that I rather had those 5 or so apps run with exec stack.
Eh.
Quoted 13 lines
Quoted 11 lines
Quoted 7 lines
again what does tristate mean.. "I don't know" ? But gcc does know, with very very very few exceptions. Eg old mono is the exception because it didn't do a proper mprotect. Saying "I don't know" doesn't solve you anything, since in the end there needs to be a policy enforced anyway, it's just postponing the inevitable to a point with less knowledge.
Remember I'm also thinking of restricted
mprotect()situations as well, because I'm trying to get it to the point where one set of markings has a predictable effect on any kernel, be it vanilla, pax, or ES.
Quoted 7 lines
well that is an entirely independent thing again. Really.
I think mixing all these into one big flag is a mistake. (And thats a lesson I learned the hard way, but Linus was right; don't mix independent things into one flag artificially. Extra flags are cheap. Don't complicate the world for a dozen bytes.)
two or four dozen bytes, eight dozen bytes in 10 years when 128 bit systems come along, and 16i dozen planck qubytes when we get quantum computers :)
Actually when I proposed adding PT_PAX_FLAGS to Ubuntu, the very first argument I got was "Oh, yeah right, add just a few bytes here for this.
Then later it'll be a few more bytes for something else. Then a few
more for another thing. It all adds up, especially when you have thousands of binaries."
And if bitfield logic is "complicated," you should stop pretending to be a programmer.
#define BIG (1) #define LONG (1 << 1) #define FAT (1 << 2) #define TALL (1 << 3)
#define GREEN (1 << 4)
struct foo {
char *myname;
unsigned long flags;
};
struct foo *newfoo() {
struct foo *out = malloc(sizeof(struct foo));
out->myname = malloc(4);
strcpy(out->myname, "bob");
out->flags = BIG | TALL | GREEN;
return out;
}
Easy enough?
struct foo {
char myname[10];
int big;
int long;
int fat;
int tall;
int green;
};
struct foo *newfoo() {
struct foo *out = malloc(sizeof(struct foo));
strcpy(out->myname, "bob");
out->big = 1;
out->tall = 1;
out->green = 1;
return out;
}
I don't find the above to be quite as elegant. In fact, it looks ugly and wasteful; even checking ...
if (myfoo->flags & BIG)
versus
if (myfoo->big)
Quoted 3 lines
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSb1rhDd4aOud5P8RAg2cAJ98SlxFCLcHvN+aWcVTM2VWxiRCEACfUPPl 24wpdtY/VyKHGs/YpPDo8Hk=
=mVc5
-----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 4 lines · John Richard Moser
Arjan van de Ven wrote:
[...]
Three more notes, then I'll sleep. These notes won't include the two paragraph long explaination of falling back to PT_GNU_STACK if PT_PAX_FLAGS isn't there; compatibility has been touched what, 5 times?
1. I don't want to continue using PT_GNU_STACK for three reasons. The first being that PaX uses a tristate in PT_PAX_FLAGS; the second being that PT_GNU_STACK is a whole ELF field and I'm inclined to take the more space-efficient method; and the third being that PT_GNU_STACK is not a tristate.
The last is particularly an important consideration to me: a tristate would allow for a compatibility/soft mode, but changing PT_GNU_STACK's logic would change the current expected behavior and thus could be unpredictable (break things). I have no interest in breaking Fedora horribly, nor wasting space with a full field where sharing with the other parts of PT_PAX_FLAGS would do just fine.
2. Although binutils can emit PT_GNU_STACK, the paxctl utility could also be modified to detect PT_GNU_STACK in a binary without PT_PAX_FLAGS and change it to PT_PAX_FLAGS, then nuke it. This would allow the flags to be changed without relinking (remember PT_GNU_STACK is to be ignored if PT_PAX_FLAGS exists at all). This is only of interest to distributions which will use PT_PAX_FLAGS.
Note also that execstack would probably be wisely modified to set PF_PAGEEXEC and PT_GNU_STACK both, just for future compatibility. This is of course a lot of work (I tried to make paxctl hack EI_PAX too, and . . .well, it didn't work).
3. PaX won't pay any attention to markings on libraries. Exec Shield and Mainline may, though I have no idea how. If it can be done with PT_GNU_STACK, it can be done with PT_PAX_FLAGS. Such behavior is acceptable, though libraries should be coded with the utmost care to avoid this simply because the weakening of security around a library weakens any and all programs using that library.
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSRWghDd4aOud5P8RAhRFAJ9Ezr6mMIEvk9R+4XpXq7+lZxgd0gCfYhBa IuUU7Zeuk1J9kSJXCSqZlKU=
=m0YW
-----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 8 lines · Arjan van de Ven
Quoted 2 lines
You need to consider that in the end I'd need
PT_GNU_STACKto do everything PaX wantswhy?
Why not have independent flags for independent things?
That way you have both cleanness of design and you don't break anything.
Also, I should have pointed out that independent flags for each part of this would require at the very least a 1 byte field per flag, totaling
6. In practice, the fields are usually 1 processor word (4 or 8 bytes), totalling 24 (or 48) bytes rather than 4 (or 8).
As these are all pretty much "control memory space related security protections," convergence to a well-defined standard would be both clean and non-stuff-breaking. Now of course there's no standard, but several things operating very similarly. This gives us the opportunity to look at how each reacts to each different proprietary marking, take the most robust (which just happens to be PT_PAX_FLAGS, no flamewars please), and define exactly what each setting controls.
I want something very well defined for PAGEEXEC (executable stack, heap). The MPROTECT setting should also be very well defined, which will match with PaX because nobody else restricts mprotect(). EMUTRAMP should be defined fairly loosely, but enough to say "stuff we can predictably identify as exceptions to the rules are caught here." All of these alter the programming environment, so must be predictable to the programmer; emutramp is a special case, which allows the programmer to assume that he needs PAGEEXEC off while the administrator knows to just EMUTRAMP in this case.
For the two randomizers, "sane for default" should define one and "not sane for default" should define the other. These have little to no effect on most programs, VM space fragmentation aside. We don't need to define these too well, but enough to know what they're for.
SEGMEXEC is of course "nothing." In truth, I want PaX to change to make SEGMEXEC absolutely nothing unless PAGEEXEC is on, and only for x86. This is because PAGEEXEC can be very clearly defined, and SEGMEXEC can be defined as a specific modifier on PAGEEXEC.
Of course, the effect of any one of these being on is subject to implementation; obviously if mprotect() restrictions aren't supported, MPROTECT being on does nothing. I doubt mainline and ES will take that particular logic specifically, though either way I have no intention of even trying to force them to. EMUTRAMP, however, I hope would be able to enhance mainline and ES both (that means Red Hat/Fedora) by allowing some of the PT_GNU_STACK markings to come off.
In the future, an SeLinux hook should go into the pax_parse_elf_flags() logic to allow SeLinux policy to control these settings for PaX, mainline, and ES in one sweep:
+ /*Are these broke? Then get out*/
+ if (0 > pax_check_flags(&pax_flags))
+ return -EINVAL;
+
(insert hook here)
+ /*Add to the memory manager flags*/
+ current->mm->flags |= pax_flags;
[...]
- --
All content of all messages exchanged herein are left in the Public Domain, unless otherwise explicitly stated.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
-- Eric Steven Raymond
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCSQ6chDd4aOud5P8RAvr3AJ91i8c7W1CetmjWFGuItG6pCHEiigCbBfXb H4RCVuOjFI71R45Q+TUw/AY=
=dLsN
-----END PGP SIGNATURE-----