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 BC2616D1D7; Tue, 23 Jan 2024 02:03:12 +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=1705975392; cv=none; b=dRJWjQAw/NaNZqmPQM0GM0s3vJR7SBWaHWKRHstSvQOIti156RjCvuOUI8D443dfLJMWpEpqUhaANdxOyK1t0Ea7RqklOawDq6/StIfSE9TGYwU6Ipz2w3rTG320iDfmreeb5lSuEZOIwbeQ2tfy4lEJb77vC87M/7QlTHYM2Uc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975392; c=relaxed/simple; bh=3SdE4aOUqdyewTKbQK3zlH7SCmp9Clbq//rDLIoYYQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KC93oka6Jpe3xQzT5RKa/Nnseri9qxBveIyZ8WRJ15FdzjaSON4T4MEbDMUdqOX9Ea7PveU7kZML5mJXN0D/DUVFjM6kZPdx+xQydY+4mf5u345No+ng7HpSWHlO1Ol9ISojzziNyCmzWUI2ziy0NiEdSIt8rLH1DY2MLltmryc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TGJ0iFfU; 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="TGJ0iFfU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84009C43394; Tue, 23 Jan 2024 02:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705975392; bh=3SdE4aOUqdyewTKbQK3zlH7SCmp9Clbq//rDLIoYYQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGJ0iFfU+PyTgGGPIgzpebFwl+YW/ZF8VXv6r5Twb/a8txw9WMKa4Xhgj+TnOJxFZ 77grnhq+ziew/r+3vfS0KdWZXe4laMHPxP2duxkwdkc+Qk9Ex/2t9RGHLZYjGSoCr7 QQ1iDos/VAw5bD1P8DUnfYwdGSgsxg8BEtZzbPGM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alice Ryhl , Carlos Llamas Subject: [PATCH 6.6 353/583] binder: fix race between mmput() and do_exit() Date: Mon, 22 Jan 2024 15:56:44 -0800 Message-ID: <20240122235822.821515325@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235812.238724226@linuxfoundation.org> References: <20240122235812.238724226@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.6-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; }