Skip to content

Commit 99559e5

Browse files
Darksonngregkh
authored andcommitted
rust_binder: don't delete FreezeListener if there are pending duplicates
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 <[email protected]> Acked-by: Carlos Llamas <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bfe144d commit 99559e5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/android/binder/freeze.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,16 @@ impl DeliverToRead for FreezeMessage {
106106
return Ok(true);
107107
}
108108
if freeze.is_clearing {
109-
_removed_listener = freeze_entry.remove_node();
109+
kernel::warn_on!(freeze.num_cleared_duplicates != 0);
110+
if freeze.num_pending_duplicates > 0 {
111+
// The primary freeze listener was deleted, so convert a pending duplicate back
112+
// into the primary one.
113+
freeze.num_pending_duplicates -= 1;
114+
freeze.is_pending = true;
115+
freeze.is_clearing = true;
116+
} else {
117+
_removed_listener = freeze_entry.remove_node();
118+
}
110119
drop(node_refs);
111120
writer.write_code(BR_CLEAR_FREEZE_NOTIFICATION_DONE)?;
112121
writer.write_payload(&self.cookie.0)?;

0 commit comments

Comments
 (0)