Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/security: Fix debugfs data leak on 32-bit

"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

authored by

Geert Uytterhoeven and committed by
Michael Ellerman
3b05a1e5 16f6b67c

+6 -6
+4 -4
arch/powerpc/include/asm/security_features.h
··· 9 9 #define _ASM_POWERPC_SECURITY_FEATURES_H 10 10 11 11 12 - extern unsigned long powerpc_security_features; 12 + extern u64 powerpc_security_features; 13 13 extern bool rfi_flush; 14 14 15 15 /* These are bit flags */ ··· 24 24 void do_stf_barrier_fixups(enum stf_barrier_type types); 25 25 void setup_count_cache_flush(void); 26 26 27 - static inline void security_ftr_set(unsigned long feature) 27 + static inline void security_ftr_set(u64 feature) 28 28 { 29 29 powerpc_security_features |= feature; 30 30 } 31 31 32 - static inline void security_ftr_clear(unsigned long feature) 32 + static inline void security_ftr_clear(u64 feature) 33 33 { 34 34 powerpc_security_features &= ~feature; 35 35 } 36 36 37 - static inline bool security_ftr_enabled(unsigned long feature) 37 + static inline bool security_ftr_enabled(u64 feature) 38 38 { 39 39 return !!(powerpc_security_features & feature); 40 40 }
+2 -2
arch/powerpc/kernel/security.c
··· 16 16 #include <asm/setup.h> 17 17 18 18 19 - unsigned long powerpc_security_features __read_mostly = SEC_FTR_DEFAULT; 19 + u64 powerpc_security_features __read_mostly = SEC_FTR_DEFAULT; 20 20 21 21 enum count_cache_flush_type { 22 22 COUNT_CACHE_FLUSH_NONE = 0x1, ··· 108 108 static __init int security_feature_debugfs_init(void) 109 109 { 110 110 debugfs_create_x64("security_features", 0400, powerpc_debugfs_root, 111 - (u64 *)&powerpc_security_features); 111 + &powerpc_security_features); 112 112 return 0; 113 113 } 114 114 device_initcall(security_feature_debugfs_init);