Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1323914 > unrolled thread

[patch] goldfish: locking bugs in goldfish_pipe_read_write()

Started byDan Carpenter <dan.carpenter@oracle.com>
First post2016-02-02 10:50 +0100
Last post2016-02-02 12:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [patch] goldfish: locking bugs in goldfish_pipe_read_write() Dan Carpenter <dan.carpenter@oracle.com> - 2016-02-02 10:50 +0100
    Re: [patch] goldfish: locking bugs in goldfish_pipe_read_write() Christoffer Dall <christoffer.dall@linaro.org> - 2016-02-02 12:50 +0100

#1323914 — [patch] goldfish: locking bugs in goldfish_pipe_read_write()

FromDan Carpenter <dan.carpenter@oracle.com>
Date2016-02-02 10:50 +0100
Subject[patch] goldfish: locking bugs in goldfish_pipe_read_write()
Message-ID<qXFKW-BP-13@gated-at.bofh.it>
We recently messed up the error handling here.  We can return with the
pipe->lock held or sometimes we unlock twice by mistake.

Fixes: 2f3be88237a3 ('goldfish_pipe: Pin pages to memory while copying and other cleanups')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
index e3fab9a..839df4a 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -313,7 +313,7 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
 				     !is_write, 0, &page, NULL);
 		up_read(&current->mm->mmap_sem);
 		if (ret < 0)
-			return ret;
+			break;
 
 		if (dev->version) {
 			/* Device version 1 or newer (qemu-android) expects the
@@ -400,22 +400,16 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
 		while (test_bit(wakeBit, &pipe->flags)) {
 			if (wait_event_interruptible(
 					pipe->wake_queue,
-					!test_bit(wakeBit, &pipe->flags))) {
-				ret = -ERESTARTSYS;
-				break;
-			}
-
-			if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) {
-				ret = -EIO;
-				break;
-			}
+					!test_bit(wakeBit, &pipe->flags)))
+				return -ERESTARTSYS;
+
+			if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
+				return -EIO;
 		}
 
 		/* Try to re-acquire the lock */
-		if (mutex_lock_interruptible(&pipe->lock)) {
-			ret = -ERESTARTSYS;
-			break;
-		}
+		if (mutex_lock_interruptible(&pipe->lock))
+			return -ERESTARTSYS;
 	}
 	mutex_unlock(&pipe->lock);
 

[toc] | [next] | [standalone]


#1324012

FromChristoffer Dall <christoffer.dall@linaro.org>
Date2016-02-02 12:50 +0100
Message-ID<qXHD4-2bY-31@gated-at.bofh.it>
In reply to#1323914
On Tue, Feb 02, 2016 at 12:48:09PM +0300, Dan Carpenter wrote:
> We recently messed up the error handling here.  We can return with the
> pipe->lock held or sometimes we unlock twice by mistake.
> 
> Fixes: 2f3be88237a3 ('goldfish_pipe: Pin pages to memory while copying and other cleanups')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
> index e3fab9a..839df4a 100644
> --- a/drivers/platform/goldfish/goldfish_pipe.c
> +++ b/drivers/platform/goldfish/goldfish_pipe.c
> @@ -313,7 +313,7 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
>  				     !is_write, 0, &page, NULL);
>  		up_read(&current->mm->mmap_sem);
>  		if (ret < 0)
> -			return ret;
> +			break;
>  
>  		if (dev->version) {
>  			/* Device version 1 or newer (qemu-android) expects the
> @@ -400,22 +400,16 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
>  		while (test_bit(wakeBit, &pipe->flags)) {
>  			if (wait_event_interruptible(
>  					pipe->wake_queue,
> -					!test_bit(wakeBit, &pipe->flags))) {
> -				ret = -ERESTARTSYS;
> -				break;
> -			}
> -
> -			if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) {
> -				ret = -EIO;
> -				break;
> -			}
> +					!test_bit(wakeBit, &pipe->flags)))
> +				return -ERESTARTSYS;
> +
> +			if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
> +				return -EIO;
>  		}
>  
>  		/* Try to re-acquire the lock */
> -		if (mutex_lock_interruptible(&pipe->lock)) {
> -			ret = -ERESTARTSYS;
> -			break;
> -		}
> +		if (mutex_lock_interruptible(&pipe->lock))
> +			return -ERESTARTSYS;
>  	}
>  	mutex_unlock(&pipe->lock);
>  

yeah, that was pretty broken, thanks for fixing this.

Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web