Re: [PATCH V3] cpuidle: Add a sysfs entry to disable specific C state for debug purpose.

Henrique de Moraes Holschuh
2012-03-13T20:49:20Z

On Tue, 13 Mar 2012, Yanmin Zhang wrote:
> > > > > +static ssize_t store_state_##_name(struct cpuidle_state *state, \
> > > > > + const char *buf, size_t size) \
> > > > > +{ \
> > > > > + int value; \
> > > > > + sscanf(buf, "%d", &value); \
> > > > > + if (value) \
> > > > > + state->disable = 1; \
> > > > > + else \
> > > > > + state->disable = 0; \
> > > > > + return size; \
> > > > > +}
> > > >
> > > > Isn't this missing a check for capabilities? Disabling cpuidle states is
> > > > not something random Joe (and IMHO that does mean random capability-
> > > > restricted Joe root) should be doing...
> > > Sorry. Could you elaborate it?
> >
> > Sure. Should any user be able to disable a C state, therefore causing
> > the system to consume more power?
> Here we use the simple way to check access. Only root could change it.

Yea, but capabilities are supposed to constrain root as well :-)

> > I am pretty sure the answer is NO, in which case you should check for
> > the appropriate user credentials before you allow a write to these
> > "debug" controls to succeed. "capability" here is one of the CAP_*
> > capabilities tested through capable(), which are supposed to limit even
> > root.
> We would add below check.
>
> if (!capable(CAP_SYS_ADMIN))
> return -EPERM;

Looks good.

Thanks!

--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh