Skip to contentSkip to conversation

powerpc/papr_scm: Make access mode of 'perf_stats' attribute file to '0400'

PATCH In review Vaibhav Jain 2 participants 3 messages Aug 7, 2020 – Aug 12, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/papr_scm: Make access mode of 'perf_stats' attribute file to '0400'

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 non-root users.

Hence this patch updates the access-mode of 'perf_stats' sysfs attribute file to 0400 to make it only readable to root-users.

---
 arch/powerpc/platforms/pseries/papr_scm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/papr_scm.c +1 -1
index f439f0dfea7d1..31864d167a2ce 100644
@@ -822,7 +822,7 @@ static ssize_t perf_stats_show(struct device *dev,
 	kfree(stats);
 	return rc ? rc : seq_buf_used(&s);
 }
-DEVICE_ATTR_RO(perf_stats);
+DEVICE_ATTR(perf_stats, 0400, perf_stats_show, NULL);
 
 static ssize_t flags_show(struct device *dev,
 			  struct device_attribute *attr, char *buf)
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw
Quoted 9 lines · Vaibhav Jain

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 non-root users.

Hence this patch updates the access-mode of 'perf_stats' sysfs attribute file to 0400 to make it only readable to root-users.

Or should we ratelimit it?

Fixes ??
Quoted 2 lines

cheers
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#2 lore raw

Hi Mpe,

Thanks for reviewing this patch. My responses below:

Quoted 8 lines · Michael Ellerman
Quoted 7 lines · Vaibhav Jain

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 non-root users.

Quoted 4 lines
Quoted 2 lines

Hence this patch updates the access-mode of 'perf_stats' sysfs attribute file to 0400 to make it only readable to root-users.

Or should we ratelimit it?

Ideal consumers of this data will be users with CAP_PERFMON or CAP_SYS_ADMIN. Also they need up-to-date values for these performance stats as these values can be time sensitive.

So rate limiting may not be a complete solution since a user running 'perf' might be throttled by another user who is simply reading the sysfs file contents.

So instead of setting attribute mode to 0400, will add a check for 'perfmon_capable()' in perf_stats_show() denying read access to users without CAP_PERFMON or CAP_SYS_ADMIN.

Quoted 1 line
Fixes ??

Right. I will add this in v2.

Quoted 6 lines
Quoted 3 lines

cheers

Signature · 5 lines
Cheers
~ Vaibhav
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]