Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4330316ybg; Mon, 21 Oct 2019 07:23:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxocWcLCg+9OYcLmPOw4zEXZXVbEE9CJAiBihTX1SMe9p3bBRyva20k25FjsFoHzd7CWoLT X-Received: by 2002:a17:906:f181:: with SMTP id gs1mr22043827ejb.13.1571667835381; Mon, 21 Oct 2019 07:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571667835; cv=none; d=google.com; s=arc-20160816; b=p5XygJy+XI3XAu2R/XlVzPHuN0EH5Q2qaPnMIGXQxVdP3ol9MCewlA61AgcfeNb+XO pCS3859Lll1i3XW2i+uxbIHAVZ8Kc3+pSAZcJsRAUmkhR3hdfpdIgXl5luaq2e6f/fC/ w9pRkoo5MzNb9sY63MeEwdHMQfqVTyb/L91DZkX4YU4Z2XoKv0OjCKzsggSYikh0Dh47 KzjBCmCpV+hYqw4jnGeUcdHG8MC8EXEYtFWvABVSYPj9XT4y24SkX47xJx47L+w6uPON 9jpcARZ6IPqJDelG7+po+9GQYkG7LliXtTt2jEF6tcv/ygJ3snTRXT0wt7wgGAkmpBQn JWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=GzvG5pPXAEq/7Ug4hC1SFbOd/Hj2+HWWje/yjgwyIlM=; b=0X/+QZe71aAQ7HVjznpNHjnL6oXthsQtilmLzBa2OAvJOWmgVibjYqkYoa3TGEHjeW FdO8RK03BiDEeaLrozGFs3kpwUdO53BstoCSF81AYBY3ztiaZj43Fxiw4pWK8n7mn8Un v5hhlqJeJPxyzKfdTtn5VFtZS/XSNahYfj95Yi4f0n0aBdW56CYlAZC/r/n2ovK074Na h/W6a3iLngZtJGiEC332Lf25/fgeLsJPFbSLNQ5xCqOJHoVlZU3ajpHNQflhJymumL+C LFP4P2dHKmLV2Q5DjFKNwwvOSiT8If0iLqI06npwhNS4BLBvPACgRdoofAyKHcgjW13u kc6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g90si10768852edd.329.2019.10.21.07.23.32; Mon, 21 Oct 2019 07:23:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728776AbfJUOXP (ORCPT + 99 others); Mon, 21 Oct 2019 10:23:15 -0400 Received: from xavier.telenet-ops.be ([195.130.132.52]:52712 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbfJUOXP (ORCPT ); Mon, 21 Oct 2019 10:23:15 -0400 Received: from ramsan ([84.194.98.4]) by xavier.telenet-ops.be with bizsmtp id GEPA2100Z05gfCL01EPAGy; Mon, 21 Oct 2019 16:23:13 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1iMYaU-0007oE-Ju; Mon, 21 Oct 2019 16:23:10 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1iMYaU-0007K2-Gm; Mon, 21 Oct 2019 16:23:10 +0200 From: Geert Uytterhoeven To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Joel Stanley , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] powerpc/security: Fix debugfs data leak on 32-bit Date: Mon, 21 Oct 2019 16:23:09 +0200 Message-Id: <20191021142309.28105-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "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 --- Compile-tested only. Alternatively, powerpc_security_features could be changed to u32. However, that would require using debugfs_create_x32() instead of debugfs_create_x64(), which would change the debugfs file formatting from "0x%016llx" to "0x%08llx". --- arch/powerpc/include/asm/security_features.h | 8 ++++---- arch/powerpc/kernel/security.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/security_features.h b/arch/powerpc/include/asm/security_features.h index 759597bf0fd867bd..a3e8ecd48dc7ffa0 100644 --- a/arch/powerpc/include/asm/security_features.h +++ b/arch/powerpc/include/asm/security_features.h @@ -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); } diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c index 7cfcb294b11ca7be..2e9a7e20d05c5f79 100644 --- a/arch/powerpc/kernel/security.c +++ b/arch/powerpc/kernel/security.c @@ -16,7 +16,7 @@ #include -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); -- 2.17.1