lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160527184007.384d23b3@bbrezillon>
Date:	Fri, 27 May 2016 18:40:07 +0200
From:	Boris Brezillon <boris.brezillon@...e-electrons.com>
To:	Brian Norris <briannorris@...omium.org>
Cc:	Thierry Reding <thierry.reding@...il.com>,
	linux-pwm@...r.kernel.org, linux-kernel@...r.kernel.org,
	Brian Norris <computersforpeace@...il.com>,
	Doug Anderson <dianders@...omium.org>
Subject: Re: [PATCH] pwm: don't allow duty cycle higher than period

On Fri, 27 May 2016 18:38:14 +0200
Boris Brezillon <boris.brezillon@...e-electrons.com> wrote:

> On Fri, 27 May 2016 09:35:33 -0700
> Brian Norris <briannorris@...omium.org> wrote:
> 
> > Hi Boris,
> > 
> > On Fri, May 27, 2016 at 09:34:39AM +0200, Boris Brezillon wrote:  
> > > On Thu, 26 May 2016 14:05:30 -0700
> > > Brian Norris <briannorris@...omium.org> wrote:
> > >     
> > > > It doesn't make sense to allow the duty cycle to be larger than the
> > > > period. I can see this behavior by, e.g.:
> > > > 
> > > >   # echo 1 > /sys/class/pwm/pwmchip0/export
> > > >   # cat /sys/class/pwm/pwmchip0/pwm1/period
> > > >   100
> > > >   # echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
> > > >   [... driver may or may not reject the value, or trigger some logic bug ...]
> > > > 
> > > > It's better to see:
> > > > 
> > > >   # echo 1 > /sys/class/pwm/pwmchip0/export
> > > >   # cat /sys/class/pwm/pwmchip0/pwm1/period
> > > >   100
> > > >   # echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
> > > >   -bash: echo: write error: Invalid argument
> > > > 
> > > > Signed-off-by: Brian Norris <briannorris@...omium.org>
> > > > ---
> > > >  drivers/pwm/core.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > > 
> > > > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> > > > index dba3843c53b8..9246b60f894a 100644
> > > > --- a/drivers/pwm/core.c
> > > > +++ b/drivers/pwm/core.c
> > > > @@ -463,6 +463,9 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
> > > >  	if (!memcmp(state, &pwm->state, sizeof(*state)))
> > > >  		return 0;
> > > >  
> > > > +	if (state->duty_cycle > state->period)
> > > > +		return -EINVAL;
> > > > +    
> > > 
> > > Argh, I forgot to move the pwm_config() checks [1] into
> > > pwm_apply_state() :-/.    
> > 
> > Oh, I didn't actually notice this was a regression.
> >   
> > > I think we should check all the corner cases (see this diff [2]),    
> > 
> > Now that you mention it, I think you've also dropped some signed
> > (negative value) checking in pwm_config(). I'll squash in your diff +
> > some pwm_config() fixes.  
> 
> ->period and ->duty_cycle are unsigned now ;).  
> 

Never mind, you're right (thought you were talking about checking the
->period and ->duty_cycle values).

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ