Rust for Linux List
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Adhyansh Verma <adhyanshverma2010@gmail.com>
Cc: Alice Ryhl <aliceryhl@google.com>,
	Carlos Llamas <cmllamas@google.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3] rust_binder: unfreeze process before returning on allocation failure
Date: Sun, 29 Nov 2026 11:07:53 +0000	[thread overview]
Message-ID: <20261129110753.1133472-1-aliceryhl@google.com> (raw)
In-Reply-To: <20261128194924.53915-1-adhyanshverma2010@gmail.com>

On Sun, Nov 29, 2026 at 01:19:24AM +0530, Adhyansh Verma wrote:
> In Process::ioctl_freeze(), when info.enable == 0 (unfreeze request),
> the driver calls self.prepare_freeze_messages()? before acquiring
> self.inner.lock() to reset inner.is_frozen = IsFrozen::No.
>
> If prepare_freeze_messages() fails due to memory allocation failure
> (AllocError), the ? operator immediately returns Err(ENOMEM).
> Consequently, inner.is_frozen is never updated to IsFrozen::No, leaving
> the target process permanently frozen. Furthermore, preparing messages
> with GFP_KERNEL before clearing is_frozen leaves a window where
> concurrent operations observe stale IsFrozen::Yes, failing early in
> top-level ioctl_freeze() leaves other binder contexts of the process
> frozen, and dropping unfreeze notifications on allocation failure leaves
> freeze listeners out of sync.
>
> Unfreezing the process itself is a zero-allocation operation and must
> succeed so that incoming transactions are not blocked.
>
> Update ioctl_freeze() to:
> - Reset inner.is_frozen = IsFrozen::No, inner.sync_recv = false, and
>   inner.async_recv = false under lock before calling
>   prepare_freeze_messages(), avoiding race windows with concurrent
>   operations.
> - Maintain a freeze_version counter on ProcessInner incremented on every
>   is_frozen transition, allowing FreezeListener instances to detect state
>   changes and avoid suppressing notifications even if an intermediate
>   notification could not be allocated due to OOM.
> - Continue unfreezing all matching process contexts in top-level
>   ioctl_freeze() even if message preparation on one context fails.
> - Return Err(ENOMEM) after ensuring processes have been unfrozen if
>   prepare_freeze_messages() fails.
>
> Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
> Signed-off-by: Adhyansh Verma <adhyanshverma2010@gmail.com>

I don't think we should take this patch. If we can't allocate and send
the freeze notifications, then we haven't properly unfrozen the process
either -- unfreezing before prepare_freeze_messages() would leave the
process unfrozen while freeze listeners still think it is frozen.

Keeping the allocation before setting is_frozen = IsFrozen::No is
intentional and symmetric with the freeze path (which rolls back
is_frozen = IsFrozen::No if prepare_freeze_messages() returns ENOMEM):
on ENOMEM the ioctl fails cleanly without leaving state half-updated,
and userspace can retry.

Alice

  reply	other threads:[~2026-11-29 11:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 15:44 [PATCH] rust_binder: unfreeze process before returning on allocation failure Adhyansh Verma
2026-11-28 17:56 ` [PATCH v2] " Adhyansh Verma
2026-11-28 19:49   ` [PATCH v3] " Adhyansh Verma
2026-11-29 11:07     ` Alice Ryhl [this message]
2026-11-29 12:25     ` Greg Kroah-Hartman
2026-11-29 13:54       ` Adhyansh Verma
2026-11-29 14:05         ` Miguel Ojeda

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=20261129110753.1133472-1-aliceryhl@google.com \
    --to=aliceryhl@google.com \
    --cc=adhyanshverma2010@gmail.com \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=rust-for-linux@vger.kernel.org \
    /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