2014-12-14 12:37:06

by Michal Privoznik

[permalink] [raw]
Subject: [PATCH] cpupower: Correctly detect if running as root

Some operations, like frequency-set, need root privileges. However,
the way that this is detected is not correct. The getuid() is called,
while in fact geteuid() should be. This way we can allow
distributions or users to set SETUID flags on the cpupower binary if
they want to and let regular users change the cpu frequency governor.

Signed-off-by: Michal Privoznik <[email protected]>
---
tools/power/cpupower/utils/cpupower.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
index 7cdcf88..9ea9143 100644
--- a/tools/power/cpupower/utils/cpupower.c
+++ b/tools/power/cpupower/utils/cpupower.c
@@ -199,7 +199,7 @@ int main(int argc, const char *argv[])
}

get_cpu_info(0, &cpupower_cpu_info);
- run_as_root = !getuid();
+ run_as_root = !geteuid();
if (run_as_root) {
ret = uname(&uts);
if (!ret && !strcmp(uts.machine, "x86_64") &&
--
2.0.4


2014-12-14 21:07:53

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] cpupower: Correctly detect if running as root

On Sunday, December 14, 2014 01:36:52 PM Michal Privoznik wrote:
> Some operations, like frequency-set, need root privileges. However,
> the way that this is detected is not correct. The getuid() is called,
> while in fact geteuid() should be. This way we can allow
> distributions or users to set SETUID flags on the cpupower binary if
> they want to and let regular users change the cpu frequency governor.
>
> Signed-off-by: Michal Privoznik <[email protected]>

An ACK from Thomas is needed.

> ---
> tools/power/cpupower/utils/cpupower.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
> index 7cdcf88..9ea9143 100644
> --- a/tools/power/cpupower/utils/cpupower.c
> +++ b/tools/power/cpupower/utils/cpupower.c
> @@ -199,7 +199,7 @@ int main(int argc, const char *argv[])
> }
>
> get_cpu_info(0, &cpupower_cpu_info);
> - run_as_root = !getuid();
> + run_as_root = !geteuid();
> if (run_as_root) {
> ret = uname(&uts);
> if (!ret && !strcmp(uts.machine, "x86_64") &&
>

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-12-17 16:22:58

by Thomas Renninger

[permalink] [raw]
Subject: Re: [PATCH] cpupower: Correctly detect if running as root

On Sunday, December 14, 2014 10:29:24 PM Rafael J. Wysocki wrote:
> On Sunday, December 14, 2014 01:36:52 PM Michal Privoznik wrote:
> > Some operations, like frequency-set, need root privileges. However,
> > the way that this is detected is not correct. The getuid() is called,
> > while in fact geteuid() should be. This way we can allow
> > distributions or users to set SETUID flags on the cpupower binary if
> > they want to and let regular users change the cpu frequency governor.
> >
> > Signed-off-by: Michal Privoznik <[email protected]>
>
> An ACK from Thomas is needed.
Patch is correct, Thanks!

Acked-by: Thomas Renninger <[email protected]>

Thomas
>
> > ---
> >
> > tools/power/cpupower/utils/cpupower.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/power/cpupower/utils/cpupower.c
> > b/tools/power/cpupower/utils/cpupower.c index 7cdcf88..9ea9143 100644
> > --- a/tools/power/cpupower/utils/cpupower.c
> > +++ b/tools/power/cpupower/utils/cpupower.c
> > @@ -199,7 +199,7 @@ int main(int argc, const char *argv[])
> >
> > }
> >
> > get_cpu_info(0, &cpupower_cpu_info);
> >
> > - run_as_root = !getuid();
> > + run_as_root = !geteuid();
> >
> > if (run_as_root) {
> >
> > ret = uname(&uts);
> > if (!ret && !strcmp(uts.machine, "x86_64") &&