Skip to contentSkip to conversation

x86, AMD, NB: silence an underflow test

PATCH In review Dan Carpenter 3 participants 3 messages Jan 21, 2014 – Jan 25, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, AMD, NB: silence an underflow test

This is under CAP_SYS_ADMIN but Smatch complains that mask comes from the user and the test for "mask > 0xf" can underflow. The fix is simple.

arch/x86/include/asm/amd_nb.h +1 -1
index a54ee1d054d9..0c4e3e47d462 100644
@@ -19,7 +19,7 @@ extern int amd_cache_northbridges(void);
 extern void amd_flush_garts(void);
 extern int amd_numa_init(void);
 extern int amd_get_subcaches(int);
-extern int amd_set_subcaches(int, int);
+extern int amd_set_subcaches(int, unsigned long);
 
 struct amd_l3_cache {
 	unsigned indices;
arch/x86/kernel/amd_nb.c +1 -1
index 59554dca96ec..d9fceb697322 100644
@@ -179,7 +179,7 @@ int amd_get_subcaches(int cpu)
 	return (mask >> (4 * cuid)) & 0xf;
 }
 
-int amd_set_subcaches(int cpu, int mask)
+int amd_set_subcaches(int cpu, unsigned long mask)
 {
 	static unsigned int reset, ban;
 	struct amd_northbridge *nb = node_to_amd_nb(amd_get_nb_id(cpu));
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Dan Carpenter

This is under CAP_SYS_ADMIN but Smatch complains that mask comes from

"Smatch complains..." - you sound just like a politician - something inanimate and abstract complains that something's wrong - I'm not to blame, I'm innocent!

Not "amd_set_subcaches should hand down an unsigned long like it was originally indended but then bugged into an int..."

:-) :-) :-)

Quoted 4 lines

the user and the test for "mask > 0xf" can underflow. The fix is simple.

In any case:

Thanks!

Quoted 27 lines
arch/x86/include/asm/amd_nb.h +1 -1
index a54ee1d054d9..0c4e3e47d462 100644
@@ -19,7 +19,7 @@ extern int amd_cache_northbridges(void);
 extern void amd_flush_garts(void);
 extern int amd_numa_init(void);
 extern int amd_get_subcaches(int);
-extern int amd_set_subcaches(int, int);
+extern int amd_set_subcaches(int, unsigned long);
 
 struct amd_l3_cache {
 	unsigned indices;
arch/x86/kernel/amd_nb.c +1 -1
index 59554dca96ec..d9fceb697322 100644
@@ -179,7 +179,7 @@ int amd_get_subcaches(int cpu)
 	return (mask >> (4 * cuid)) & 0xf;
 }
 
-int amd_set_subcaches(int cpu, int mask)
+int amd_set_subcaches(int cpu, unsigned long mask)
 {
 	static unsigned int reset, ban;
 	struct amd_northbridge *nb = node_to_amd_nb(amd_get_nb_id(cpu));
Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#2 lore raw

[tip:x86/urgent] x86/AMD/NB: Fix amd_set_subcaches() parameter type

In reply to Dan Carpenter
x86/AMD/NB: Fix amd_set_subcaches() parameter type
Commit-ID:  2993ae3305ad10b41e0d0bc2662f7754ee8e30fa
Gitweb:     http://git.kernel.org/tip/2993ae3305ad10b41e0d0bc2662f7754ee8e30fa
Author:     Dan Carpenter <[email protected]>
AuthorDate: Tue, 21 Jan 2014 10:22:09 +0300
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 25 Jan 2014 08:50:09 +0100

x86/AMD/NB: Fix amd_set_subcaches() parameter type

This is under CAP_SYS_ADMIN, but Smatch complains that mask comes from the user and the test for "mask > 0xf" can underflow.

The fix is simple: amd_set_subcaches() should hand down not an 'int' but an 'unsigned long' like it was originally indended to do.

---
 arch/x86/include/asm/amd_nb.h | 2 +-
 arch/x86/kernel/amd_nb.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/amd_nb.h +1 -1
index a54ee1d..aaac3b2 100644
@@ -19,7 +19,7 @@ extern int amd_cache_northbridges(void);
 extern void amd_flush_garts(void);
 extern int amd_numa_init(void);
 extern int amd_get_subcaches(int);
-extern int amd_set_subcaches(int, int);
+extern int amd_set_subcaches(int, unsigned long);
 
 struct amd_l3_cache {
 	unsigned indices;
arch/x86/kernel/amd_nb.c +1 -1
index 59554dc..dec8de4 100644
@@ -179,7 +179,7 @@ int amd_get_subcaches(int cpu)
 	return (mask >> (4 * cuid)) & 0xf;
 }
 
-int amd_set_subcaches(int cpu, int mask)
+int amd_set_subcaches(int cpu, unsigned long mask)
 {
 	static unsigned int reset, ban;
 	struct amd_northbridge *nb = node_to_amd_nb(amd_get_nb_id(cpu));