From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3371733097; Tue, 23 Jan 2024 00:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969657; cv=none; b=kXOe6dVBTrnxH/I+Dywvw3Y2vEqzgzfEKRbPy+Vf2IVOV0057Okv0uBSW+0MGAtJE+pIDiwv7Pw6XXX0zMG39rVTkgnWHUBQBqTBZCKDncWpLlo14l7AKfUq59USnMM9dSwXTtvqaA17E6A8edXlwVPeckNzli3UeuzlgvF6KLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969657; c=relaxed/simple; bh=Xzl25RfW47QX1x725omJINM/YyAxzDMrkWoNQJ4OkNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UG4bf6wekM1jyFWlpX4J4uQ7MkDXYxDQULrutDRs+VvKoqJx4bvH0WHiZRzIyMN+VKA7FIUxQnlhs92X5xivkg3ZsKB3VrooxOSg5zd2QHAtocv4dSztGLA5w7ExULT/qJTKIhQgiTvwEkRRyTDmmoJJr8EvlkfK7N4Vs4z9tpU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Vkwns5RW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Vkwns5RW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E411AC43390; Tue, 23 Jan 2024 00:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969657; bh=Xzl25RfW47QX1x725omJINM/YyAxzDMrkWoNQJ4OkNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vkwns5RWMed5wouM2hIaEFLhOfOlLDP+UVTvf8oEmBxMWL2F+8OpQZpVaGM3EG7ES wCd0qErA6RUGI4HV6qOGc1gJybrM53dlvpKf52cMu573bWKTSWoYfJPXxaS4xsa2Ry X43lRjSpzdFmD+T9aBgLl+do9Gz/qXWOoCLXdQGI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alice Ryhl , Carlos Llamas Subject: [PATCH 6.7 387/641] binder: fix race between mmput() and do_exit() Date: Mon, 22 Jan 2024 15:54:51 -0800 Message-ID: <20240122235830.064272627@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235818.091081209@linuxfoundation.org> References: <20240122235818.091081209@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Carlos Llamas commit 9a9ab0d963621d9d12199df9817e66982582d5a5 upstream. Task A calls binder_update_page_range() to allocate and insert pages on a remote address space from Task B. For this, Task A pins the remote mm via mmget_not_zero() first. This can race with Task B do_exit() and the final mmput() refcount decrement will come from Task A. Task A | Task B ------------------+------------------ mmget_not_zero() | | do_exit() | exit_mm() | mmput() mmput() | exit_mmap() | remove_vma() | fput() | In this case, the work of ____fput() from Task B is queued up in Task A as TWA_RESUME. So in theory, Task A returns to userspace and the cleanup work gets executed. However, Task A instead sleep, waiting for a reply from Task B that never comes (it's dead). This means the binder_deferred_release() is blocked until an unrelated binder event forces Task A to go back to userspace. All the associated death notifications will also be delayed until then. In order to fix this use mmput_async() that will schedule the work in the corresponding mm->async_put_work WQ instead of Task A. Fixes: 457b9a6f09f0 ("Staging: android: add binder driver") Reviewed-by: Alice Ryhl Signed-off-by: Carlos Llamas Link: https://lore.kernel.org/r/20231201172212.1813387-4-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -271,7 +271,7 @@ static int binder_update_page_range(stru } if (mm) { mmap_write_unlock(mm); - mmput(mm); + mmput_async(mm); } return 0; @@ -304,7 +304,7 @@ err_page_ptr_cleared: err_no_vma: if (mm) { mmap_write_unlock(mm); - mmput(mm); + mmput_async(mm); } return vma ? -ENOMEM : -ESRCH; }