arm64: constify hwcap_str
PATCH 1/1 arm64: constify hwcap_str
Turn hwcap_str from a 'writable array of pointers to const char[]' to a multidimensional const char[][].
---
This is something I noticed when looking at Steve Capper's hwcaps patch: really no point in having a writable array of 8-byte pointers in .data keeping track of these hwcap strings.
arch/arm64/kernel/setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kernel/setup.c +3 -3
@@ -301,10 +301,10 @@ static int __init topology_init(void) }subsys_initcall (topology_init); -static const char *hwcap_str[] = { +static const char hwcap_str[][8 ] = {"fp" ,"asimd" , -NULL +"" };static int c_show (struct seq_file *m,void *v)
@@ -328,7 +328,7 @@ static int c_show(struct seq_file *m, void *v)/* dump out the processor features */ seq_puts (m,"Features\t: " ); -for (i =0 ; hwcap_str[i]; i++) +for (i =0 ; hwcap_str[i][0 ]; i++)if (elf_hwcap & (1 << i))seq_printf (m,"%s " , hwcap_str[i]);
Signature · 1 line
1.8.3.2
Catalin Marinas
maintainerPATCH 1/1 arm64: constify hwcap_str
Quoted 9 lines · Ard Biesheuvel
Turn
hwcap_strfrom a 'writable array of pointers to const char[]' to a multidimensional const char[][].Signed-off-by Ard Biesheuvel <[email protected]>---
This is something I noticed when looking at Steve Capper's hwcaps patch: really no point in having a writable array of 8-byte pointers in .data keeping track of these hwcap strings.
I don't see a problem (few bytes wasted). If you want to make it read-only, this would do:
arch/arm64/kernel/setup.c +1 -1
@@ -308,7 +308,7 @@ static int __init topology_init(void) }subsys_initcall (topology_init); -static const char *hwcap_str[] = { +static const char *const hwcap_str[] = {"fp" ,"asimd" ,NULL
Signature · 1 line
Catalin
PATCH 1/1 arm64: constify hwcap_str
Quoted 20 lines · Catalin Marinas
Quoted 9 lines · Ard Biesheuvel
Turn
hwcap_strfrom a 'writable array of pointers to const char[]' to a multidimensional const char[][].Signed-off-by Ard Biesheuvel <[email protected]>---
This is something I noticed when looking at Steve Capper's hwcaps patch: really no point in having a writable array of 8-byte pointers in .data keeping track of these hwcap strings.
I don't see a problem (few bytes wasted). If you want to make it read-only, this would do:
arch/arm64/kernel/setup.c +0
-0
arch/arm64/kernel/setup.c static int __init topology_init(void) · line 314
Quoted 8 lines
arch/arm64/kernel/setup.c +1
-1@@ -308,7 +308,7 @@ static int __init topology_init(void) }subsys_initcall (topology_init); -static const char *hwcap_str[] = { +static const char *const hwcap_str[] = {"fp" ,"asimd" ,NULL
I agree that whether you want to put up with the additional layer of indirection, additional relocations etc is a matter of taste, but having writable pointers around that are easily dereferenced directly by unprivileged users is a bad idea in any case, so if this is your preferred solution, it's fine by me.
Regards,
Ard.
Catalin Marinas
maintainerPATCH 1/1 arm64: constify hwcap_str
Quoted 23 lines · Ard Biesheuvel
Quoted 22 lines · Catalin Marinas
Quoted 9 lines · Ard Biesheuvel
Turn
hwcap_strfrom a 'writable array of pointers to const char[]' to a multidimensional const char[][].Signed-off-by Ard Biesheuvel <[email protected]>---
This is something I noticed when looking at Steve Capper's hwcaps patch: really no point in having a writable array of 8-byte pointers in .data keeping track of these hwcap strings.
I don't see a problem (few bytes wasted). If you want to make it read-only, this would do:
arch/arm64/kernel/setup.c +0
-0@@ -308,7 +308,7 @@ static int __init topology_init(void) }subsys_initcall (topology_init);
Quoted 10 lines
arch/arm64/kernel/setup.c static int __init topology_init(void) · line 314
Quoted 5 lines
arch/arm64/kernel/setup.c +1
-1-static const char *hwcap_str[] = { +static const char *const hwcap_str[] = {"fp" ,"asimd" ,NULL I agree that whether you want to put up with the additional layer of indirection, additional relocations etc is a matter of taste, but having writable pointers around that are easily dereferenced directly by unprivileged users is a bad idea in any case,
"unprivileged users"?!
Quoted 1 line
so if this is your preferred solution, it's fine by me.
My preferred solution is to leave it as it is ;).
Signature · 1 line
Catalin
PATCH 1/1 arm64: constify hwcap_str
Quoted 1 line · Catalin Marinas
On Thu, Nov 07, 2013 at 06:53:06PM +0000, Ard Biesheuvel wrote:
[...]
Quoted 7 lines
Quoted 4 lines
I agree that whether you want to put up with the additional layer of indirection, additional relocations etc is a matter of taste, but having writable pointers around that are easily dereferenced directly by unprivileged users is a bad idea in any case,
"unprivileged users"?!
Well, I know this may seem far fetched, but /proc/cpuinfo lacks any kind of access control because it is deemed harmless, while, as an unprivileged user, having some pointers in .data that you can clobber (through some other vulnerability) without breaking anything, and can conveniently dereference at your leisure by cat'ing /proc/cpuinfo, may well be something that could potentially be used in the wrong way.
Quoted 4 lines
Quoted 1 line
so if this is your preferred solution, it's fine by me.
My preferred solution is to leave it as it is ;).
It's a trivial fix, so why not apply it?
Signature · 1 line
Ard.
Catalin Marinas
maintainerPATCH 1/1 arm64: constify hwcap_str
Quoted 8 lines · Ard Biesheuvel
Quoted 1 line · Catalin Marinas
On Thu, Nov 07, 2013 at 06:53:06PM +0000, Ard Biesheuvel wrote:
[...]
Quoted 5 lines
Quoted 4 lines
I agree that whether you want to put up with the additional layer of indirection, additional relocations etc is a matter of taste, but having writable pointers around that are easily dereferenced directly by unprivileged users is a bad idea in any case,
Quoted 8 lines
Quoted 1 line
"unprivileged users"?!
Well, I know this may seem far fetched, but
/proc/cpuinfolacks any kind of access control because it is deemed harmless, while, as an unprivileged user, having some pointers in .data that you can clobber (through some other vulnerability) without breaking anything, and can conveniently dereference at your leisure by cat'ing/proc/cpuinfo, may well be something that could potentially be used in the wrong way.
That's far fetched indeed ;). I'm pretty sure once you can write the .data section there are far better way to hack the kernel.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
so if this is your preferred solution, it's fine by me.
My preferred solution is to leave it as it is ;).
It's a trivial fix, so why not apply it?
So far my toolchain already places it in .rodata since there is no write to these pointers.
Signature · 1 line
Catalin
PATCH 1/1 arm64: constify hwcap_str
Quoted 8 lines · Catalin Marinas
Quoted 3 lines · Ard Biesheuvel
Quoted 1 line · Catalin Marinas
On Thu, Nov 07, 2013 at 06:53:06PM +0000, Ard Biesheuvel wrote:
It's a trivial fix, so why not apply it?
So far my toolchain already places it in .rodata since there is no write to these pointers.
So the fix is even more trivial than I thought :-)
Cheers,
Ard.