Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp563237rdb; Thu, 18 Jan 2024 11:29:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEFX0F+4BAi/WqAS+ZI65AsvPYtS5LiPn8vf614ZMZJdSVbGiUwJYIEGZtd5UYR+/vYSgH X-Received: by 2002:aa7:d44c:0:b0:559:d08b:b318 with SMTP id q12-20020aa7d44c000000b00559d08bb318mr962932edr.49.1705606161857; Thu, 18 Jan 2024 11:29:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705606161; cv=pass; d=google.com; s=arc-20160816; b=Od+mQRKeMOXaElPqNT9tKyNM7zzAVWvCJDmdlePg2meWCKX3inFwCm9UTMzEE3OApw Be+qYUU4E6vQLqVp3/Irokf6niEamDl1cabfv+HbcK3j89VplKGbEg4sgqQ5xAQxo57m 65dhbmGwdz+Tlhe9gbpJ0nAki3ToAEcRyEUqJdO2GBZicgrRvhEh8CViE7APTdFSH4tW HNFzvMXiSBp891iVwmMWOB0rMimaDDOG2G5UQ7CVJDB8fAxEm0OHdDfd4xB3Vl0+uYpd yYq1H1A4Qk88HLjxpnJqjoc+V4ZlgIMJhg0RU+fzqmWxnpJ5rNGIwmwPHiuuW3S77fOe 6rEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+iomTbXqRTjibxPrZcFIaAB8B6frVBWEtPfgQV/mc1o=; fh=dFXQ4kH5n6Jtw22yLNmylmiUFAy+1fb4DhC653lk3lU=; b=epLkY7yD/PJ7Byr5NS1amhqrAcV7OnZip9hP3z7YKrjPXkSxUW3x53KtvOfLy7YVol XSho3jcMO+4/goWI6kOwKZtbwVDExNMUaOF68HEYKJRLEGQ+tExUsQUm8EZi3YU9Nemm 2TkCQy9c1SrjeVYBWdlNCEe28yRNMM8g1StnIRVivNfYmEnssoJasKux9oIt6oE5oSA9 +yx8HtOE5UsAQtgAaL/vkVgIS1xIAsjg/nNDazxUupOY9Xqyy1xOYmHQRSa9VY3msAwb dPfvGRAhib8FVMi6MNXwA2aCGPNqYURArWvEfrse8wtbOM2X/lvjx2jptKkPYklpGXEw Zw0A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="S3u/Av31"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-30516-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fj9-20020a0564022b8900b00559cbe24779si2269598edb.675.2024.01.18.11.29.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:29:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30516-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="S3u/Av31"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-30516-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 750D51F2117D for ; Thu, 18 Jan 2024 19:29:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 558DC2E40E; Thu, 18 Jan 2024 19:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="S3u/Av31" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 457042E3FD for ; Thu, 18 Jan 2024 19:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705606154; cv=none; b=efLBHkja5ZOuO2YuRULlt0F5kzPHm95ygsXfo+KzK1RP3f2H3YMKzojW3f2M8RV0zrIYJNMpbv5C4eUgULnfLSfEWN2hK7S3mSsf8f9caEq6ki+kgjVdbVOireR7yQXouxJu/65Bk7X+JmmLbG43XJMdx16X5maJ9R/JbMZagDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705606154; c=relaxed/simple; bh=EYGd/BtwuvtD8ZA8Nfy4r9pHo1JatfhJ33J3FjqEQrM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IjpeMlRYeJOX7iBKbXMggWC8MPmvWdofhkivHEk4pWsqpdB7uiLu5uFwsuz2schFC4eFvJmQqWX+HYRPGe/5e0Ju0ZI0VQgPCgwIULOoaGQ0PP6zB5ysi50rGDynEKqO1ARYjMdr2LG8LIw4D7BySUxiuvQSIHFsOZEFkPLzSIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=S3u/Av31; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-28ffac1ce99so45875a91.1 for ; Thu, 18 Jan 2024 11:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705606152; x=1706210952; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+iomTbXqRTjibxPrZcFIaAB8B6frVBWEtPfgQV/mc1o=; b=S3u/Av314bbOChT4eb5WgE0aLJdxWthB6iKAfRqC1CA59rt1pW5unaFdmlBfnJeedP cjKM1qDTXCCKEWOWQ/gpWvnQ1lF68ASBYjP29kT5H8JdTUCwFmc6VyQb2X/vmXrXMwxs UJ8TaYXJmwBZZm1QPVI9I83uLnO2T05RK1mFQ5Z+KCub5WGV8YClTU0LrROXS66DJPK4 vOZaoZOi84i22Fc8CIFEoz+yAafYtyh2QGmJbTMtxyFbkFHqyEhSYwRSfK88d/dUS3Q7 BXg+rS7pRXpCypYQZy9KBWSoi2d58knqvFw0c94rEngi/mNKSBCm1cI6S9pyvHwFcXrh U77g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705606152; x=1706210952; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+iomTbXqRTjibxPrZcFIaAB8B6frVBWEtPfgQV/mc1o=; b=epQV0/seaylXD0BxkzOEQyCCxJxPrAPh/X9PBL5cWfXYJzVk/6REuTqe+9gkHw0G0y W6EkfBqo25clrdE3rcrwaJTC/P6jC0/fINnBTt9ZhSDh0RTXfhtMvGSrwzAwtw4/vPwh NnWwY+d9DsWU7bjys9jvmpSUwdXhhbRjWdKa7LwuKdZ6ae3xGXISZB1nkSmEch2JypCu 7Fhrd36q3O/5RXZ9zzngOEXhPZKN4i2yYPN0Hga+Ea392jwx0Fhq0ZbPKDSVj6D1A8Wc yEr7wF1dKALMlw+CXWjGupXc/OZZfO9zeGSgVL+YMabvtoRCtmQdq3CJMeY8ZHMybZ6C RItQ== X-Gm-Message-State: AOJu0Yzc+6IqyG6iAHzGbkqkKwxRSiTupR8oTgnoUsRTErANfzg/3Qfy 5ArfHAe1/Rsswd/BMCb+s/2z0l9diKjA3mQOUHAuayIxEmolHfs5GyzfBKqiXg== X-Received: by 2002:a17:90a:e2c8:b0:290:45a7:3ed7 with SMTP id fr8-20020a17090ae2c800b0029045a73ed7mr158870pjb.3.1705606152436; Thu, 18 Jan 2024 11:29:12 -0800 (PST) Received: from google.com (77.62.105.34.bc.googleusercontent.com. [34.105.62.77]) by smtp.gmail.com with ESMTPSA id oe15-20020a17090b394f00b002903a89ebb3sm716848pjb.31.2024.01.18.11.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:29:11 -0800 (PST) Date: Thu, 18 Jan 2024 19:29:07 +0000 From: Carlos Llamas To: Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Suren Baghdasaryan , Brian Swetland Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Alice Ryhl , Greg Kroah-Hartman , stable@vger.kernel.org Subject: Re: [PATCH v2 03/28] binder: fix race between mmput() and do_exit() Message-ID: References: <20231201172212.1813387-1-cmllamas@google.com> <20231201172212.1813387-4-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231201172212.1813387-4-cmllamas@google.com> On Fri, Dec 01, 2023 at 05:21:32PM +0000, Carlos Llamas wrote: > 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 > --- Sorry, I forgot to Cc: stable@vger.kernel.org. -- Carlos Llamas