* [PATCH 0/2] Fix two issues with freeze listeners
@ 2025-10-04 10:07 Alice Ryhl
2025-10-04 10:07 ` [PATCH 1/2] rust_binder: freeze_notif_done should resend if wrong state Alice Ryhl
2025-10-04 10:07 ` [PATCH 2/2] rust_binder: don't delete FreezeListener if there are pending duplicates Alice Ryhl
0 siblings, 2 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-10-04 10:07 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel, rust-for-linux, Alice Ryhl
See each commit message for details.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Alice Ryhl (2):
rust_binder: freeze_notif_done should resend if wrong state
rust_binder: don't delete FreezeListener if there are pending duplicates
drivers/android/binder/freeze.rs | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
---
base-commit: eafedbc7c050c44744fbdf80bdf3315e860b7513
change-id: 20251002-binder-freeze-f99e23dc47bf
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] rust_binder: freeze_notif_done should resend if wrong state
2025-10-04 10:07 [PATCH 0/2] Fix two issues with freeze listeners Alice Ryhl
@ 2025-10-04 10:07 ` Alice Ryhl
2025-10-04 10:07 ` [PATCH 2/2] rust_binder: don't delete FreezeListener if there are pending duplicates Alice Ryhl
1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-10-04 10:07 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel, rust-for-linux, Alice Ryhl
Consider the following scenario:
1. A freeze notification is delivered to thread 1.
2. The process becomes frozen or unfrozen.
3. The message for step 2 is delivered to thread 2 and ignored because
there is already a pending notification from step 1.
4. Thread 1 acknowledges the notification from step 1.
In this case, step 4 should ensure that the message ignored in step 3 is
resent as it can now be delivered.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
drivers/android/binder/freeze.rs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/android/binder/freeze.rs b/drivers/android/binder/freeze.rs
index e68c3c8bc55a203c32261c23915d8c427569e3b0..74bebb8d4d9b24860eed34363ce69b1c6df58028 100644
--- a/drivers/android/binder/freeze.rs
+++ b/drivers/android/binder/freeze.rs
@@ -245,8 +245,9 @@ pub(crate) fn freeze_notif_done(self: &Arc<Self>, reader: &mut UserSliceReader)
);
return Err(EINVAL);
}
- if freeze.is_clearing {
- // Immediately send another FreezeMessage for BR_CLEAR_FREEZE_NOTIFICATION_DONE.
+ let is_frozen = freeze.node.owner.inner.lock().is_frozen;
+ if freeze.is_clearing || freeze.last_is_frozen != Some(is_frozen) {
+ // Immediately send another FreezeMessage.
clear_msg = Some(FreezeMessage::init(alloc, cookie));
}
freeze.is_pending = false;
--
2.51.0.618.g983fd99d29-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] rust_binder: don't delete FreezeListener if there are pending duplicates
2025-10-04 10:07 [PATCH 0/2] Fix two issues with freeze listeners Alice Ryhl
2025-10-04 10:07 ` [PATCH 1/2] rust_binder: freeze_notif_done should resend if wrong state Alice Ryhl
@ 2025-10-04 10:07 ` Alice Ryhl
1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-10-04 10:07 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel, rust-for-linux, Alice Ryhl
When userspace issues commands to a freeze listener, it identifies it
using a cookie. Normally this cookie uniquely identifies a freeze
listener, but when userspace clears a listener with the intent of
deleting it, it's allowed to "regret" clearing it and create a new
freeze listener for the same node using the same cookie. (IMO this was
an API mistake, but userspace relies on it.)
Currently if the active freeze listener gets fully deleted while there
are still pending duplicates, then the code incorrectly deletes the
pending duplicates too. To fix this, do not delete the entry if there
are still pending duplicates.
Since the current data structure requires a main freeze listener, we
convert one pending duplicate into the primary listener in this
scenario.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
drivers/android/binder/freeze.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/android/binder/freeze.rs b/drivers/android/binder/freeze.rs
index 74bebb8d4d9b24860eed34363ce69b1c6df58028..e304aceca7f31c15444cf67bb13488cd144345e6 100644
--- a/drivers/android/binder/freeze.rs
+++ b/drivers/android/binder/freeze.rs
@@ -106,7 +106,16 @@ fn do_work(
return Ok(true);
}
if freeze.is_clearing {
- _removed_listener = freeze_entry.remove_node();
+ kernel::warn_on!(freeze.num_cleared_duplicates != 0);
+ if freeze.num_pending_duplicates > 0 {
+ // The primary freeze listener was deleted, so convert a pending duplicate back
+ // into the primary one.
+ freeze.num_pending_duplicates -= 1;
+ freeze.is_pending = true;
+ freeze.is_clearing = true;
+ } else {
+ _removed_listener = freeze_entry.remove_node();
+ }
drop(node_refs);
writer.write_code(BR_CLEAR_FREEZE_NOTIFICATION_DONE)?;
writer.write_payload(&self.cookie.0)?;
--
2.51.0.618.g983fd99d29-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-04 10:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-04 10:07 [PATCH 0/2] Fix two issues with freeze listeners Alice Ryhl
2025-10-04 10:07 ` [PATCH 1/2] rust_binder: freeze_notif_done should resend if wrong state Alice Ryhl
2025-10-04 10:07 ` [PATCH 2/2] rust_binder: don't delete FreezeListener if there are pending duplicates Alice Ryhl
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®