Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3596817ybl; Tue, 21 Jan 2020 03:48:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw6j4Nod7a2+ZY12wvtnVaiwqz9v+KB+v8CDeHuLX6MhViQwB97ZnKRxFL1eudPmZEZVV9o X-Received: by 2002:aca:c494:: with SMTP id u142mr2729836oif.86.1579607289267; Tue, 21 Jan 2020 03:48:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579607289; cv=none; d=google.com; s=arc-20160816; b=bZVgiVohz2qk9OC+yebQp5jpj0NRf826BlaT++1lY0Q+4lbEDtUgNdsqGsEgXQ2Mgo fQLr9uY2t3fGWCDLw5Gndo9wKj/rGcSJDgwDcEcggDoS08DJZqTyJw6EaxJqa58j3JBZ tWT9g3ONdakrMffk+PXRYt1dqfF3L/6dq7jooLEp4+KBPjusyz5RxO4dtVhTSKVeg6/m nvOunNEMCEHzUg/9Xs4kQys+r/807q3hWwIIC1PQ+Qq1xmJTYaHk6C3AJkzwF98ogihf mBlFgXR3kazGeyCsej6+GBcCbI8/DiW2kTfPt/GBdT+V74B8T3NXAwInUxl1qykOm62T 80rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=XczTCn/rnfL/G3li4qG6+MyxraMAjIFdReRjWFo3ZrQ=; b=JEIxkj0fVAdUJIWUt1lAUYareqGpS2gDO2z16O9dTSxbcurW13kSIDogB9IlhRHQvL mutuQWK0CO6G1668THrpW/zhV//CLwLKYayvSwqCc8FhQ2Aaxe5GiPm+i2+mk6qX8k0r 4a4E/gDL23Sp2DTKNxn7Bkk1WeTyJail2V4AOvE+/fqEeoykjICJGp4g9Yfiz/E1GENt VnfFzqirRVYgddx6Z5jYQXTTaURpsRUtUpBxVoaLFaBkiFwtK9N9Oh88vpNlQ42oPV++ vxacfQxo91nAmHsI2MnHiBm0c6XaTu1sR8Gtpy7X0MoGqskmdgWRHFCCNpWnZ6yl8tux 5wKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si22067894otp.111.2020.01.21.03.47.57; Tue, 21 Jan 2020 03:48:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729409AbgAULq2 (ORCPT + 99 others); Tue, 21 Jan 2020 06:46:28 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:42287 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726052AbgAULq1 (ORCPT ); Tue, 21 Jan 2020 06:46:27 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N5mSj-1jhyoV2BSN-017CgH; Tue, 21 Jan 2020 12:46:00 +0100 From: Arnd Bergmann To: Lucas Stach Cc: Arnd Bergmann , =?UTF-8?q?Guido=20G=C3=BCnther?= , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Philipp Zabel , Sam Ravnborg , Rob Herring , Emil Velikov , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/etnaviv: only reject timeouts with tv_nsec >= 2 seconds Date: Tue, 21 Jan 2020 12:45:25 +0100 Message-Id: <20200121114553.2667556-1-arnd@arndb.de> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:mC7FeQHazeOL/EsiloGVwenBqO1CqSzKh9a3azedjzvSyEdynvt PTIDkCtpkmSAi0hqrYtN76EzktImZwsEkh0+c9a1+oN67MRE439lpwzjVi5IyhqBMsix/Vx ifIKxKovG+T653zcUc8vdD0nVKWHd8AxwwkoaF51DpPrCMvQ6d624FEzGnKgvuIAkIAFp4Y KI3camDDhBDgIB75lVIAA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:9P78OmeT3W0=:SH2hT2Gyde3yA/AfdHEewi 9UYWvun/XZNKgNXHoEQkKw8tmTTgY1IFjtViM9tiCn20dQzXqDeKTUnw4/puATqhanXuGAjml 4mqXuyhHPbPPmXmfKN7n14u1uY+0OHeWBp1ZAaUkkxdRYLeOjJfq57z2VhNnP813Dzhvoie0A ix6fxh9pb9aEyR9Z541+Vr9l5s+a/gX6TS2+0VuZrx4MhpEgsSYpkqFpXOCFN2kljTVjrYSA0 SQSC24h5OGcq2HD2Y7GDBWzWkfWpABo5qm66hilTrfGxm89HZ3EHc01W3pe91YZ7U3hMSR3OW D62+2Itr5NXjtNhvjidNeBd2UcqLfu7VoymS0X895yV92hwNnZQOqVhOdawxYAcihXzeZOzov 1UKwsZv9IFebv9faPCPdHG2CRkOsFbhx+kZK8ZOwddoaHS3/KePFQZE3i9675NdwnrUzvmq9N y0brONYTtiRHLfC079hEng50khqQG9Q3+9YicMrlQQwMTw2Tt2mncuQbXaAk1rPQjmm1enOLQ C70OKrGiQNCaR8YsPOTa48OJhh2syTB1wgi1WGrgScEyZpTmTTWCL2Sh9rkfUmPPEVbNJT26G XxlELPJs4QaCLaT26iGicdw0SKgPb2TEkO8cpAI51ghu0+XpVXgcUJW+A4J6smoNcq3GeX/J6 WCCrlkbTCr0lY2B8MrgypKacuQjDqXPif5uwJmd2grONww6wMfrzoTFAqdyJxjVEOnPbNbrmD lFlPnGjmwnS/3xsCLTZrrR9u3EyM7Y1DVXMwe9LwSFzapRaJayFC9kqXk9KzLNQJhbD1SpdsD q4TN7NSZfSOQZoCHf32AOxAfg/6l5nStTyKH3Txx+cF3PkFqo7A8ZCeF5LJeJ094CiUhNKfc9 oyoLcIVRJgqFsOVsDiDg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 Link: https://patchwork.kernel.org/patch/11291089/ Signed-off-by: Arnd Bergmann --- 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