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: <1971902c68ff805ee0b4a66f558afe06e6edf0c5.camel@pengutronix.de>
Date:   Tue, 21 Jan 2020 17:09:56 +0100
From:   Lucas Stach <l.stach@...gutronix.de>
To:     Guido Günther <agx@...xcpu.org>,
        Arnd Bergmann <arnd@...db.de>
Cc:     Russell King <linux+etnaviv@...linux.org.uk>,
        Christian Gmeiner <christian.gmeiner@...il.com>,
        David Airlie <airlied@...ux.ie>,
        Daniel Vetter <daniel@...ll.ch>,
        Philipp Zabel <p.zabel@...gutronix.de>,
        Sam Ravnborg <sam@...nborg.org>, Rob Herring <robh@...nel.org>,
        Emil Velikov <emil.velikov@...labora.com>,
        etnaviv@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] drm/etnaviv: only reject timeouts with tv_nsec >= 2
 seconds

Hi Guido,

On Di, 2020-01-21 at 13:55 +0100, Guido Günther wrote:
> Hi,
> On Tue, Jan 21, 2020 at 12:45:25PM +0100, Arnd Bergmann wrote:
> > As Guido Günther reported, get_abs_timeout() in the etnaviv user space
> > sometimes passes timeouts with nanosecond values larger than 1000000000,
> > which gets rejected after my first patch.
> > 
> > To avoid breaking this, while also not allowing completely arbitrary
> > values, set the limit to 1999999999 and use set_normalized_timespec64()
> > to get the correct format before comparing it.
> 
> I'm seeing values up to 5 seconds so I need
> 
>      if (args->timeout.tv_nsec > (5 * NSEC_PER_SEC))
> 
> to unbreak rendering. Which seems to match what mesa's get_abs_timeout()
> does and how it's invoked.

I have not tested this myself yet, only looked at the code. From the
code I quoted earlier, I don't see how we end up with 5 * NSEC_PER_SEC
in the tv_nsec member, even if the timeout passed to get_abs_timeout()
is 5 seconds.

Regards,
Lucas

>    with that:
> 
> Tested-by: Guido Günther <agx@...xcpu.org>
> 
> Cheers,
>  -- Guido
> 
> > This also addresses the off-by-1 glitch reported by Ben Hutchings.
> > 
> > Fixes: 172a216ff334 ("drm/etnaviv: reject timeouts with tv_nsec >= NSEC_PER_SEC")
> > Cc: Guido Günther <agx@...xcpu.org>
> > Link: https://patchwork.kernel.org/patch/11291089/
> > Signed-off-by: Arnd Bergmann <arnd@...db.de>
> > ---
> >  drivers/gpu/drm/etnaviv/etnaviv_drv.c | 10 +++++++---
> >  drivers/gpu/drm/etnaviv/etnaviv_drv.h |  6 ++----
> >  2 files changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> > index 3eb0f9223bea..d94740c123d3 100644
> > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> > @@ -292,7 +292,11 @@ static int etnaviv_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
> >  	if (args->op & ~(ETNA_PREP_READ | ETNA_PREP_WRITE | ETNA_PREP_NOSYNC))
> >  		return -EINVAL;
> >  
> > -	if (args->timeout.tv_nsec > NSEC_PER_SEC)
> > +	/*
> > +	 * existing user space passes non-normalized timespecs, but never
> > +	 * more than 2 seconds worth of nanoseconds
> > +	 */
> > +	if (args->timeout.tv_nsec >= (2 * NSEC_PER_SEC))
> >  		return -EINVAL;
> >  
> >  	obj = drm_gem_object_lookup(file, args->handle);
> > @@ -358,7 +362,7 @@ static int etnaviv_ioctl_wait_fence(struct drm_device *dev, void *data,
> >  	if (args->flags & ~(ETNA_WAIT_NONBLOCK))
> >  		return -EINVAL;
> >  
> > -	if (args->timeout.tv_nsec > NSEC_PER_SEC)
> > +	if (args->timeout.tv_nsec >= (2 * NSEC_PER_SEC))
> >  		return -EINVAL;
> >  
> >  	if (args->pipe >= ETNA_MAX_PIPES)
> > @@ -412,7 +416,7 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data,
> >  	if (args->flags & ~(ETNA_WAIT_NONBLOCK))
> >  		return -EINVAL;
> >  
> > -	if (args->timeout.tv_nsec > NSEC_PER_SEC)
> > +	if (args->timeout.tv_nsec >= (2 * NSEC_PER_SEC))
> >  		return -EINVAL;
> >  
> >  	if (args->pipe >= ETNA_MAX_PIPES)
> > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> > index efc656efeb0f..3e47050af706 100644
> > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> > @@ -109,12 +109,10 @@ static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
> >  static inline unsigned long etnaviv_timeout_to_jiffies(
> >  	const struct drm_etnaviv_timespec *timeout)
> >  {
> > -	struct timespec64 ts, to = {
> > -		.tv_sec = timeout->tv_sec,
> > -		.tv_nsec = timeout->tv_nsec,
> > -	};
> > +	struct timespec64 ts, to;
> >  
> >  	ktime_get_ts64(&ts);
> > +	set_normalized_timespec64(&to, timeout->tv_sec, timeout->tv_nsec);
> >  
> >  	/* timeouts before "now" have already expired */
> >  	if (timespec64_compare(&to, &ts) <= 0)
> > -- 
> > 2.25.0
> > 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ