]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/power/x86/intel-speed-select: Allow non root users
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Fri, 16 Jan 2026 23:30:23 +0000 (15:30 -0800)
committerSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Sat, 17 Jan 2026 00:03:20 +0000 (16:03 -0800)
When permitted by the file /dev/isst_interface, allow to issue commands
for non root users.

When user id is non root, check if  "/dev/isst_interface" can still be
opened. If this file can be opened, allow all read only commands.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
tools/power/x86/intel-speed-select/isst-config.c

index 558138eea75e972d81c4b6e5ea0036a28867becb..807feb17bb8173ffad5b74137eac0e7af3d6b1c4 100644 (file)
@@ -80,6 +80,18 @@ struct cpu_topology {
        short die_id;
 };
 
+static int read_only;
+
+static void check_privilege(void)
+{
+       if (!read_only)
+               return;
+
+       isst_display_error_info_message(1, "Insufficient privileges", 0, 0);
+       isst_ctdp_display_information_end(outf);
+       exit(1);
+}
+
 FILE *get_output_file(void)
 {
        return outf;
@@ -1578,6 +1590,8 @@ free_mask:
 
 static void set_tdp_level(int arg)
 {
+       check_privilege();
+
        if (cmd_help) {
                fprintf(stderr, "Set Config TDP level\n");
                fprintf(stderr,
@@ -2046,6 +2060,8 @@ static void set_pbf_enable(int arg)
 {
        int enable = arg;
 
+       check_privilege();
+
        if (cmd_help) {
                if (enable) {
                        fprintf(stderr,
@@ -2212,6 +2228,8 @@ static void set_fact_enable(int arg)
        int i, ret, enable = arg;
        struct isst_id id;
 
+       check_privilege();
+
        if (cmd_help) {
                if (enable) {
                        fprintf(stderr,
@@ -2361,6 +2379,8 @@ static void set_clos_enable(int arg)
 {
        int enable = arg;
 
+       check_privilege();
+
        if (cmd_help) {
                if (enable) {
                        fprintf(stderr,
@@ -2491,6 +2511,8 @@ static void set_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
 
 static void set_clos_config(int arg)
 {
+       check_privilege();
+
        if (cmd_help) {
                fprintf(stderr,
                        "Set core-power configuration for one of the four clos ids\n");
@@ -2556,6 +2578,8 @@ static void set_clos_assoc_for_cpu(struct isst_id *id, void *arg1, void *arg2, v
 
 static void set_clos_assoc(int arg)
 {
+       check_privilege();
+
        if (cmd_help) {
                fprintf(stderr, "Associate a clos id to a CPU\n");
                fprintf(stderr,
@@ -2637,6 +2661,8 @@ static void set_turbo_mode(int arg)
        int i, disable = arg;
        struct isst_id id;
 
+       check_privilege();
+
        if (cmd_help) {
                if (disable)
                        fprintf(stderr, "Set turbo mode disable\n");
@@ -2682,6 +2708,7 @@ static void get_set_trl(struct isst_id *id, void *arg1, void *arg2, void *arg3,
        }
 
        if (set) {
+               check_privilege();
                ret = isst_set_trl(id, fact_trl);
                isst_display_result(id, outf, "turbo-mode", "set-trl", ret);
                return;
@@ -3204,8 +3231,16 @@ static void cmdline(int argc, char **argv)
        };
 
        if (geteuid() != 0) {
-               fprintf(stderr, "Must run as root\n");
-               exit(0);
+               int fd;
+
+               fd = open(pathname, O_RDWR);
+               if (fd < 0) {
+                       fprintf(stderr, "Must run as root\n");
+                       exit(0);
+               }
+               fprintf(stderr, "\nNot running as root, Only read only operations are supported\n");
+               close(fd);
+               read_only = 1;
        }
 
        ret = update_cpu_model();