stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Paul Lawrence <paullawrence@google.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	"Ben Hutchings" <ben@decadent.org.uk>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Martijn Coenen" <maco@android.com>,
	devel@driverdev.osuosl.org
Subject: Re: [PATCH] staging: android: ashmem: Remove deadlock
Date: Wed, 7 Mar 2018 14:48:29 -0700	[thread overview]
Message-ID: <20180307214829.GA15587@flashbox> (raw)
In-Reply-To: <20180307214042.135109-1-paullawrence@google.com>

On Wed, Mar 07, 2018 at 01:40:30PM -0800, Paul Lawrence wrote:
> Regression introduced in commit ce8a3a9e76d0193e2e8d74a06d275b3c324ca652
> ("staging: android: ashmem: Fix a race condition in pin ioctls")
> causing deadlock.
> 
> No need to hold ashmem_mutex while copying from user
> 
> Stacks are:
> 
> ashmem_mmap+0x53/0x400 drivers/staging/android/ashmem.c:379
> mmap_region+0x7dd/0xfd0 mm/mmap.c:1694
> do_mmap+0x57b/0xbe0 mm/mmap.c:1473
> 
> and
> 
> lock_acquire+0x12e/0x410 kernel/locking/lockdep.c:3756
> __might_fault+0x14a/0x1d0 mm/memory.c:4014
> copy_from_user arch/x86/include/asm/uaccess.h:705 [inline]
> ashmem_pin_unpin drivers/staging/android/ashmem.c:719 [inline]
> 
> Signed-off-by: Paul Lawrence <paullawrence@google.com>
> Cc: <stable@vger.kernel.org> # 4.9.x
> Cc: <stable@vger.kernel.org> # 4.4.x
> Cc: <stable@vger.kernel.org> # 3.18.x: ce8a3a9e76d01
> Cc: <stable@vger.kernel.org> # 3.18.x
> Cc: Ben Hutchings <ben@decadent.org.uk>
> ---
>  drivers/staging/android/ashmem.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
> index 6dbba5aff191..8c55706c2cfa 100644
> --- a/drivers/staging/android/ashmem.c
> +++ b/drivers/staging/android/ashmem.c
> @@ -702,16 +702,14 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
>  	size_t pgstart, pgend;
>  	int ret = -EINVAL;
>  
> +	if (unlikely(copy_from_user(&pin, p, sizeof(pin))))
> +		return -EFAULT;
> +
>  	mutex_lock(&ashmem_mutex);
>  
>  	if (unlikely(!asma->file))
>  		goto out_unlock;
>  
> -	if (unlikely(copy_from_user(&pin, p, sizeof(pin)))) {
> -		ret = -EFAULT;
> -		goto out_unlock;
> -	}
> -
>  	/* per custom, you can pass zero for len to mean "everything onward" */
>  	if (!pin.len)
>  		pin.len = PAGE_ALIGN(asma->size) - pin.offset;
> -- 
> 2.16.2.395.g2e18187dfd-goog
>

Hey Paul,

Looks like this same patch is already in Greg's tree:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git/commit/?id=740a5759bf222332fbb5eda42f89aa25ba38f9b2

Cheers!
Nathan Chancellor

  reply	other threads:[~2018-03-07 21:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 21:40 [PATCH] staging: android: ashmem: Remove deadlock Paul Lawrence
2018-03-07 21:48 ` Nathan Chancellor [this message]
     [not found]   ` <CAL=UVf7Y0Ga869u66xi0EumQAkULAP0fWf9O69Z0vYJ9G5gmcA@mail.gmail.com>
2018-03-07 22:07     ` Greg Kroah-Hartman
2018-03-08 11:02 ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180307214829.GA15587@flashbox \
    --to=natechancellor@gmail.com \
    --cc=arve@android.com \
    --cc=ben@decadent.org.uk \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.com \
    --cc=paullawrence@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tkjos@android.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).