mm: mmap: Add new /proc tunable for mmap_base ASLR.
Subsystems (5)
PATCH 1/2 mm: mmap: Add new /proc tunable for mmap_base ASLR.
From: dcashman <[email protected]>
ASLR currently only uses 8 bits to generate the random offset for the mmap base address on 32 bit architectures. This value was chosen to prevent a poorly chosen value from dividing the address space in such a way as to prevent large allocations. This may not be an issue on all platforms. Allow the specification of a minimum number of bits so that platforms desiring greater ASLR protection may determine where to place the trade-off.
--- Documentation/sysctl/kernel.txt | 14 ++++++++++++++ include/linux/mm.h | 6 ++++++ kernel/sysctl.c | 11 +++++++++++ 3 files changed, 31 insertions(+)
Documentation/sysctl/kernel.txt +14 -0
@@ -41,6 +41,7 @@ show up in /proc/sys/kernel: - kptr_restrict - kstack_depth_to_print [ X86 only ] - l2cr [ PPC only ] +- mmap_rnd_bits - modprobe ==> Documentation/debugging-modules.txt - modules_disabled - msg_next_id [ sysv ipc ]
@@ -391,6 +392,19 @@ This flag controls the L2 cache of G3 processor boards. If ============================================================== +mmap_rnd_bits: + +This value can be used to select the number of bits to use to +determine the random offset to the base address of vma regions +resulting from mmap allocations on architectures which support +tuning address space randomization. This value will be bounded +by the architecture's minimum and maximum supported values. + +This value can be changed after boot using the +/proc/sys/kernel/mmap_rnd_bits tunable + +============================================================== + modules_disabled: A toggle value indicating if modules are allowed to be loaded
include/linux/mm.h +6 -0
@@ -51,6 +51,12 @@ extern int sysctl_legacy_va_layout;#define sysctl_legacy_va_layout 0#endif +#ifdef CONFIG_ARCH_MMAP_RND_BITS +extern int mmap_rnd_bits_min; +extern int mmap_rnd_bits_max; +extern int mmap_rnd_bits; +#endif +#include <asm/page.h> #include <asm/pgtable.h> #include <asm/processor.h>
kernel/sysctl.c +11 -0
@@ -1139,6 +1139,17 @@ static struct ctl_table kern_table[] = { .proc_handler = timer_migration_handler, },#endif +#ifdef CONFIG_ARCH_MMAP_RND_BITS + { + .procname = "mmap_rnd_bits", + .data = &mmap_rnd_bits, + .maxlen = sizeof(mmap_rnd_bits), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &mmap_rnd_bits_min, + .extra2 = &mmap_rnd_bits_max, + }, +#endif { } };
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 2/2 arm: mm: support ARCH_MMAP_RND_BITS.
From: dcashman <[email protected]>
arm: arch_mmap_rnd() uses a hard-code value of 8 to generate the random offset for the mmap base address. This value represents a compromise between increased ASLR effectiveness and avoiding address-space fragmentation. Replace it with a Kconfig option, which is sensibly bounded, so that platform developers may choose where to place this compromise. Keep 8 as the minimum acceptable value.
--- arch/arm/Kconfig | 24 ++++++++++++++++++++++++ arch/arm/mm/mmap.c | 7 +++++-- 2 files changed, 29 insertions(+), 2 deletions(-)
arch/arm/Kconfig +24 -0
@@ -306,6 +306,30 @@ config MMU Select if you want MMU-based virtualised addressing space support by paged memory management. If unsure, say 'Y'. +config ARCH_MMAP_RND_BITS_MIN + int + default 8 + +config ARCH_MMAP_RND_BITS_MAX + int + default 14 if MMU && PAGE_OFFSET=0x40000000 + default 15 if MMU && PAGE_OFFSET=0x80000000 + default 16 if MMU + default 8 + +config ARCH_MMAP_RND_BITS + int "Number of bits to use for ASLR of mmap base address" if EXPERT + range ARCH_MMAP_RND_BITS_MIN ARCH_MMAP_RND_BITS_MAX + default ARCH_MMAP_RND_BITS_MIN + help + This value can be used to select the number of bits to use to + determine the random offset to the base address of vma regions + resulting from mmap allocations. This value will be bounded + by the architecture's minimum and maximum supported values. + + This value can be changed after boot using the + /proc/sys/kernel/mmap_rnd_bits tunable + # # The "ARM system type" choice list is ordered alphabetically by option # text. Please add new entries in the option alphabetic order.
arch/arm/mm/mmap.c +5 -2
@@ -11,6 +11,10 @@#include <linux/random.h> #include <asm/cachetype.h> +int mmap_rnd_bits_min =CONFIG_ARCH_MMAP_RND_BITS_MIN ; +int mmap_rnd_bits_max =CONFIG_ARCH_MMAP_RND_BITS_MAX ; +int mmap_rnd_bits =CONFIG_ARCH_MMAP_RND_BITS ; +#define COLOUR_ALIGN (addr,pgoff) \ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
@@ -173,8 +177,7 @@ unsigned long arch_mmap_rnd(void) {unsigned long rnd; -/* 8 bits of randomness in 20 address space bits */ - rnd = (unsigned long )get_random_int () % (1 <<8 ); + rnd = (unsigned long )get_random_int () % (1 << mmap_rnd_bits);return rnd <<PAGE_SHIFT ; }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Quoted 9 lines · Daniel Cashman
From: dcashman <[email protected]>
ASLR currently only uses 8 bits to generate the random offset for the mmap base address on 32 bit architectures. This value was chosen to prevent a poorly chosen value from dividing the address space in such a way as to prevent large allocations. This may not be an issue on all platforms. Allow the specification of a minimum number of bits so that platforms desiring greater ASLR protection may determine where to place the trade-off.
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
Eric
Quoted 77 lines
Signed-off-by Daniel Cashman <[email protected]>--- Documentation/sysctl/kernel.txt | 14 ++++++++++++++ include/linux/mm.h | 6 ++++++ kernel/sysctl.c | 11 +++++++++++ 3 files changed, 31 insertions(+)Documentation/sysctl/kernel.txt +14
-0@@ -41,6 +41,7 @@ show up in /proc/sys/kernel: - kptr_restrict - kstack_depth_to_print [ X86 only ] - l2cr [ PPC only ] +- mmap_rnd_bits - modprobe ==> Documentation/debugging-modules.txt - modules_disabled - msg_next_id [ sysv ipc ]@@ -391,6 +392,19 @@ This flag controls the L2 cache of G3 processor boards. If ============================================================== +mmap_rnd_bits: + +This value can be used to select the number of bits to use to +determine the random offset to the base address of vma regions +resulting from mmap allocations on architectures which support +tuning address space randomization. This value will be bounded +by the architecture's minimum and maximum supported values. + +This value can be changed after boot using the +/proc/sys/kernel/mmap_rnd_bits tunable + +============================================================== + modules_disabled: A toggle value indicating if modules are allowed to be loadedinclude/linux/mm.h +6
-0@@ -51,6 +51,12 @@ extern int sysctl_legacy_va_layout;#define sysctl_legacy_va_layout 0#endif +#ifdef CONFIG_ARCH_MMAP_RND_BITS +extern int mmap_rnd_bits_min; +extern int mmap_rnd_bits_max; +extern int mmap_rnd_bits; +#endif +#include <asm/page.h> #include <asm/pgtable.h> #include <asm/processor.h> kernel/sysctl.c +11
-0@@ -1139,6 +1139,17 @@ static struct ctl_table kern_table[] = { .proc_handler = timer_migration_handler, },#endif +#ifdef CONFIG_ARCH_MMAP_RND_BITS + { + .procname = "mmap_rnd_bits", + .data = &mmap_rnd_bits, + .maxlen = sizeof(mmap_rnd_bits), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &mmap_rnd_bits_min, + .extra2 = &mmap_rnd_bits_max, + }, +#endif { } };
Quoted 4 lines
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use (min, max, and default) since these values are architecture dependent. Arm64 patch should be forthcoming, and others after that. With that in mind, would you still prefer to have the sysctl code in the arm-specific patch?
plain text this time...
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use (min, max, and default) since these values are architecture dependent. Arm64 patch should be forthcoming, and others after that. With that in mind, would you still prefer to have the sysctl code in the arm-specific patch?
Quoted 8 lines
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use
Yes. I included these patches together because they provide mutual context, but each has a different outcome and they could be taken separately. The arm architecture-specific portion allows the changing of the number of bits used for mmap ASLR, useful even without the sysctl. The sysctl patch (patch 1) provides another way of setting this value, and the hope is that this will be adopted across multiple architectures, with the arm changes (patch 2) providing an example. I hope to follow this with changes to arm64 and x86, for example.
Quoted 14 lines · Jeffrey Vander Stoep
plain text this time...
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use (min, max, and default) since these values are architecture dependent. Arm64 patch should be forthcoming, and others after that. With that in mind, would you still prefer to have the sysctl code in the arm-specific patch?
Quoted 6 lines · Dan Cashman
Quoted 6 lines
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
Quoted 6 lines
Quoted 2 lines
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use
Yes. I included these patches together because they provide mutual context, but each has a different outcome and they could be taken separately.
They can not. The first patch is incomplete by itself.
Quoted 6 lines
The arm architecture-specific portion allows the changing of the number of bits used for mmap ASLR, useful even without the sysctl. The sysctl patch (patch 1) provides another way of setting this value, and the hope is that this will be adopted across multiple architectures, with the arm changes (patch 2) providing an example. I hope to follow this with changes to arm64 and x86, for example.
If you want to make the code generic. Please maximize the sharing. That is please define the variables in a generic location, as well as the Kconfig variables (if possible).
As it is you have an architecture specific piece of code that can not be reused without duplicating code, and that is just begging for problems.
Eric
Quoted 8 lines · Eric W. Biederman
Quoted 6 lines · Dan Cashman
Quoted 6 lines
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use
Yes. I included these patches together because they provide mutual context, but each has a different outcome and they could be taken separately.
They can not. The first patch is incomplete by itself.
Could you be more specific in what makes the first patch incomplete? Is it because it is essentially a no-op without additional architecture changes (e.g. the second patch) or is it specifically because it introduces and uses the three "mmap_rnd_bits*" variables without defining them? If the former, I'd like to avoid combining the general procfs change with any architecture-specific one(s). If the latter, I hope the proposal below addresses that.
Quoted 7 lines
Quoted 6 lines
The arm architecture-specific portion allows the changing of the number of bits used for mmap ASLR, useful even without the sysctl. The sysctl patch (patch 1) provides another way of setting this value, and the hope is that this will be adopted across multiple architectures, with the arm changes (patch 2) providing an example. I hope to follow this with changes to arm64 and x86, for example.
Quoted 6 lines
If you want to make the code generic. Please maximize the sharing. That is please define the variables in a generic location, as well as the
Kconfigvariables (if possible).As it is you have an architecture specific piece of code that can not be reused without duplicating code, and that is just begging for problems.
I think it would make sense to move the variable definitions into mm/mmap.c, included conditionally based on the presence of CONFIG_ARCH_MMAP_RND_BITS.
As for the Kconfigs, I am open to suggestions. I considered declaring and documenting ARCH_MMAP_RND_BITS in arch/Kconfig, but I would like it to be bounded in range by the _MIN and _MAX values, which necessarily must be defined in the arch-specific Kconfigs. Thus, we'd have ARCH_MMAP_RND_BITS declared in arch/Kconfig as it currently is in arch/arm/Kconfig defaulting to _MIN, and would declare both the _MIN and _MAX in arch/Kconfig, while specifying default values in arch/${ARCH}/Kconfig.
Would these changes be more acceptable?
Thank You,
Dan
Quoted 18 lines · Daniel Cashman
Quoted 8 lines · Eric W. Biederman
Quoted 6 lines · Dan Cashman
Quoted 6 lines
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use
Yes. I included these patches together because they provide mutual context, but each has a different outcome and they could be taken separately.
They can not. The first patch is incomplete by itself.
Quoted 7 lines
Could you be more specific in what makes the first patch incomplete? Is it because it is essentially a no-op without additional architecture changes (e.g. the second patch) or is it specifically because it introduces and uses the three "mmap_rnd_bits*" variables without defining them? If the former, I'd like to avoid combining the general procfs change with any architecture-specific one(s). If the latter, I hope the proposal below addresses that.
A bit of both. The fact that the code can not compile in the first patch because of missing variables is distressing. Having the arch specific code as a separate patch is fine, but they need to remain in the same patchset.
Quoted 27 lines
Quoted 7 lines
Quoted 6 lines
The arm architecture-specific portion allows the changing of the number of bits used for mmap ASLR, useful even without the sysctl. The sysctl patch (patch 1) provides another way of setting this value, and the hope is that this will be adopted across multiple architectures, with the arm changes (patch 2) providing an example. I hope to follow this with changes to arm64 and x86, for example.
Quoted 6 lines
If you want to make the code generic. Please maximize the sharing. That is please define the variables in a generic location, as well as the
Kconfigvariables (if possible).As it is you have an architecture specific piece of code that can not be reused without duplicating code, and that is just begging for problems.
I think it would make sense to move the variable definitions into
mm/mmap.c, included conditionally based on the presence ofCONFIG_ARCH_MMAP_RND_BITS.As for the Kconfigs, I am open to suggestions. I considered declaring and documenting
ARCH_MMAP_RND_BITSinarch/Kconfig, but I would like it to be bounded in range by the_MINand_MAXvalues, which necessarily must be defined in the arch-specific Kconfigs. Thus, we'd haveARCH_MMAP_RND_BITSdeclared inarch/Kconfigas it currently is inarch/arm/Kconfigdefaulting to_MIN, and would declare both the_MINand_MAXinarch/Kconfig, while specifying default values inarch/${ARCH}/Kconfig.
Quoted 1 line
Would these changes be more acceptable?
Yes. I don't think you can do much about the Kconfigs so I would not worry about that too much.
Eric
Quoted 28 lines · Eric W. Biederman
Quoted 18 lines · Daniel Cashman
Quoted 8 lines · Eric W. Biederman
Quoted 6 lines · Dan Cashman
Quoted 6 lines
Quoted 5 lines
This all would be much cleaner if the arm architecture code were just to register the sysctl itself.
As it sits this looks like a patchset that does not meaninfully bisect, and would result in code that is hard to trace and understand.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I believe the intent is to follow up with more architecture specific patches to allow each architecture to define the number of bits to use
Yes. I included these patches together because they provide mutual context, but each has a different outcome and they could be taken separately.
They can not. The first patch is incomplete by itself.
Quoted 7 lines
Could you be more specific in what makes the first patch incomplete? Is it because it is essentially a no-op without additional architecture changes (e.g. the second patch) or is it specifically because it introduces and uses the three "mmap_rnd_bits*" variables without defining them? If the former, I'd like to avoid combining the general procfs change with any architecture-specific one(s). If the latter, I hope the proposal below addresses that.
Quoted 5 lines
A bit of both. The fact that the code can not compile in the first patch because of missing variables is distressing. Having the arch specific code as a separate patch is fine, but they need to remain in the same patchset.
The first patch would compile as long as CONFIG_ARCH_MMAP_RND_BITS were not defined without also defining the missing variables. I actually viewed this as a safeguard against attempting to use those variables without architecture support, but am ok with changing it.
I've gone ahead and submitted [PATCH v2] which aims to reduce duplication in the arch-specific config files and concerning those variables. The only caveat is that now the second patch depends on the first, whereas before it did not.
Thank You,
Dan