Skip to content

Commit 08ccce4

Browse files
Madhavan Srinivasangregkh
authored andcommitted
powerpc/sysfs: Disable writing to PURR in guest mode
commit d1211af upstream. arch/powerpc/kernel/sysfs.c exports PURR with write permission. This may be valid for kernel in phyp mode. But writing to the file in guest mode causes crash due to a priviledge violation Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> [Backported to 3.4: adjust context] Signed-off-by: Yijing Wang <wangyijing@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent badd9b7 commit 08ccce4

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

arch/powerpc/kernel/sysfs.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <asm/machdep.h>
1818
#include <asm/smp.h>
1919
#include <asm/pmc.h>
20+
#include <asm/firmware.h>
2021

2122
#include "cacheinfo.h"
2223

@@ -179,15 +180,25 @@ SYSFS_PMCSETUP(spurr, SPRN_SPURR);
179180
SYSFS_PMCSETUP(dscr, SPRN_DSCR);
180181
SYSFS_PMCSETUP(pir, SPRN_PIR);
181182

183+
/*
184+
Lets only enable read for phyp resources and
185+
enable write when needed with a separate function.
186+
Lets be conservative and default to pseries.
187+
*/
182188
static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
183189
static DEVICE_ATTR(spurr, 0600, show_spurr, NULL);
184190
static DEVICE_ATTR(dscr, 0600, show_dscr, store_dscr);
185-
static DEVICE_ATTR(purr, 0600, show_purr, store_purr);
191+
static DEVICE_ATTR(purr, 0400, show_purr, store_purr);
186192
static DEVICE_ATTR(pir, 0400, show_pir, NULL);
187193

188194
unsigned long dscr_default = 0;
189195
EXPORT_SYMBOL(dscr_default);
190196

197+
static void add_write_permission_dev_attr(struct device_attribute *attr)
198+
{
199+
attr->attr.mode |= 0200;
200+
}
201+
191202
static ssize_t show_dscr_default(struct device *dev,
192203
struct device_attribute *attr, char *buf)
193204
{
@@ -394,8 +405,11 @@ static void __cpuinit register_cpu_online(unsigned int cpu)
394405
if (cpu_has_feature(CPU_FTR_MMCRA))
395406
device_create_file(s, &dev_attr_mmcra);
396407

397-
if (cpu_has_feature(CPU_FTR_PURR))
408+
if (cpu_has_feature(CPU_FTR_PURR)) {
409+
if (!firmware_has_feature(FW_FEATURE_LPAR))
410+
add_write_permission_dev_attr(&dev_attr_purr);
398411
device_create_file(s, &dev_attr_purr);
412+
}
399413

400414
if (cpu_has_feature(CPU_FTR_SPURR))
401415
device_create_file(s, &dev_attr_spurr);

0 commit comments

Comments
 (0)