Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751352AbdHAHXe (ORCPT ); Tue, 1 Aug 2017 03:23:34 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:37115 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750763AbdHAHXc (ORCPT ); Tue, 1 Aug 2017 03:23:32 -0400 Date: Tue, 1 Aug 2017 08:23:29 +0100 From: Piotr Gregor To: Ian Abbott Cc: devel@driverdev.osuosl.org, Greg Kroah-Hartman , H Hartley Sweeten , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] staging: comedi: comedi_fops: do not call blocking ops when !TASK_RUNNING Message-ID: <20170801072329.v5rdkogok2coyq4p@debian1.home> References: <20170728152231.4521-1-abbotti@mev.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170728152231.4521-1-abbotti@mev.co.uk> User-Agent: Mutt/1.6.2-neo (2016-06-11) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1726 Lines: 50 On Fri, Jul 28, 2017 at 04:22:31PM +0100, Ian Abbott wrote: > Comedi's read and write file operation handlers (`comedi_read()` and > `comedi_write()`) currently call `copy_to_user()` or `copy_from_user()` > whilst in the `TASK_INTERRUPTIBLE` state, which falls foul of the > `might_fault()` checks when enabled. Fix it by setting the current task > state back to `TASK_RUNNING` a bit earlier before calling these > functions. > > Reported-by: Piotr Gregor > Signed-off-by: Ian Abbott > Cc: # 4.5+ > --- > Note: stable kernel versions 4.4 and earlier will need a slightly more > extensive change in `comedi_write()` than provided by this patch due to > a call to `mutex_lock()` whilst in the `TASK_INTERRUPTIBLE` state. > --- > drivers/staging/comedi/comedi_fops.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c > index ca11be21f64b..34ca7823255d 100644 > --- a/drivers/staging/comedi/comedi_fops.c > +++ b/drivers/staging/comedi/comedi_fops.c > @@ -2396,6 +2396,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf, > continue; > } > > + set_current_state(TASK_RUNNING); > wp = async->buf_write_ptr; > n1 = min(n, async->prealloc_bufsz - wp); > n2 = n - n1; > @@ -2528,6 +2529,8 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, > } > continue; > } > + > + set_current_state(TASK_RUNNING); > rp = async->buf_read_ptr; > n1 = min(n, async->prealloc_bufsz - rp); > n2 = n - n1; > -- > 2.13.2 > Hi Ian, I will be able to test this in a couple of days. cheers, Piotr