[PATCH] hwmon: (ina3221): tighten attribute sysfs permissions

From: Ninad Malwade
Date: Thu Nov 17 2022 - 03:39:50 EST


The INA3221 device provides voltage and current measurements for
various power rails, including the CPU rail, on at least some Jetson
boards. This raises the possibility of the Platypus attack being relevant
to Jetson. To prevent this possibility, modify all attribute
channel permissions so that only root can access the values.

This is logically equivalent to 949dd0104c49 ("powercap: restrict energy
meter to root access") upstream.

Signed-off-by: Ninad Malwade <nmalwade@xxxxxxxxxx>
---
drivers/hwmon/ina3221.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index e06186986444..ceddcbaa26dc 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -605,7 +605,7 @@ static umode_t ina3221_is_visible(const void *drvdata,
switch (attr) {
case hwmon_chip_samples:
case hwmon_chip_update_interval:
- return 0644;
+ return 0600;
default:
return 0;
}
@@ -619,13 +619,13 @@ static umode_t ina3221_is_visible(const void *drvdata,
if (channel - 1 <= INA3221_CHANNEL3)
input = &ina->inputs[channel - 1];
else if (channel == 7)
- return 0444;
+ return 0400;
/* Hide label node if label is not provided */
- return (input && input->label) ? 0444 : 0;
+ return (input && input->label) ? 0400 : 0;
case hwmon_in_input:
- return 0444;
+ return 0400;
case hwmon_in_enable:
- return 0644;
+ return 0600;
default:
return 0;
}
@@ -634,10 +634,10 @@ static umode_t ina3221_is_visible(const void *drvdata,
case hwmon_curr_input:
case hwmon_curr_crit_alarm:
case hwmon_curr_max_alarm:
- return 0444;
+ return 0400;
case hwmon_curr_crit:
case hwmon_curr_max:
- return 0644;
+ return 0600;
default:
return 0;
}
--
2.17.1