Thread (4 messages) flat view 4 messages, 3 authors, 2020-08-19

Re: [PATCH] powerpc/papr_scm: Limit the readability of 'perf_stats' sysfs attribute

From: Aneesh Kumar K.V <hidden>
Date: 2020-08-13 12:34:30
Also in: nvdimm

On 8/13/20 10:04 AM, Vaibhav Jain wrote:
quoted hunk ↗ jump to hunk
The newly introduced 'perf_stats' attribute uses the default access
mode of 0444 letting non-root users access performance stats of an
nvdimm and potentially force the kernel into issuing large number of
expensive HCALLs. Since the information exposed by this attribute
cannot be cached hence its better to ward of access to this attribute
from users who don't need to access these performance statistics.

Hence this patch adds check in perf_stats_show() to only let users
that are 'perfmon_capable()' to read the nvdimm performance
statistics.

Fixes: 2d02bf835e573 ('powerpc/papr_scm: Fetch nvdimm performance stats from PHYP')
Reported-by: Aneesh Kumar K.V <redacted>
Signed-off-by: Vaibhav Jain <redacted>
---
  arch/powerpc/platforms/pseries/papr_scm.c | 4 ++++
  1 file changed, 4 insertions(+)
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index f439f0dfea7d1..36c51bf8af9a8 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -792,6 +792,10 @@ static ssize_t perf_stats_show(struct device *dev,
  	struct nvdimm *dimm = to_nvdimm(dev);
  	struct papr_scm_priv *p = nvdimm_provider_data(dimm);
  
+	/* Allow access only to perfmon capable users */
+	if (!perfmon_capable())
+		return -EACCES;
+
An access check is usually done in open(). This is the read callback IIUC.
  	if (!p->stat_buffer_len)
  		return -ENOENT;
  
-aneesh
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help