public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joelaf@google.com>
To: linux-kernel@vger.kernel.org,
	syzbot <syzbot+8ec30bb7bf1a981a2012@syzkaller.appspotmail.com>,
	hughd@google.com, linux-mm@kvack.org,
	syzkaller-bugs@googlegroups.com
Cc: Dmitry Vyukov <dvyukov@google.com>, Joel Fernandes <joelaf@google.com>
Subject: Re: possible deadlock in shmem_file_llseek
Date: Wed, 24 Jan 2018 09:47:23 -0800	[thread overview]
Message-ID: <20180124174723.25289-1-joelaf@google.com> (raw)
In-Reply-To: <001a1144d6e854b3c90562668d74@google.com>


#syz test: https://github.com/joelagnel/linux.git test-ashmem

--->8----
>From 55dd7e77e0e46af101ef2195d618d5f56af1023d Mon Sep 17 00:00:00 2001
From: Joel Fernandes <joelaf@google.com>
Date: Tue, 23 Jan 2018 17:45:04 -0800
Subject: [PATCH] ashmem: Fix lockdep issue during llseek

ashmem_mutex create a chain of dependencies like so:

(1)
mmap syscall ->
  mmap_sem ->  (acquired)
  ashmem_mmap
  ashmem_mutex (try to acquire)
  (block)

(2)
llseek syscall ->
  ashmem_llseek ->
  ashmem_mutex ->  (acquired)
  inode_lock ->
  inode->i_rwsem (try to acquire)
  (block)

(3)
getdents ->
  iterate_dir ->
  inode_lock ->
  inode->i_rwsem   (acquired)
  copy_to_user ->
  mmap_sem         (try to acquire)

There is a lock ordering created between mmap_sem and inode->i_rwsem
during a syzcaller test, this patch fixes the issue by releasing the
ashmem_mutex before the call the vfs_llseek, and reacquiring it after.

Reported-by: syzbot+8ec30bb7bf1a981a2012@syzkaller.appspotmail.com
Signed-off-by: Joel Fernandes <joelaf@google.com>
---
 drivers/staging/android/ashmem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 0f695df14c9d..248983cf2db1 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -343,7 +343,9 @@ static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
 		goto out;
 	}
 
+	mutex_unlock(&ashmem_mutex);
 	ret = vfs_llseek(asma->file, offset, origin);
+	mutex_lock(&ashmem_mutex);
 	if (ret < 0)
 		goto out;
 
-- 
2.16.0.rc1.238.g530d649a79-goog

  parent reply	other threads:[~2018-01-24 17:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  6:58 possible deadlock in shmem_file_llseek syzbot
2018-01-10  8:02 ` Dmitry Vyukov
2018-01-24 17:47 ` Joel Fernandes [this message]
2018-01-24 18:40   ` Dmitry Vyukov
2018-01-24 18:42     ` syzbot
2018-01-24 18:43       ` Dmitry Vyukov
2018-01-24 19:01         ` syzbot
2018-01-24 21:11     ` Joel Fernandes
2018-01-30  3:05     ` Joel Fernandes
  -- strict thread matches above, loose matches on Subject: below --
2018-01-31 17:23 Joel Fernandes
2018-01-31 17:42 ` syzbot

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=20180124174723.25289-1-joelaf@google.com \
    --to=joelaf@google.com \
    --cc=dvyukov@google.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=syzbot+8ec30bb7bf1a981a2012@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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