From: Liam Howlett <liam.howlett@oracle.com>
To: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"arve@android.com" <arve@android.com>,
"brauner@kernel.org" <brauner@kernel.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"hridya@google.com" <hridya@google.com>,
"joel@joelfernandes.org" <joel@joelfernandes.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"maco@android.com" <maco@android.com>,
"surenb@google.com" <surenb@google.com>,
"tkjos@android.com" <tkjos@android.com>
Subject: [PATCH] android: binder: Fix lockdep check on clearing vma
Date: Mon, 27 Jun 2022 15:18:59 +0000 [thread overview]
Message-ID: <20220627151857.2316964-1-Liam.Howlett@oracle.com> (raw)
When munmapping a vma, the mmap_lock can be degraded to a write before
calling close() on the file handle. The binder close() function calls
binder_alloc_set_vma() to clear the vma address, which now has a lock
dep check for writing on the mmap_lock. Change the lockdep check to
ensure the reading lock is held while clearing and keep the write check
while writing.
Reported-by: syzbot+da54fa8d793ca89c741f@syzkaller.appspotmail.com
Fixes: 472a68df605b ("android: binder: stop saving a pointer to the VMA")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
drivers/android/binder_alloc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index f555eebceef6..1014beb12802 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -315,12 +315,19 @@ static inline void binder_alloc_set_vma(struct binder_alloc *alloc,
{
unsigned long vm_start = 0;
+ /*
+ * Allow clearing the vma with holding just the read lock to allow
+ * munmapping downgrade of the write lock before freeing and closing the
+ * file using binder_alloc_vma_close().
+ */
if (vma) {
vm_start = vma->vm_start;
alloc->vma_vm_mm = vma->vm_mm;
+ mmap_assert_write_locked(alloc->vma_vm_mm);
+ } else {
+ mmap_assert_locked(alloc->vma_vm_mm);
}
- mmap_assert_write_locked(alloc->vma_vm_mm);
alloc->vma_addr = vm_start;
}
--
2.35.1
next reply other threads:[~2022-06-27 15:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 15:18 Liam Howlett [this message]
2022-06-27 15:43 ` Todd Kjos
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=20220627151857.2316964-1-Liam.Howlett@oracle.com \
--to=liam.howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=arve@android.com \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hridya@google.com \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maco@android.com \
--cc=surenb@google.com \
--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
all inboxes | Powered by JetHome®