powerpc/security: Fix debugfs data leak on 32-bit
authorGeert Uytterhoeven <geert+renesas@glider.be>
Mon, 21 Oct 2019 14:23:09 +0000 (16:23 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 5 Nov 2019 11:29:27 +0000 (22:29 +1100)
"powerpc_security_features" is "unsigned long", i.e. 32-bit or 64-bit,
depending on the platform (PPC_FSL_BOOK3E or PPC_BOOK3S_64).  Hence
casting its address to "u64 *", and calling debugfs_create_x64() is
wrong, and leaks 32-bit of nearby data to userspace on 32-bit platforms.

While all currently defined SEC_FTR_* security feature flags fit in
32-bit, they all have "ULL" suffixes to make them 64-bit constants.
Hence fix the leak by changing the type of "powerpc_security_features"
(and the parameter types of its accessors) to "u64".  This also allows
to drop the cast.

Fixes: 398af571128fe75f ("powerpc/security: Show powerpc_security_features in debugfs")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20191021142309.28105-1-geert+renesas@glider.be
arch/powerpc/include/asm/security_features.h
arch/powerpc/kernel/security.c

index 759597bf0fd867bd6d4c151acb8acce7f7f3ff6b..a3e8ecd48dc7ffa0d69b2435ae90bb5f9acb828c 100644 (file)
@@ -9,7 +9,7 @@
 #define _ASM_POWERPC_SECURITY_FEATURES_H
 
 
-extern unsigned long powerpc_security_features;
+extern u64 powerpc_security_features;
 extern bool rfi_flush;
 
 /* These are bit flags */
@@ -24,17 +24,17 @@ void setup_stf_barrier(void);
 void do_stf_barrier_fixups(enum stf_barrier_type types);
 void setup_count_cache_flush(void);
 
-static inline void security_ftr_set(unsigned long feature)
+static inline void security_ftr_set(u64 feature)
 {
        powerpc_security_features |= feature;
 }
 
-static inline void security_ftr_clear(unsigned long feature)
+static inline void security_ftr_clear(u64 feature)
 {
        powerpc_security_features &= ~feature;
 }
 
-static inline bool security_ftr_enabled(unsigned long feature)
+static inline bool security_ftr_enabled(u64 feature)
 {
        return !!(powerpc_security_features & feature);
 }
index ad7f4bf8447c629557cb568917ec17d82b345a9d..a3021e6faed865872073b99c69dcf160fc370c87 100644 (file)
@@ -16,7 +16,7 @@
 #include <asm/setup.h>
 
 
-unsigned long powerpc_security_features __read_mostly = SEC_FTR_DEFAULT;
+u64 powerpc_security_features __read_mostly = SEC_FTR_DEFAULT;
 
 enum count_cache_flush_type {
        COUNT_CACHE_FLUSH_NONE  = 0x1,
@@ -108,7 +108,7 @@ device_initcall(barrier_nospec_debugfs_init);
 static __init int security_feature_debugfs_init(void)
 {
        debugfs_create_x64("security_features", 0400, powerpc_debugfs_root,
-                          (u64 *)&powerpc_security_features);
+                          &powerpc_security_features);
        return 0;
 }
 device_initcall(security_feature_debugfs_init);